Skip to content

Commit 4d9286a

Browse files
committed
Include details about upgrading navigators in upgrading from 3.x
1 parent 82d7c4c commit 4d9286a

File tree

1 file changed

+145
-20
lines changed

1 file changed

+145
-20
lines changed

website/versioned_docs/version-4.x/upgrading-from-3.x.md

Lines changed: 145 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ original_id: upgrading-from-3.x
77

88
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.
99

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.
1111
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
1513

1614
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.
1715

@@ -23,9 +21,9 @@ npm install react-navigation react-navigation-stack@^1.7.3 react-navigation-tabs
2321

2422
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.
2523

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.
2725
28-
### Changing your code
26+
## Changing your code
2927

3028
Then change any imports for stack, tabs or drawer to import from the above packages instead of `react-navigation`.
3129

@@ -65,17 +63,17 @@ The following imports need to be changed to import from `react-navigation-drawer
6563
- `DrawerNavigatorItems`
6664
- `DrawerSidebar`
6765

68-
### Upgrading navigators (optional)
66+
## Upgrading navigators (optional)
6967

7068
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.
7169

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.
7371
74-
#### Installing dependencies
72+
### Installing dependencies
7573

7674
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.
7775

78-
##### Installing dependencies into an Expo managed project
76+
#### Installing dependencies into an Expo managed project
7977

8078
In your project directory, run the following:
8179

@@ -85,7 +83,7 @@ expo install react-native-gesture-handler react-native-reanimated
8583

8684
This will install versions of these libraries that are compatible.
8785

88-
##### Installing dependencies into a bare React Native project
86+
#### Installing dependencies into a bare React Native project
8987

9088
In your project directory, run `npm install react-native-reanimated react-native-gesture-handler react-native-screens`.
9189

@@ -141,33 +139,160 @@ public class MainActivity extends ReactActivity {
141139
}
142140
```
143141

144-
#### Upgrading packages
142+
### Upgrading packages
143+
144+
#### `react-navigation-tabs`
145145

146146
To upgrade `react-navigation-tabs`, run:
147147

148148
```sh
149149
npm install react-navigation-tabs
150150
```
151151

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`
153166

154167
To upgrade `react-navigation-drawer`, run:
155168

156169
```sh
157170
npm install react-navigation-drawer
158171
```
159172

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`.
161174

162-
#### More info
175+
#### `react-navigation-stack`
163176

164-
For more info and release notes, please refer to the individual packages:
177+
To upgrade `react-navigation-stack`, run:
165178

166-
- [`react-navigation-stack`](https://github.com/react-navigation/stack) ([Changelog](https://github.com/react-navigation/stack/releases))
167-
- [`react-navigation-drawer`](https://github.com/react-navigation/drawer) ([Changelog](https://github.com/react-navigation/stack/releases))
168-
- [`react-navigation-tabs`](https://github.com/react-navigation/tabs) ([Changelog](https://github.com/react-navigation/stack/releases))
179+
```sh
180+
npm install react-navigation-stack
181+
```
182+
183+
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:
192+
193+
```sh
194+
npm install react-native-safe-area-context @react-native-community/masked-view
195+
```
169196

170-
### TypeScript
197+
##### Stack Navigator config
198+
199+
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
171296

172297
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:
173298

0 commit comments

Comments
 (0)