Skip to content

Commit

Permalink
Merge pull request #27452 from allroundexperts/fix-22953
Browse files Browse the repository at this point in the history
  • Loading branch information
dangrous authored Sep 18, 2023
2 parents 96f0b6f + 62a35bb commit 88d36fd
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions src/components/Popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,41 @@ import PopoverWithoutOverlay from '../PopoverWithoutOverlay';
* On small screen widths, it uses BottomDocked modal type, and a Popover type on wide screen widths.
*/
function Popover(props) {
if (!props.fullscreen && !props.isSmallScreenWidth) {
const {isVisible, onClose, isSmallScreenWidth, fullscreen, animationInTiming, onLayout, animationOutTiming, disableAnimation, withoutOverlay, anchorPosition} = props;

// Not adding this inside the PopoverProvider
// because this is an issue on smaller screens as well.
React.useEffect(() => {
const listener = () => {
if (!isVisible) {
return;
}

onClose();
};
window.addEventListener('popstate', listener);
return () => {
window.removeEventListener('popstate', listener);
};
}, [onClose, isVisible]);

if (!fullscreen && !isSmallScreenWidth) {
return createPortal(
<Modal
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
type={CONST.MODAL.MODAL_TYPE.POPOVER}
popoverAnchorPosition={props.anchorPosition}
animationInTiming={props.disableAnimation ? 1 : props.animationInTiming}
animationOutTiming={props.disableAnimation ? 1 : props.animationOutTiming}
popoverAnchorPosition={anchorPosition}
animationInTiming={disableAnimation ? 1 : animationInTiming}
animationOutTiming={disableAnimation ? 1 : animationOutTiming}
shouldCloseOnOutsideClick
onLayout={props.onLayout}
onLayout={onLayout}
/>,
document.body,
);
}

if (props.withoutOverlay && !props.isSmallScreenWidth) {
if (withoutOverlay && !isSmallScreenWidth) {
// eslint-disable-next-line react/jsx-props-no-spreading
return createPortal(<PopoverWithoutOverlay {...props} />, document.body);
}
Expand All @@ -36,12 +54,12 @@ function Popover(props) {
<Modal
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
type={props.isSmallScreenWidth ? CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED : CONST.MODAL.MODAL_TYPE.POPOVER}
popoverAnchorPosition={props.isSmallScreenWidth ? undefined : props.anchorPosition}
fullscreen={props.isSmallScreenWidth ? true : props.fullscreen}
animationInTiming={props.disableAnimation && !props.isSmallScreenWidth ? 1 : props.animationInTiming}
animationOutTiming={props.disableAnimation && !props.isSmallScreenWidth ? 1 : props.animationOutTiming}
onLayout={props.onLayout}
type={isSmallScreenWidth ? CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED : CONST.MODAL.MODAL_TYPE.POPOVER}
popoverAnchorPosition={isSmallScreenWidth ? undefined : anchorPosition}
fullscreen={isSmallScreenWidth ? true : fullscreen}
animationInTiming={disableAnimation && !isSmallScreenWidth ? 1 : animationInTiming}
animationOutTiming={disableAnimation && !isSmallScreenWidth ? 1 : animationOutTiming}
onLayout={onLayout}
/>
);
}
Expand Down

0 comments on commit 88d36fd

Please sign in to comment.