Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only switch position if it is possible #39143

Merged
merged 4 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions src/libs/PopoverWithMeasuredContentUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ function computeHorizontalShift(anchorLeftEdge: number, menuWidth: number, windo
*/
function computeVerticalShift(anchorTopEdge: number, menuHeight: number, windowHeight: number, anchorHeight: number, shoudSwitchPositionIfOverflow = false): number {
const popoverBottomEdge = anchorTopEdge + menuHeight;
let canSwitchPosition = false;

if (anchorTopEdge < 0) {
// Anchor is in top window Edge, shift bottom by a multiple of four.
return roundToNearestMultipleOfFour(shoudSwitchPositionIfOverflow ? menuHeight + anchorHeight : 0 - anchorTopEdge);
canSwitchPosition = popoverBottomEdge + menuHeight + anchorHeight <= windowHeight;
return roundToNearestMultipleOfFour(shoudSwitchPositionIfOverflow && canSwitchPosition ? menuHeight + anchorHeight : 0 - anchorTopEdge);
}

if (popoverBottomEdge > windowHeight) {
// Anchor is in Bottom window Edge, shift top by a multiple of four.
return roundToNearestMultipleOfFour(shoudSwitchPositionIfOverflow ? -(menuHeight + anchorHeight) : windowHeight - popoverBottomEdge);
canSwitchPosition = anchorTopEdge - menuHeight - anchorHeight >= 0;
return roundToNearestMultipleOfFour(shoudSwitchPositionIfOverflow && canSwitchPosition ? -(menuHeight + anchorHeight) : windowHeight - popoverBottomEdge);
}

// Anchor is not in the gutter, so no need to shift it vertically
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef<Repor
const [isChatPinned, setIsChatPinned] = useState(false);
const [hasUnreadMessages, setHasUnreadMessages] = useState(false);
const [disabledActions, setDisabledActions] = useState<ContextMenuAction[]>([]);
const [shoudSwitchPositionIfOverflow, setShoudSwitchPositionIfOverflow] = useState(false);

const contentRef = useRef<View>(null);
const anchorRef = useRef<View | HTMLDivElement | null>(null);
Expand Down Expand Up @@ -218,6 +219,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef<Repor
setIsChronosReportEnabled(isChronosReport);
setIsChatPinned(isPinnedChat);
setHasUnreadMessages(isUnreadChat);
setShoudSwitchPositionIfOverflow(isOverflowMenu);
});
};

Expand Down Expand Up @@ -328,7 +330,7 @@ function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef<Repor
withoutOverlay
anchorDimensions={contextMenuDimensions.current}
anchorRef={anchorRef}
shoudSwitchPositionIfOverflow
shoudSwitchPositionIfOverflow={shoudSwitchPositionIfOverflow}
>
<BaseReportActionContextMenu
isVisible
Expand Down
Loading