Skip to content

Remove most or all definitions in navActions. #4417

@chrisbobbe

Description

@chrisbobbe

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 navigation prop or useNavigation since 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 navigation object instead of using action creators and dispatch. 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 component prop to a <*.Screen /> component). Thus, it gets passed the navigation prop, 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 navigation prop.
    • These can often easily be converted to Hooks-based components, so that useNavigation can 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 navigation prop 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.
  • 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 NavigationService for these callsites (as an "advanced use case"), rather than finding a way to thread the navigation object through from React. But we may find that something forces our hand.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions