Skip to content
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/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;
Comment thread
dominictb marked this conversation as resolved.
/** 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]);
Comment thread
dominictb marked this conversation as resolved.

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