Skip to content

Commit

Permalink
Merge pull request Expensify#46357 from dominictb/fix/44082-hold-edu-…
Browse files Browse the repository at this point in the history
…modal

fix: remove popstate listener in popover
  • Loading branch information
puneetlath authored Jul 29, 2024
2 parents aae253e + 36f8d8a commit 6be6082
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/components/Popover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function Popover(props: PopoverProps) {
anchorRef = () => {},
animationIn = 'fadeIn',
animationOut = 'fadeOut',
shouldCloseWhenBrowserNavigationChanged = true,
} = props;

const {isSmallScreenWidth} = useResponsiveLayout();
Expand All @@ -36,18 +37,20 @@ function Popover(props: PopoverProps) {
// Not adding this inside the PopoverProvider
// because this is an issue on smaller screens as well.
React.useEffect(() => {
if (!shouldCloseWhenBrowserNavigationChanged) {
return;
}
const listener = () => {
if (!isVisible) {
return;
}

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

const onCloseWithPopoverContext = () => {
if (popover && 'current' in anchorRef) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Popover/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type PopoverProps = BaseModalProps &
/** Whether we want to show the popover on the right side of the screen */
fromSidebarMediumScreen?: boolean;

/** Whether handle navigation back when modal show. */
shouldHandleNavigationBack?: boolean;
/** Whether we should close when browser navigation change. This doesn't affect native platform */
shouldCloseWhenBrowserNavigationChanged?: boolean;
};

type PopoverWithWindowDimensionsProps = PopoverProps & WindowDimensionsProps;
Expand Down
12 changes: 11 additions & 1 deletion src/components/ProcessMoneyRequestHoldMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {useRef} from 'react';
import {useNavigation} from '@react-navigation/native';
import React, {useEffect, useRef} from 'react';
import {View} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -31,6 +32,14 @@ function ProcessMoneyRequestHoldMenu({isVisible, onClose, onConfirm, anchorPosit
const {translate} = useLocalize();
const styles = useThemeStyles();
const popoverRef = useRef(null);
const navigation = useNavigation();

useEffect(() => {
const unsub = navigation.addListener('beforeRemove', () => {
onClose();
});
return unsub;
}, [navigation, onClose]);

return (
<Popover
Expand All @@ -41,6 +50,7 @@ function ProcessMoneyRequestHoldMenu({isVisible, onClose, onConfirm, anchorPosit
anchorAlignment={anchorAlignment}
disableAnimation={false}
withoutOverlay={false}
shouldCloseWhenBrowserNavigationChanged={false}
>
<View style={[styles.mh5, styles.mv5]}>
<View style={[styles.flexRow, styles.alignItemsCenter, styles.mb5]}>
Expand Down

0 comments on commit 6be6082

Please sign in to comment.