Skip to content

Commit 586be63

Browse files
committed
fix navigation
1 parent 32c866d commit 586be63

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

.storybook/preview.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {SafeAreaProvider} from 'react-native-safe-area-context';
55
import type {Parameters} from 'storybook/internal/types';
66
import EnvironmentProvider from '@components/EnvironmentContextProvider';
77
import OnyxListItemProvider from '@components/OnyxListItemProvider';
8+
import ScreenWrapperStatusContext from '@components/ScreenWrapper/ScreenWrapperStatusContext';
89
import {SearchContextProvider} from '@components/Search/SearchContext';
910
import colors from '@styles/theme/colors';
1011
import ComposeProviders from '@src/components/ComposeProviders';
@@ -36,7 +37,9 @@ const decorators = [
3637
SearchContextProvider,
3738
]}
3839
>
39-
<Story />
40+
<ScreenWrapperStatusContext.Provider value={{didScreenTransitionEnd: true, isSafeAreaTopPaddingApplied: false, isSafeAreaBottomPaddingApplied: false}}>
41+
<Story />
42+
</ScreenWrapperStatusContext.Provider>
4043
</ComposeProviders>
4144
),
4245
];

__mocks__/@react-navigation/native/index.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type * as ReactNavigation from '@react-navigation/native';
2+
import {useEffect} from 'react';
23
import createAddListenerMock from '../../../tests/utils/createAddListenerMock';
34

45
const isJestEnv = process.env.NODE_ENV === 'test';
@@ -16,16 +17,14 @@ const {triggerTransitionEnd, addListener} = isJestEnv
1617
addListener: () => {},
1718
};
1819

19-
const useNavigation = isJestEnv
20-
? realReactNavigation.useNavigation
21-
: () => ({
22-
navigate: isJestEnv ? jest.fn() : () => {},
23-
getState: () => ({
24-
routes: [],
25-
}),
26-
isFocused: () => true,
27-
addListener,
28-
});
20+
const navigationMock = {
21+
navigate: () => {},
22+
getState: () => ({routes: []}),
23+
isFocused: () => true,
24+
addListener,
25+
};
26+
27+
const useNavigation = isJestEnv ? realReactNavigation.useNavigation : () => navigationMock;
2928

3029
type NativeNavigationMock = typeof ReactNavigation & {
3130
triggerTransitionEnd: () => void;
@@ -43,7 +42,12 @@ const useLinkProps = isJestEnv ? realReactNavigation.useLinkProps : () => null;
4342
const useLinkTo = isJestEnv ? realReactNavigation.useLinkTo : () => null;
4443
const useScrollToTop = isJestEnv ? realReactNavigation.useScrollToTop : () => null;
4544
const useRoute = isJestEnv ? realReactNavigation.useRoute : () => ({params: {}});
46-
const useFocusEffect = isJestEnv ? realReactNavigation.useFocusEffect : (callback: () => void) => callback();
45+
// Run callback in useEffect (like real useFocusEffect), not synchronously during render
46+
const useFocusEffect = isJestEnv
47+
? realReactNavigation.useFocusEffect
48+
: (callback: () => (() => void) | void) => {
49+
useEffect(() => callback(), [callback]);
50+
};
4751
const usePreventRemove = isJestEnv ? jest.fn() : () => {};
4852
const useNavigationState = isJestEnv ? realReactNavigation.useNavigationState : () => {};
4953

0 commit comments

Comments
 (0)