Skip to content

Commit

Permalink
Wrap isDisplayedInNarrowModalNavigator in useMemo
Browse files Browse the repository at this point in the history
  • Loading branch information
roryabraham committed Jun 4, 2024
1 parent 56d4ff2 commit 3d37f26
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/hooks/useResponsiveLayout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {NavigationContainerRefContext, NavigationContext} from '@react-navigation/native';
import {useContext} from 'react';
import {useContext, useMemo} from 'react';
import ModalContext from '@components/Modal/ModalContext';
import CONST from '@src/CONST';
import NAVIGATORS from '@src/NAVIGATORS';
Expand Down Expand Up @@ -46,8 +46,12 @@ export default function useResponsiveLayout(): ResponsiveLayoutResult {
const navigator = useContext(NavigationContext);
const currentNavigator = navigator ?? navigationContainerRef;

const isDisplayedInNarrowModalNavigator =
!!currentNavigator?.getParent?.(NAVIGATORS.RIGHT_MODAL_NAVIGATOR as unknown as undefined) || !!currentNavigator?.getParent?.(NAVIGATORS.LEFT_MODAL_NAVIGATOR as unknown as undefined);
const isDisplayedInNarrowModalNavigator = useMemo(
() =>
!!currentNavigator?.getParent?.(NAVIGATORS.RIGHT_MODAL_NAVIGATOR as unknown as undefined) ||
!!currentNavigator?.getParent?.(NAVIGATORS.LEFT_MODAL_NAVIGATOR as unknown as undefined),
[currentNavigator],
);

// The component calling this hook is in a "narrow pane modal" if:
const isInNarrowPaneModal =
Expand Down

0 comments on commit 3d37f26

Please sign in to comment.