Skip to content

Commit

Permalink
deps: Upgrade to react-navigation v4.
Browse files Browse the repository at this point in the history
v4 includes lots of housekeeping changes that aim to make
maintenance easier [1].

In particular, we no longer grab stack, tab, or drawer navigation
logic from react-navigation itself; we must now depend directly on
separate libraries that provide these and import from them.

- We got a head start on this in the v3 upgrade (in a recent commit)
  by ensuring we had react-navigation-{tabs,stack,drawer} installed
  at v3-compatible versions.

- Now, we bump these to their latest versions (no peer-dep warnings
  when we do this!) and default to using carets in their version
  ranges since we see no indication that we can't.

- This means installing react-native-reanimated, as we knew we'd
  need to. (We mock it in our Jest setup, following some
  instructions [2].) For react-navigation-stack, we add peer
  dependencies react-native-safe-area-context and
  @react-native-community/masked-view.

The upgrade guide asks us to stop depending on
@react-navigation/core and @react-navigation/native and change any
imports of those to react-navigation imports instead. We don't have
any imports to change, and we can freely remove
@react-navigation/native. We can't yet remove @react-navigation/core
because it's still a peer dependency of
react-navigation-redux-helpers [3]. So we keep it, and align its
version range with the one in react-navigation's dependencies.

There's a long list of identifiers whose usage has changed.
Searching our code for each one, these are the interesting ones:

- `create*Navigator` being imported from the respective
  react-navigation-{tabs,stack,drawer} library; quite easy to handle

- `cardStyle` (in stack nav config) being moved to
  `navigationOptions` (or `defaultNavigationOptions`). We deleted
  our only use of `cardStyle` in the recent react-navigation v3
  upgrade because we only used it to make the background color white
  and, white became the default background color in that upgrade.

Finally, attempt to upgrade libdefs for the dependencies we touched,
if we import from them directly. We get new version-appropriate
libdefs for react-navigation, react-navigation-drawer, and
react-navigation-tabs. Unfortunately react-navigation-stack only has
a v1 libdef.

[1] https://reactnavigation.org/docs/4.x/upgrading-from-3.x/

[2] See https://reactnavigation.org/docs/testing/. We don't include
    the following line also recommended there:

    ```
    // Silence the warning: Animated: `useNativeDriver` is not
    // supported because the native animated module is missing
    jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
    ```

    We don't get that warning in the first place, and it's not clear
    what mock is being applied (apart from React Native's own
    default one). If we need to mock `NativeAnimatedHelper` in the
    future, we shouldn't point to the internal path in react-native;
    it should go in our existing react-native mock (alongside
    NativeModules, etc.).

[3] zulip#3804 (comment)
  • Loading branch information
chrisbobbe committed Sep 4, 2020
1 parent 9ead197 commit f086a43
Show file tree
Hide file tree
Showing 9 changed files with 2,554 additions and 1,406 deletions.
688 changes: 688 additions & 0 deletions flow-typed/npm/react-navigation-drawer_v2.x.x.js

Large diffs are not rendered by default.

781 changes: 781 additions & 0 deletions flow-typed/npm/react-navigation-tabs_v2.x.x.js

Large diffs are not rendered by default.

1,325 changes: 0 additions & 1,325 deletions flow-typed/npm/react-navigation_v3.x.x.js

This file was deleted.

980 changes: 980 additions & 0 deletions flow-typed/npm/react-navigation_v4.x.x.js

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ PODS:
- React
- react-native-safe-area (0.4.4):
- React
- react-native-safe-area-context (3.1.7):
- React
- react-native-simple-toast (1.0.0):
- React
- Toast (~> 4.0.0)
Expand Down Expand Up @@ -270,10 +272,14 @@ PODS:
- React-Core
- RNCAsyncStorage (1.6.3):
- React
- RNCMaskedView (0.1.10):
- React
- RNDeviceInfo (0.21.5):
- React
- RNGestureHandler (1.7.0):
- React
- RNReanimated (1.13.0):
- React
- RNSentry (1.6.3):
- React
- Sentry (~> 5.1.8)
Expand Down Expand Up @@ -338,6 +344,7 @@ DEPENDENCIES:
- react-native-photo-view (from `../node_modules/react-native-photo-view`)
- react-native-safari-view (from `../node_modules/react-native-safari-view`)
- react-native-safe-area (from `../node_modules/react-native-safe-area`)
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
- react-native-simple-toast (from `../node_modules/react-native-simple-toast`)
- react-native-webview (from `../node_modules/react-native-webview`)
- React-RCTActionSheet (from `../node_modules/react-native/Libraries/ActionSheetIOS`)
Expand All @@ -354,8 +361,10 @@ DEPENDENCIES:
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- rn-fetch-blob (from `../node_modules/rn-fetch-blob`)
- "RNCAsyncStorage (from `../node_modules/@react-native-community/async-storage`)"
- "RNCMaskedView (from `../node_modules/@react-native-community/masked-view`)"
- RNDeviceInfo (from `../node_modules/react-native-device-info`)
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
- RNReanimated (from `../node_modules/react-native-reanimated`)
- "RNSentry (from `../node_modules/@sentry/react-native`)"
- RNSound (from `../node_modules/react-native-sound`)
- RNVectorIcons (from `../node_modules/react-native-vector-icons`)
Expand Down Expand Up @@ -437,6 +446,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native-safari-view"
react-native-safe-area:
:path: "../node_modules/react-native-safe-area"
react-native-safe-area-context:
:path: "../node_modules/react-native-safe-area-context"
react-native-simple-toast:
:path: "../node_modules/react-native-simple-toast"
react-native-webview:
Expand Down Expand Up @@ -467,10 +478,14 @@ EXTERNAL SOURCES:
:path: "../node_modules/rn-fetch-blob"
RNCAsyncStorage:
:path: "../node_modules/@react-native-community/async-storage"
RNCMaskedView:
:path: "../node_modules/@react-native-community/masked-view"
RNDeviceInfo:
:path: "../node_modules/react-native-device-info"
RNGestureHandler:
:path: "../node_modules/react-native-gesture-handler"
RNReanimated:
:path: "../node_modules/react-native-reanimated"
RNSentry:
:path: "../node_modules/@sentry/react-native"
RNSound:
Expand Down Expand Up @@ -536,6 +551,7 @@ SPEC CHECKSUMS:
react-native-photo-view: 63e9e61da873531f931008b545d8d10c5373ddf8
react-native-safari-view: 955d7160d159241b8e9395d12d10ea0ef863dcdd
react-native-safe-area: 5fce5242419932bc05656f31bc5f0716e30be0f6
react-native-safe-area-context: 955ecfce672683b495d9294d2f154a9ad1d9796b
react-native-simple-toast: 6c376bd79b1e255a4bee90a72ead6447f96ea10d
react-native-webview: 83d00afd3f3ebfbee7f02d149ce1bfa8494d55f3
React-RCTActionSheet: 600b4d10e3aea0913b5a92256d2719c0cdd26d76
Expand All @@ -551,8 +567,10 @@ SPEC CHECKSUMS:
ReactCommon: 198c7c8d3591f975e5431bec1b0b3b581aa1c5dd
rn-fetch-blob: f525a73a78df9ed5d35e67ea65e79d53c15255bc
RNCAsyncStorage: 3c304d1adfaea02ec732ac218801cb13897aa8c0
RNCMaskedView: 5a8ec07677aa885546a0d98da336457e2bea557f
RNDeviceInfo: e7c5fcde13d40e161d8a27f6c5dc69c638936002
RNGestureHandler: b6b359bb800ae399a9c8b27032bdbf7c18f08a08
RNReanimated: 89f5e0a04d1dd52fbf27e7e7030d8f80a646a3fc
RNSentry: ae1e005e4f2655775475445a9c49c1d343e8e3a7
RNSound: da030221e6ac7e8290c6b43f2b5f2133a8e225b0
RNVectorIcons: 0bb4def82230be1333ddaeee9fcba45f0b288ed4
Expand Down
12 changes: 12 additions & 0 deletions jest/jestSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ jest.mock('react-native', () => {
* before mocking it here.
*/

// As instructed at https://reactnavigation.org/docs/testing/.
jest.mock('react-native-reanimated', () => {
/* eslint-disable-next-line global-require */
const Reanimated = require('react-native-reanimated/mock');

// The mock for `call` immediately calls the callback which is incorrect
// So we override it with a no-op
Reanimated.default.call = () => {};

return Reanimated;
});

jest.mock('@react-native-community/async-storage', () => mockAsyncStorage);

jest.mock('react-native-sound', () => () => ({
Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
"@expo/react-native-action-sheet": "^3.4.0",
"@react-native-community/async-storage": "^1.6.3",
"@react-native-community/cameraroll": "^1.7.2",
"@react-native-community/masked-view": "^0.1.10",
"@react-native-community/netinfo": "^5.9.5",
"@react-navigation/core": "^3.5.0",
"@react-navigation/native": "^3.6.2",
"@react-navigation/core": "^3.7.6",
"@sentry/react-native": "^1.0.9",
"@unimodules/core": "~5.1.2",
"@zulip/shared": "^0.0.2",
Expand Down Expand Up @@ -66,21 +66,23 @@
"react-native-image-picker": "^2.3.3",
"react-native-notifications": "^1.2.0",
"react-native-photo-view": "alwx/react-native-photo-view#c58fd6b30",
"react-native-reanimated": "^1.0.0",
"react-native-safari-view": "2.0.0",
"react-native-safe-area": "^0.4.1",
"react-native-screens": "^1.0.0-alpha.23",
"react-native-safe-area-context": "^3.1.7",
"react-native-screens": "^2.10.1",
"react-native-simple-toast": "^1.0.0",
"react-native-sound": "^0.11.0",
"react-native-text-input-reset": "^1.0.2",
"react-native-unimodules": "^0.9.1",
"react-native-url-polyfill": "1.2.0-rc.0",
"react-native-vector-icons": "^6.6.0",
"react-native-webview": "~10.0.0",
"react-navigation": "^3.13.0",
"react-navigation-drawer": "~1.4.0",
"react-navigation": "^4.4.0",
"react-navigation-drawer": "^2.5.0",
"react-navigation-redux-helpers": "^3.0.8",
"react-navigation-stack": "1.5.3",
"react-navigation-tabs": "~1.2.0",
"react-navigation-stack": "^2.8.2",
"react-navigation-tabs": "^2.9.0",
"react-redux": "^5.0.7",
"redux": "^4.0.0",
"redux-action-buffer": "^1.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/nav/AppNavigator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* @flow strict-local */
import { createStackNavigator } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';

import AccountPickScreen from '../account/AccountPickScreen';
import RealmScreen from '../start/RealmScreen';
Expand Down
Loading

0 comments on commit f086a43

Please sign in to comment.