Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: A very WIP upgrade to React Navigation v3 #3502

Closed
wants to merge 11 commits into from

Conversation

borisyankov
Copy link
Contributor

Based on and a follow up to #2702

Upgrade to React Navigation 2 and do the minimal changes that make
our code compatible.

Navigating behavior has changed, and pushing a route with the
same key does not result in duplicated entry in the history.

The code to wire RN navigator to Redux have changed. The newer
approach is simpler, just using `reduxifyNavigator` helper does
most of the work.

Since `pop` was removed from `NavigationActions` use the
`pop` action from `StackActions` instead.
Update definitions by running `flow-typed update`.

This lets Flow know about the new constructor functions.
The type `NavigationNavigateAction` we use is too specific and
not the correct one. We want the `NavigationAction` type instead.

Also, to make it simpler and consistent, we rename our own type
`NavigateAction` to `NavigationAction`.
The `StackNavigator` constructor function has been deprcated.
Using the `createStackNavigator` that expects the same inputs.
`TabNavigator` constructor is deprecated in favor of the function
'createMaterialTopTabNavigator'. Our config no longer needs some
parameters passed, so this is simplified while keeping the very
same behavior.
Replace `TabNavigator` constructor with `createMaterialTopTabNavigator`
creator function which is the one that matched the old behavior.

Note: While `createBottomTabNavigator` sounds like what we might need,
it is a simpler navigator compared to what we were using and actually
`createMaterialTopTabNavigator` is the correct one.
Instead of using the written by us `getSameRoutesCount` and the
standard `StackActions.pop` use the new 'StackActions.popToTop'.
Now that we don't need `getSameRoutesCount` we can remove it
together with the accompanying unit-tests.
Reaict Native Gesture Handler provides native-driven gesture management APIs
for building best possible touch-based experiences in React Native.

While we might need to use it directly sometime in the future, the need to add
it now is that React Navigation 3 depends on it.

This PR adds 'react-native-gesture-handler' as dependency and configures it for
use in both iOS and Android. It follows the documentation on how to do it here:
https://reactnavigation.org/docs/en/getting-started.html
https://kmagiera.github.io/react-native-gesture-handler/docs/getting-started.html

First, `react-native link` was used, but then manually a lot of code changes that
were cosmetic and line reordering were undone. After that, some manual changes
were implemented (according to the documentation)
@gnprice
Copy link
Member

gnprice commented May 30, 2019

Ah, good thought, thanks!

I think the thing to prioritize here will be braindumping what you've learned about this upgrade. Doing that in code is great where it's easy; in general,

  • What are the main things changed in react-navigation v3 that will be relevant to us, or potential pitfalls?
  • What questions are still open / what things are you still uncertain about as you're investigating?

That can be in commit messages, or in this PR thread.

@borisyankov
Copy link
Contributor Author

The commit Add and configure 'react-native-gesture-handler' is mergeable independently.

@borisyankov
Copy link
Contributor Author

What are the main things changed in react-navigation v3 that will be relevant to us, or potential pitfalls?

I think the upgrade is straightforward, they lib just tends to churn a bit on the API and some navigation objects have had the format of the config objects changed a bit. Nothing major.

What questions are still open / what things are you still uncertain about as you're investigating?

The 'very WIP' part comes from the fact that I worked on this PR a long time ago, but now that I have reviewed the code, it needs a bit of cleanup and would likely be a fast and painless merge.

@gnprice
Copy link
Member

gnprice commented May 30, 2019

The commit Add and configure 'react-native-gesture-handler' is mergeable independently.

Good to know, thanks!

Is it mergeable independently of the v2 upgrade #2702, or does it depend on that? (It comes after it in this branch.)

And thanks for the other notes too; that's helpful.

@borisyankov
Copy link
Contributor Author

Yeah, it does not depend on anything.
It setups this library:
https://github.com/kmagiera/react-native-gesture-handler

Which is a dependency of RN3. It can be used separately from it (but unlikely to)

gnprice added a commit that referenced this pull request Jul 24, 2019
With the upcoming upgrade to RN v0.59 (from v0.57), without this
change I found that I could navigate to any tab as usual... but
just once, and then the bottom tabs had no effect, until the app
was restarted.

Similarly, if I used my one main-tab navigation to go to "streams",
then the top tabs there were good for exactly one navigation: I
could navigate from "Subscribed" to "All streams", but not back.

So, that's pretty broken.  The issue appears to be
react-navigation/react-navigation#5713.

This change is a workaround suggested in a comment there (thanks!)
The look isn't awesome, but at least it keeps things functioning.

The issue thread sounds like the issue is fixed in a later
release of react-navigation.  We're on a quite old release, 1.6.1.
We have some partial work toward an upgrade (#2702 and #3502);
so this is one more reason to finish that.
@chrisbobbe
Copy link
Contributor

chrisbobbe commented Aug 29, 2019

Hi, first comment on Zulip code here! :)

One thing I ran into a few months ago with React Navigation 3 (I'm 95% sure it was introduced in version 2 actually), was that if you try to .navigate(routeName) or .push(routeName), and routeName is not "registered somewhere in the app's router" (https://reactnavigation.org/docs/en/2.x/navigation-prop.html#navigate-link-to-other-screens), then it will fail with no error or warning. I don't think the upgrades to 2 or 3 touched any calls to .push or .navigate, so those commits themselves should be fine, but it's something to know for the future if/when new routes are added (or there are new ways of naming routes; I saw a suggestion to use JSON.stringify, I might tread carefully if doing that: #2702 (comment)).

It seems a PR was made to React Navigation to add a helpful message or error, but rejected with very little ceremony: react-navigation/react-navigation#2140.

Maybe someone has run into this (or you've seen that they've fixed the issue in the last few months)?

@gnprice
Copy link
Member

gnprice commented Aug 30, 2019

Thanks @chrisbobbe !

Looks like the underlying issue for that is react-navigation/react-navigation#1053 , which in turn they copied to https://react-navigation.canny.io/feature-requests/p/throw-warning-or-error-when-navigate-to-an-invalid-route and closed. That is an annoying pitfall, and it sure seems like they should be able to mitigate it with a warning.

For our project, we largely deal with this issue by centralizing the .push calls in one file that provides tiny wrappers for them: https://github.com/zulip/zulip-mobile/blob/ca20e816a/src/nav/navActions.js Then most everything else that needs to refer to a route does so by calling one of those wrappers. So as long as we get the spellings right in that file, we get the benefits of type-checking when we use them. (Same story for the parameter types, too.)

@chrisbobbe
Copy link
Contributor

Closing as superseded by #4249, which has already been merged.

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.

3 participants