fix: fix nested navigation not working the first time

This commit is contained in:
Satyajit Sahoo
2020-11-03 06:59:42 +01:00
parent bd9f0ad5f6
commit ebc7f9ea75
2 changed files with 2 additions and 15 deletions

View File

@@ -747,7 +747,7 @@ it('navigates to nested child in a navigator', () => {
act(() => navigation.current?.navigate('bar', { screen: 'bar-b' }));
expect(element).toMatchInlineSnapshot(
`"[bar-b, {\\"some\\":\\"stuff\\",\\"test\\":42}]"`
`"[bar-b, {\\"some\\":\\"stuff\\",\\"test\\":42,\\"whoa\\":\\"test\\"}]"`
);
});

View File

@@ -356,21 +356,8 @@ export default function useNavigationBuilder<
route.params !== previousParams)
) {
// FIXME: Since params are merged, `route.params.params` might contain params from an older route
// So we need to make sure to reuse it only if:
// - The screen is the same, so navigation happened with same params
// - Params have actually changed
// - It's the first navigation during initialization
const params = (
route.params.screen === nextState.routes[nextState.index].name
? route.params.screen === previousParams?.screen
: route.params.params !== previousParams?.params ||
(route.params.initial === false && isFirstStateInitialization)
)
? route.params.params
: undefined;
// If the route was updated with new screen name and/or params, we should navigate there
action = CommonActions.navigate(route.params.screen, params);
action = CommonActions.navigate(route.params.screen, route.params.params);
}
// The update should be limited to current navigator only, so we call the router manually