Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {ParamListBase} from '@react-navigation/native';
import {createNavigatorFactory} from '@react-navigation/native';
import useNavigationResetOnLayoutChange from '@libs/Navigation/AppNavigator/useNavigationResetOnLayoutChange';
import useNavigationResetRootOnLayoutChange from '@libs/Navigation/AppNavigator/useNavigationResetRootOnLayoutChange';
import createPlatformStackNavigatorComponent from '@libs/Navigation/PlatformStackNavigation/createPlatformStackNavigatorComponent';
import defaultPlatformStackScreenOptions from '@libs/Navigation/PlatformStackNavigation/defaultPlatformStackScreenOptions';
import type {PlatformStackNavigationEventMap, PlatformStackNavigationOptions, PlatformStackNavigationState} from '@libs/Navigation/PlatformStackNavigation/types';
Expand All @@ -12,7 +12,7 @@ const ResponsiveStackNavigatorComponent = createPlatformStackNavigatorComponent(
createRouter: CustomRouter,
defaultScreenOptions: defaultPlatformStackScreenOptions,
useCustomState: useStateWithSearch,
useCustomEffects: useNavigationResetOnLayoutChange,
useCustomEffects: useNavigationResetRootOnLayoutChange,
ExtraContent: RenderSearchRoute,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import type {ParamListBase} from '@react-navigation/native';
import {useEffect} from 'react';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import navigationRef from '@libs/Navigation/navigationRef';
import type {CustomEffectsHookProps} from '@libs/Navigation/PlatformStackNavigation/types';

function useNavigationResetOnLayoutChange() {
function useNavigationResetOnLayoutChange({navigation}: CustomEffectsHookProps<ParamListBase>) {
const {shouldUseNarrowLayout} = useResponsiveLayout();

useEffect(() => {
if (!navigationRef.isReady()) {
return;
}
navigationRef.resetRoot(navigationRef.getRootState());
navigation.reset(navigation.getState());
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [shouldUseNarrowLayout]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {useEffect} from 'react';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import navigationRef from '@libs/Navigation/navigationRef';

function useNavigationResetRootOnLayoutChange() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a comment description of what this is used for.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to start setting this up for more unit tests in the navigation are too @WojtekBoman @adamgrzybowski

const {shouldUseNarrowLayout} = useResponsiveLayout();

useEffect(() => {
if (!navigationRef.isReady()) {
return;
}
navigationRef.resetRoot(navigationRef.getRootState());
}, [shouldUseNarrowLayout]);
}

export default useNavigationResetRootOnLayoutChange;