Skip to content

Commit

Permalink
Revert "fix: remove popstate listener in popover"
Browse files Browse the repository at this point in the history
  • Loading branch information
blazejkustra authored Aug 23, 2024
1 parent 6488908 commit a1d94a7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
7 changes: 2 additions & 5 deletions src/components/Popover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function Popover(props: PopoverProps) {
anchorRef = () => {},
animationIn = 'fadeIn',
animationOut = 'fadeOut',
shouldCloseWhenBrowserNavigationChanged = true,
} = props;

const {isSmallScreenWidth} = useResponsiveLayout();
Expand All @@ -37,20 +36,18 @@ 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, shouldCloseWhenBrowserNavigationChanged]);
}, [onClose, isVisible]);

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 we should close when browser navigation change. This doesn't affect native platform */
shouldCloseWhenBrowserNavigationChanged?: boolean;
/** Whether handle navigation back when modal show. */
shouldHandleNavigationBack?: boolean;
};

type PopoverWithWindowDimensionsProps = PopoverProps & WindowDimensionsProps;
Expand Down
12 changes: 1 addition & 11 deletions src/components/ProcessMoneyRequestHoldMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {useNavigation} from '@react-navigation/native';
import React, {useEffect, useRef} from 'react';
import React, {useRef} from 'react';
import {View} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -32,14 +31,6 @@ 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 @@ -50,7 +41,6 @@ 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 a1d94a7

Please sign in to comment.