Skip to content

Commit 9b07d7f

Browse files
committed
Do not render PopoverMenu until it gets opened
1 parent 18d4f1e commit 9b07d7f

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/components/PopoverMenu.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {ModalProps} from 'react-native-modal';
88
import type {SvgProps} from 'react-native-svg';
99
import useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager';
1010
import useKeyboardShortcut from '@hooks/useKeyboardShortcut';
11+
import usePrevious from '@hooks/usePrevious';
1112
import useResponsiveLayout from '@hooks/useResponsiveLayout';
1213
import useStyleUtils from '@hooks/useStyleUtils';
1314
import useTheme from '@hooks/useTheme';
@@ -28,6 +29,7 @@ import MenuItem from './MenuItem';
2829
import type ReanimatedModalProps from './Modal/ReanimatedModal/types';
2930
import type BaseModalProps from './Modal/types';
3031
import OfflineWithFeedback from './OfflineWithFeedback';
32+
import {PopoverContext} from './PopoverProvider';
3133
import PopoverWithMeasuredContent from './PopoverWithMeasuredContent';
3234
import ScrollView from './ScrollView';
3335
import Text from './Text';
@@ -178,7 +180,16 @@ function getSelectedItemIndex(menuItems: PopoverMenuItem[]) {
178180
return menuItems.findIndex((option) => option.isSelected);
179181
}
180182

181-
function PopoverMenu({
183+
function PopoverMenu(props: PopoverMenuProps) {
184+
const wasVisible = usePrevious(props.isVisible);
185+
// Do not render the PopoverMenu before it gets opened. Until then both values are false
186+
if (!wasVisible && !props.isVisible) {
187+
return null;
188+
}
189+
return <BasePopoverMenu {...props} />;
190+
}
191+
192+
function BasePopoverMenu({
182193
menuItems,
183194
onItemSelected,
184195
isVisible,

0 commit comments

Comments
 (0)