You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In React Navigation 4, we've extracted out the navigators to separate packages to make it easier to maintain and release updates faster. You can follow the guide below to upgrade your projects.
9
9
10
-
## Upgrading
10
+
> Note: Before making these changes, we recommend you to commit all local changes to git so you can revert back to a good state if something goes wrong with the upgrade.
11
11
12
-
> **NOTE**: Before making these changes, we recommend you to commit all local changes to git so you can revert back to a good state if something goes wrong with the upgrade.
13
-
14
-
### Install the new packages
12
+
## Install the new packages
15
13
16
14
First, we need to install the `react-navigation` package along with the various navigators. If you don't use some of these navigators, you can omit them.
This will install the versions compatible with your code if you were using `react-navigation@3.x`, so you wouldn't need any more changes beyond changing the imports.
25
23
26
-
> **NOTE**: If you have `@react-navigation/core` or `@react-navigation/native` in your `package.json`, please remove them and change the imports to import from `react-navigation` package instead.
24
+
> Note: If you have `@react-navigation/core` or `@react-navigation/native` in your `package.json`, please remove them and change the imports to import from `react-navigation` package instead.
27
25
28
-
###Changing your code
26
+
## Changing your code
29
27
30
28
Then change any imports for stack, tabs or drawer to import from the above packages instead of `react-navigation`.
31
29
@@ -65,17 +63,17 @@ The following imports need to be changed to import from `react-navigation-drawer
65
63
-`DrawerNavigatorItems`
66
64
-`DrawerSidebar`
67
65
68
-
###Upgrading navigators (optional)
66
+
## Upgrading navigators (optional)
69
67
70
68
You don't need to upgrade the navigators to their latest version when upgrading to `react-navigation@4.x`. You can upgrade them separately later as per your convenience.
71
69
72
-
> **NOTE**: We recommend to do these changes in a separate commit so you can revert back to a good state if something goes wrong with the upgrade.
70
+
> Note: We recommend to do each of these changes in a separate commit so you can revert back to a good state if something goes wrong with the upgrade.
73
71
74
-
####Installing dependencies
72
+
### Installing dependencies
75
73
76
74
The latest drawer and tabs depend on [`react-native-gesture-handler`](https://github.com/kmagiera/react-native-gesture-handler) and [`react-native-reanimated`](https://github.com/kmagiera/react-native-reanimated). If you already have these libraries installed and at the latest version, you are done here! Otherwise, read on for installation instructions for these dependencies.
77
75
78
-
#####Installing dependencies into an Expo managed project
76
+
#### Installing dependencies into an Expo managed project
This will install versions of these libraries that are compatible.
87
85
88
-
#####Installing dependencies into a bare React Native project
86
+
#### Installing dependencies into a bare React Native project
89
87
90
88
In your project directory, run `npm install react-native-reanimated react-native-gesture-handler react-native-screens`.
91
89
@@ -141,33 +139,160 @@ public class MainActivity extends ReactActivity {
141
139
}
142
140
```
143
141
144
-
#### Upgrading packages
142
+
### Upgrading packages
143
+
144
+
#### `react-navigation-tabs`
145
145
146
146
To upgrade `react-navigation-tabs`, run:
147
147
148
148
```sh
149
149
npm install react-navigation-tabs
150
150
```
151
151
152
-
For list of breaking changes, refer to the [release notes](https://github.com/react-navigation/tabs/releases/tag/v2.0.0).
152
+
This version upgrades [`react-native-tab-view`](https://github.com/react-native-community/react-native-tab-view) to 2.x. As a result, the animations in `createMaterialTopTabNavigator` now use the [`react-native-reanimated`](https://github.com/software-mansion/react-native-reanimated) library.
153
+
154
+
##### Breaking changes
155
+
156
+
- If you have a custom tab bar in `createMaterialTopTabNavigator` which uses the `position` prop, you'll need to update it to use `Animated` from `react-native-reanimated` instead of `react-native`.
157
+
- The `activeTintColor` and `inactiveTintColor` options for the tab bar of `createMaterialTopTabNavigator` now controls the opacity of the label and icons as well.
158
+
- The `animationsEnabled` and `optimizationsEnabled` options have been removed from `createMaterialTopTabNavigator`.
159
+
- Support for React < 16.3 has been dropped, which means the minimum supported React Native version is now 0.56.
160
+
161
+
##### New features
162
+
163
+
- A new `lazyPlaceholderComponent` option is added which lets you show a placeholder for lazy loaded tabs.
164
+
165
+
#### `react-navigation-drawer`
153
166
154
167
To upgrade `react-navigation-drawer`, run:
155
168
156
169
```sh
157
170
npm install react-navigation-drawer
158
171
```
159
172
160
-
For list of breaking changes, refer to the [release notes](https://github.com/react-navigation/drawer/releases/tag/v2.0.0).
173
+
This version upgrades now uses the [`react-native-reanimated`](https://github.com/software-mansion/react-native-reanimated) library for animations. This means, if you're using the `drawerProgress` value, you'll need to migrate your code to use `Animated` from `react-native-reanimated`.
161
174
162
-
#### More info
175
+
#### `react-navigation-stack`
163
176
164
-
For more info and release notes, please refer to the individual packages:
In this release, we have moved several options into `navigationOptions` so that you can configure options per screen instead of per navigator. This lets you do things like customize animations for a particular screen, set options based on `screenProps` etc. Usage of built-in components such as `Header` and `HeaderBackButton` has also been simplified. Other changes are made to improve consistency within the API.
184
+
185
+
From this version, all state changes have an animation, including `replace` and `reset` which didn't do an animation previously. If you don't want animations, you can specify `animationEnabled: false` in `navigationOptions` for a specific screen, or in `defaultNavigationOptions` for the whole navigator.
186
+
187
+
> Note: The alpha versions for 2.0 used Reanimated for the animations. We've replaced Reanimated with React Native's Animated API in the stable release. If you did any custom animations with the alpha, please migrate your code to the Animated API.
188
+
189
+
##### New peer dependencies
190
+
191
+
The new version requires 2 new peer dependencies. To install them in your project, run:
The following configuration options have been removed or moved:
200
+
201
+
-`cardShadowEnabled` - moved to `navigationOptions`
202
+
-`cardOverlayEnabled` - moved to `navigationOptions`
203
+
-`cardStyle` - moved to `navigationOptions`
204
+
-`transparentCard` - removed in favor of `cardStyle: { backgroundColor: 'transparent' }` in `navigationOptions`
205
+
-`headerBackTitleVisible` - moved to `navigationOptions`
206
+
-`headerLayoutPreset` - moved to `navigationOptions` as `headerTitleAlign`
207
+
-`onTransitionStart` - moved to `navigationOptions`
208
+
-`onTransitionEnd` - moved to `navigationOptions`
209
+
-`headerTransitionPreset` - removed in favor of [new APIs for animations](https://reactnavigation.org/docs/en/stack-navigator.html#animations) in `navigationOptions`
210
+
-`transitionConfig` - removed in favor of [new APIs for animations](https://reactnavigation.org/docs/en/stack-navigator.html#animations) in `navigationOptions`
211
+
212
+
##### `navigationOptions`
213
+
214
+
The following `navigationOptions` have been removed or changed:
215
+
216
+
-`headerForceInset` - use `safeAreaInsets` instead to control the safe areas, or use `headerStatusBarHeight` to control the padding for the status bar.
217
+
-`gesturesEnabled` - renamed to `gestureEnabled` for consistency.
218
+
-`header` - now accepts a function returning react element instead, use `headerShown: false` instead of `header: null` to hide the header.
219
+
-`headerTitle` - now accepts a function returning a React element or a string.
220
+
-`headerLeft` - now accepts a function returning a React element.
221
+
-`headerRight` - now accepts a function returning a React element.
222
+
-`headerBackImage` - now accepts a function returning a React element.
223
+
-`headerBackTitle` - now specifies the back title visible in current screen instead of next, specifying `null` no longer hides back title, use `backTitleVisible` instead, for a screen to change next screen's back title, it can pass params.
224
+
-`headerBackground` - now accepts a function returning a React element.
225
+
226
+
The following `navigationOptions` have been added:
227
+
228
+
-`gestureEnabled`
229
+
-`animationEnabled`
230
+
-`headerTitleAlign`
231
+
-`cardShadowEnabled`
232
+
-`cardOverlayEnabled`
233
+
-`cardStyle`
234
+
-`headerBackgroundStyle`
235
+
-`headerBackTitleVisible`
236
+
-`swipeVelocityImpact`
237
+
-`onTransitionStart`
238
+
-`onTransitionEnd`
239
+
240
+
You can find more details about these options in the [documentation](https://reactnavigation.org/docs/en/stack-navigator.html#navigationoptions-for-screens-inside-of-the-navigator).
241
+
242
+
##### Library exports
243
+
244
+
The library now exports the following items:
245
+
246
+
-`createStackNavigator`
247
+
-`StackView`
248
+
-`Header`
249
+
-`HeaderTitle`
250
+
-`HeaderBackButton`
251
+
-`HeaderBackground`
252
+
-`CardStyleInterpolators`
253
+
-`HeaderStyleInterpolators`
254
+
-`TransitionSpecs`
255
+
-`TransitionPresets`
256
+
-`CardAnimationContext`
257
+
-`GestureHandlerRefContext`
258
+
-`HeaderHeightContext`
259
+
-`useCardAnimation`
260
+
-`useHeaderHeight`
261
+
-`useGestureHandlerRef`
262
+
263
+
The following components now receive different set of props, so if you use them, or use your own custom component, you will need to update them:
264
+
265
+
###### `Header` (`header` option)
266
+
267
+
-`mode`
268
+
-`layout`
269
+
-`scene`
270
+
-`previous`
271
+
-`navigation`
272
+
-`styleInterpolator`
273
+
274
+
###### `HeaderBackButton` (`headerLeft` option)
275
+
276
+
-`disabled`
277
+
-`onPress`
278
+
-`pressColorAndroid`
279
+
-`backImage`
280
+
-`tintColor`
281
+
-`label`
282
+
-`truncatedLabel`
283
+
-`labelVisible`
284
+
-`labelStyle`
285
+
-`allowFontScaling`
286
+
-`onLabelLayout`
287
+
-`screenLayout`
288
+
-`titleLayout`
289
+
-`canGoBack`
290
+
291
+
##### Removal of `Transitioner`
292
+
293
+
The old `Transitioner` component has been removed as a result of rewrite of the animation logic. We're not going to expose the new animation logic since it's internal implementation detail and we want to be able to change it without breaking your code. If you need `Transitioner` in your project for some reason, you can copy the old files into your project https://github.com/react-navigation/stack/blob/1.0/src/views/Transitioner.tsx
294
+
295
+
## TypeScript
171
296
172
297
If you're using TypeScript, you'll also need to upgrade the navigators to the latest version following the previous section. Since the navigators have been extracted out, navigator specific types have been removed from the main package. You'll need to update the types accordingly:
0 commit comments