Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions package/src/contexts/overlayContext/MessageOverlayHostLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ export const MessageOverlayHostLayer = ({ BackgroundComponent }: MessageOverlayH
const msgH = messageH.value.h;
const minTop = minY + topH.value.h;
const maxTopWithBottom = maxY - (msgH + bottomH.value.h);
const maxTopWithoutBottom = maxY - msgH;
const maxTop = minTop <= maxTopWithBottom ? maxTopWithBottom : maxTopWithoutBottom;
const solvedTop = clamp(anchorY, minTop, Math.max(minTop, maxTop));
const canFitBottomWithoutOverlap = minTop <= maxTopWithBottom;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for myself: At some point this should come as an overridable function, allowing more control over how these calculations work.

const solvedTop = canFitBottomWithoutOverlap
? clamp(anchorY, minTop, Math.max(minTop, maxTopWithBottom))
: minTop;

return solvedTop - anchorY;
});
Expand All @@ -139,16 +140,10 @@ export const MessageOverlayHostLayer = ({ BackgroundComponent }: MessageOverlayH
const msgH = messageH.value.h;
const minMessageTop = minY + topH.value.h;
const maxMessageTopWithBottom = maxY - (msgH + bottomH.value.h);
const maxMessageTopWithoutBottom = maxY - msgH;
const maxMessageTop =
minMessageTop <= maxMessageTopWithBottom
? maxMessageTopWithBottom
: maxMessageTopWithoutBottom;
const solvedMessageTop = clamp(
anchorMessageTop,
minMessageTop,
Math.max(minMessageTop, maxMessageTop),
);
const canFitBottomWithoutOverlap = minMessageTop <= maxMessageTopWithBottom;
const solvedMessageTop = canFitBottomWithoutOverlap
? clamp(anchorMessageTop, minMessageTop, Math.max(minMessageTop, maxMessageTopWithBottom))
: minMessageTop;

const solvedBottomTop = Math.min(solvedMessageTop + msgH, maxY - bottomH.value.h);
return solvedBottomTop - bottomH.value.y;
Expand Down