Skip to content

Commit 1dc1b1d

Browse files
authored
Merge pull request Expensify#67877 from software-mansion-labs/perf/improve-popovermenu
Perf: Do not render `PopoverMenu` until it gets opened
2 parents 0a8f20b + a364c90 commit 1dc1b1d

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/components/PopoverMenu.tsx

Lines changed: 11 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';
@@ -178,7 +179,16 @@ function getSelectedItemIndex(menuItems: PopoverMenuItem[]) {
178179
return menuItems.findIndex((option) => option.isSelected);
179180
}
180181

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

0 commit comments

Comments
 (0)