Skip to content

fix: avoid deprecated object form of CommonActions.navigate on tab press#538

Open
rayabelcode wants to merge 1 commit into
callstack:mainfrom
rayabelcode:fix/navigate-deprecation-warning
Open

fix: avoid deprecated object form of CommonActions.navigate on tab press#538
rayabelcode wants to merge 1 commit into
callstack:mainfrom
rayabelcode:fix/navigate-deprecation-warning

Conversation

@rayabelcode

Copy link
Copy Markdown

Since @react-navigation/routers 7.6.0 (pulled in by @react-navigation/native 7.3.x), passing an object to CommonActions.navigate is deprecated and logs a warning. Because NativeBottomTabView dispatches the object form on tab selection, every tab press in an app on React Navigation 7.3+ now prints:

WARN  Passing an object as the argument to 'navigate' is deprecated. Use 'navigate(name, params, options)' instead.

This swaps it for the supported navigate(name, params) signature. It's the same pattern @react-navigation/bottom-tabs uses for its own tab press handling (BottomTabBar.tsx):

navigation.dispatch({
  ...CommonActions.navigate(route.name, route.params),
  target: state.key,
});

Behavior is unchanged: the action is still scoped to the tab navigator via target: state.key, and the route is resolved by name within that navigator exactly as before. The only difference is the route's key is no longer spread into the action payload, which the v7 navigate action doesn't use for matching anyway.

Repro: any app using createNativeBottomTabNavigator with @react-navigation/native >= 7.3.0, press any unfocused tab, watch the console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant