diff --git a/src/components/PopoverWithMeasuredContent.tsx b/src/components/PopoverWithMeasuredContent.tsx index 7d83d8525b5c..429aaad7452f 100644 --- a/src/components/PopoverWithMeasuredContent.tsx +++ b/src/components/PopoverWithMeasuredContent.tsx @@ -9,6 +9,7 @@ import ComposerFocusManager from '@libs/ComposerFocusManager'; import PopoverWithMeasuredContentUtils from '@libs/PopoverWithMeasuredContentUtils'; import CONST from '@src/CONST'; import type {AnchorDimensions, AnchorPosition} from '@src/styles'; +import type {PopoverAnchorPosition} from './Modal/types'; import Popover from './Popover'; import type PopoverProps from './Popover/types'; @@ -76,6 +77,10 @@ function PopoverWithMeasuredContent({ ComposerFocusManager.saveFocusState(modalId); } + if (!prevIsVisible && isVisible && isContentMeasured) { + setIsContentMeasured(false); + } + /** * Measure the size of the popover's content. */ @@ -130,11 +135,18 @@ function PopoverWithMeasuredContent({ anchorDimensions.height, shoudSwitchPositionIfOverflow, ); - const shiftedAnchorPosition = { + const shiftedAnchorPosition: PopoverAnchorPosition = { left: adjustedAnchorPosition.left + horizontalShift, - bottom: windowHeight - (adjustedAnchorPosition.top + popoverHeight) - verticalShift, }; + if (anchorAlignment.vertical === CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP) { + shiftedAnchorPosition.top = adjustedAnchorPosition.top; + } + + if (anchorAlignment.vertical === CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM) { + shiftedAnchorPosition.bottom = windowHeight - (adjustedAnchorPosition.top + popoverHeight) - verticalShift; + } + return isContentMeasured ? (