-
-
Notifications
You must be signed in to change notification settings - Fork 654
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
Upgrade to React Navigation v2 #2702
Conversation
0782f18
to
91a6a5d
Compare
9e97460
to
d46568b
Compare
3ec9582
to
9f8cf04
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @borisyankov for doing this upgrade!
One of the really important steps for a major upgrade like this, which I think you've basically done, is reading through the release notes and thinking through what might break or we might need to change. A corollary to that is let's link to the release notes in the commit message, so the reader can easily follow along -- I think that means
https://reactnavigation.org/blog/2018/05/07/react-navigation-2.0.html
Reading that myself, there's one item that concerns me:
navigate(routeName) in StackNavigator is “less pushy”
We do a lot of navigate
and no push
. And I think the behavior we want is typically what's now push
, to the extent that they'd ever differ... the new navigate
behavior sounds to me like a mixture of push
and pop
that will feel flaky and unpredictable as a user (unless it just never ends up being pop
.)
Do you agree? If so, we should probably update accordingly.
Some other comments below.
I'm going to go ahead and merge the first commit, which splits up AppWithNavigation
.
|
||
export const navigateBack = () => (dispatch: Dispatch, getState: GetState): NavigateAction => | ||
// $FlowFixMe | ||
dispatch(NavigationActions.pop({ n: getSameRoutesCount(getState()) })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit message says pop
was removed, which made me concerned that the preceding commit was putting us in a broken state.
I think it isn't, though -- here it still is in the docs:
https://reactnavigation.org/docs/en/navigation-prop.html#pop
... Oh, subtle. This is NavigationActions.pop, which has indeed gone missing from the docs.
Before checking the docs, I looked in the release notes.
https://reactnavigation.org/blog/2018/05/07/react-navigation-2.0.html
For a major-version upgrade like this, I wanted to be sure to read those anyway. I didn't see this change there, and it'd be pretty disappointing if they broke part of the API like that and didn't mention it... but aha, there's this bit:
NavigationActions split up according to router
If you are using NavigationActions.push or other stack-specific actions, you’ll need to import StackActions and use StackActions.push instead.
And indeed, here's that pop
method:
https://reactnavigation.org/docs/en/stack-actions.html
So what I think I'd like to do is:
- We shouldn't leave things in a broken state at any commit. The commit that bumps the react-navigation version should fix this line so it keeps working, in the minimal way that's easy to see is correct: switch to
StackActions
. - This switch to
back
looks cleaner thangetSameRoutesCount
, so I'll be glad to see a change that does that. It should be its own followup commit, and the commit message should explain why the new thing really does have the exact same behavior as the old -- that isn't obvious to me from a quick look at the doc forback
. (Or it'd be fine for the behavior to be different; then the explanation just needs to say why the new behavior is good.)
@@ -12,7 +12,7 @@ import SettingsCard from '../settings/SettingsCard'; | |||
import { IconHome, IconStream, IconSettings } from '../common/Icons'; | |||
import IconUnreadConversations from '../nav/IconUnreadConversations'; | |||
|
|||
export default TabNavigator( | |||
export default createMaterialTopTabNavigator( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, that is confusing that this works! I appreciate that the apparent contradiction is pointed out in the commit message. :-)
It doesn't actually seem to be documented that this is something you can do -- tabBarPosition
doesn't appear on this page:
https://reactnavigation.org/docs/en/material-top-tab-navigator.html
As long as it does work, it's OK, but it's something we'd want to call out and be watchful for on future upgrades.
It looks like there is a "bottom" counterpart to this component, though:
https://reactnavigation.org/docs/en/material-bottom-tab-navigator.html
Does that one work? If so, that seems cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... Aha -- I see #2831 switches to doing exactly this. And from looking at that commit, I see I'd missed this line in that doc:
npm install react-navigation-material-bottom-tabs
I guess I'll continue this thread on that PR.
Oh, also: a commit message says this fixes #2682. It's not obvious to me why that would be -- can you say more? |
8216931
to
1434b86
Compare
Heads up @borisyankov, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the |
c39e2cf
to
bda8009
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did go through the whole PR, updated dependencies, definitions etc. Added one commit that addressed type issues. I think it is ready to merge. I am not sure about the issue, but it works for me. Try restarting. |
@borisyankov I'm still curious about this question, which doesn't look like it's changed:
The second commit removes a fixme, but ... Oh. This is the same issue I pointed out in this comment above: Would you address that feedback and the question about #2682? Then I'll re-review. |
About #2682 I think I did describe this few times somewhere but who knows if it got swallowed in GitHub's comments or is somewhere in the chats... RN2 changes its behavior to treat routes with the same key (even if the params are different) as somehow the same navigation for processing purposes. That would have, typically, required us to do some fixes to make sure the behavior remains the same. Luckily, the new behavior is what we want. On back from two |
(BTW the feedback about
OK; once you've successfully explained this to me, please put it in the commit message so that nobody has to wonder about it again in the future. :-)
Hmm. I don't actually see how this is related to #2682. As Robert's description there says:
and the screencast shows that we then did two narrow animations, one right after the other. This is (a) the same params both times, (b) not about going back. Does this fix #2682, then? If so, how? |
(Also, please make sure to fix the build; the PR is certainly not "ready to merge" while our tests fail on it. Looks easy to fix, but easy or hard it's the author's responsibility.) |
f6f6375
to
fe011be
Compare
@gnprice this is ready for another look. One of the more questionable commit was completely replaced by this commit: |
I've added one commit from #3067 without which the |
Thanks @borisyankov! I've tried to identify below the points I'd especially like to get your thinking on, and the ones where I think I understand already and can easily polish it up myself later before merging. The priority items end up being, in order:
ddd8a11 navigation: Upgrade to React Navigation v2
b600c2f flow: Update 'flow-typed' for React Navigation 2
de29b5a flow: Fix
|
9977ade
to
c484f0e
Compare
Not necessarily. To make it easier to spot the potential place to update this... Just updating the flow-typed definition against our current src/nav/AppWithNavigation.js:4:10 src/nav/AppNavigator.js:39:3 src/nav/AppWithNavigation.js:28:11 |
On the other hand, after all the changes, but not updating the Flow Typed types: src/main/MainTabs.js:4:10 src/main/StreamTabs.js:4:10 src/nav/AppNavigator.js:2:10 src/nav/navActions.js:2:29 |
To me, it seems logical to update this right after the change to RN 2 as it represents the truth even if it raises a few errors temporarily. |
This has the benefit of enough time passing since I last described it in detail. Hope to be more clear now. In our case, this How it worked in V1:
We did manually do the logic WIth V2 with and without our custom logic:
|
I think
To clarify by 'chat' I refer to the route 'chat': |
Thanks, that's helpful! Rereading the docs (those release notes, and the linked "RFC 4") and your explanation, here's the basic interaction that seems very confusing to me, with the new
And OTOH if
I basically don't see how it can make any sense for the same action (navigate to A), starting from the same screen (C) and even same recent history of screens (B, C), to pop off B and C based on whether there's a match for A way back earlier in the stack. I can see it making sense if we're at A, and navigating to A (with just different |
I think that RFC doc also pretty clearly recommends that we should be using
|
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.
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.
Fixes zulip#3503 The popToTop action takes you back to the first screen in the stack: https://reactnavigation.org/docs/en/stack-actions.html#poptotop 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.
Makes sure our main tabs are aligned properly with the edges of the screen on iOS. More about how safe areas work on iOS: https://developer.apple.com/documentation/uikit/uiview/positioning_content_relative_to_the_safe_area About the React Native-specific component: https://facebook.github.io/react-native/docs/safeareaview
The PR migrates to React Navigation v2 without changing or introducing new behavior.