-
-
Notifications
You must be signed in to change notification settings - Fork 675
Description
React Navigation 5, which we've recently upgraded to (#4296), discourages the NavigationService strategy we've been using, as we mentioned in 140c28c.
From their doc about that strategy:
Do not use this method when you have access to a
navigationprop oruseNavigationsince it will behave differently, and many helper methods specific to screens won't be available.
And from their doc on upgrading from v4 to v5:
It's highly recommended to use the methods on the
navigationobject instead of using action creators anddispatch. It should only be used for advanced use cases.
We should aim to remove all the action creators in navActions and use, e.g., navigation.navigate instead. See discussion here and here.
The callsites for the action creators in navActions seem to fall into three categories:
- We're in a React component that functions only as a "screen" component in React Navigation (i.e., the component is used in one way: it gets passed as the
componentprop to a<*.Screen />component). Thus, it gets passed thenavigationprop, and it's quite easy to just use it. - We're in a React component that doesn't function as a "screen" component, so it doesn't automatically get the
navigationprop.- These can often easily be converted to Hooks-based components, so that
useNavigationcan provide the navigation object. - Sometimes, (as in the case of
ComposeMenu) the conversion to Hooks would take a bit of effort. We can consider- just pushing through with the conversion,
- passing down the
navigationprop from the nearest component that has it, or - making a trivial Hooks-based wrapper component that uses
useNavigation, in the same file, and export that.
- These can often easily be converted to Hooks-based components, so that
- We're not in a React component; e.g., we're somewhere deep in the event-handling code for a button being pressed on the action sheet, or for an outbound event coming from the WebView. It might actually end up being appropriate to keep the use of
NavigationServicefor these callsites (as an "advanced use case"), rather than finding a way to thread thenavigationobject through from React. But we may find that something forces our hand.