Skip to content

Commit afbeec9

Browse files
authored
Document detachInactiveScreens (#859)
1 parent 8bb532f commit afbeec9

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

versioned_docs/version-4.x/bottom-tab-navigator.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The route configs object is a mapping from route name to a route config, which t
3535
- `order` - Array of routeNames which defines the order of the tabs.
3636
- `paths` - Provide a mapping of routeName to path config, which overrides the paths set in the routeConfigs.
3737
- `backBehavior` - `initialRoute` to return to initial tab, `order` to return to previous tab, `history` to return to last visited tab, or `none`.
38+
- `detachInactiveScreens` - Boolean used to indicate whether inactive screens should be detached from the view hierarchy to save memory. Make sure to call `enableScreens` from [react-native-screens](https://github.com/software-mansion/react-native-screens) to make it work. Defaults to `true`.
3839
- `lazy` - Defaults to `true`. If `false`, all tabs are rendered immediately. When `true`, tabs are rendered only when they are made active for the first time. Note: tabs are **not** re-rendered upon subsequent visits.
3940
- `tabBarComponent` - Optional, override component to use as the tab bar.
4041
- `tabBarOptions` - An object with the following properties:
@@ -72,14 +73,14 @@ If you want to customize the `tabBarComponent`:
7273
```js
7374
import { createBottomTabNavigator, BottomTabBar } from 'react-navigation-tabs';
7475

75-
const TabBarComponent = props => <BottomTabBar {...props} />;
76+
const TabBarComponent = (props) => <BottomTabBar {...props} />;
7677

7778
const TabScreens = createBottomTabNavigator(
7879
{
7980
// other screens
8081
},
8182
{
82-
tabBarComponent: props => (
83+
tabBarComponent: (props) => (
8384
<TabBarComponent {...props} style={{ borderTopColor: '#605F60' }} />
8485
),
8586
}

versioned_docs/version-4.x/drawer-navigator.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Several options get passed to the underlying router to modify navigation logic:
5353
- `order` - Array of routeNames which defines the order of the drawer items.
5454
- `paths` - Provide a mapping of routeName to path config, which overrides the paths set in the routeConfigs.
5555
- `backBehavior` - Should the back button cause switch to the initial route? If yes, set to `initialRoute`, otherwise `none`. Defaults to `initialRoute` behavior.
56+
- `detachInactiveScreens` - Boolean used to indicate whether inactive screens should be detached from the view hierarchy to save memory. Make sure to call `enableScreens` from [react-native-screens](https://github.com/software-mansion/react-native-screens) to make it work. Defaults to `true`.
5657

5758
### Providing a custom `contentComponent`
5859

@@ -62,7 +63,7 @@ The default component for the drawer is scrollable and only contains links for t
6263
import SafeAreaView from 'react-native-safe-area-view';
6364
import { DrawerItems } from 'react-navigation-drawer';
6465

65-
const CustomDrawerContentComponent = props => (
66+
const CustomDrawerContentComponent = (props) => (
6667
<ScrollView>
6768
<SafeAreaView
6869
style={styles.container}
@@ -83,7 +84,7 @@ const styles = StyleSheet.create({
8384
`contentComponent` also received a prop called `drawerOpenProgress` which is an Reanimated Node that represents the animated position of the drawer (0 is closed; 1 is open). This allows you to do interesting animations in your `contentComponent`, such as parallax motion of the drawer contents:
8485

8586
```js
86-
const CustomDrawerContentComponent = props => {
87+
const CustomDrawerContentComponent = (props) => {
8788
const translateX = Animated.interpolate(drawerOpenProgress, {
8889
inputRange: [0, 1],
8990
outputRange: [-100, 0],

versioned_docs/version-4.x/stack-navigator.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Options for the router:
5858
- `navigationOptions` - Navigation options for the navigator itself, to configure a parent navigator
5959
- `defaultNavigationOptions` - Default navigation options to use for screens
6060
- `paths` - A mapping of overrides for the paths set in the route configs
61+
- `detachInactiveScreens` - Boolean used to indicate whether inactive screens should be detached from the view hierarchy to save memory. Make sure to call `enableScreens` from [react-native-screens](https://github.com/software-mansion/react-native-screens) to make it work. Defaults to `true` on Android and `false` on iOS.
6162

6263
Visual options:
6364

@@ -79,6 +80,10 @@ Visual options:
7980

8081
String that can be used as a fallback for `headerTitle`. Additionally, will be used as a fallback for `tabBarLabel` (if nested in a TabNavigator) or `drawerLabel` (if nested in a DrawerNavigator).
8182

83+
#### `detachPreviousScreen`
84+
85+
Boolean used to indicate whether to detach the previous screen from the view hierarchy to save memory. Set it to `false` if you need the previous screen to be seen through the active screen. Only applicable if `detachInactiveScreens` isn't set to `false`. Defaults to `false` for the last screen when `mode='modal'`, otherwise `true`.
86+
8287
#### `header`
8388

8489
Function that given `HeaderProps` returns a React Element, to display as a header.

versioned_docs/version-5.x/bottom-tab-navigator.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ The name of the route to render on first load of the navigator.
5353

5454
Default options to use for the screens in the navigator.
5555

56+
#### `detachInactiveScreens`
57+
58+
Boolean used to indicate whether inactive screens should be detached from the view hierarchy to save memory. Make sure to call `enableScreens` from [react-native-screens](https://github.com/software-mansion/react-native-screens) to make it work. Defaults to `true`.
59+
5660
#### `backBehavior`
5761

5862
Behavior of back button handling.

versioned_docs/version-5.x/drawer-navigator.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ The name of the route to render on first load of the navigator.
5353

5454
Default options to use for the screens in the navigator.
5555

56+
#### `detachInactiveScreens`
57+
58+
Boolean used to indicate whether inactive screens should be detached from the view hierarchy to save memory. Make sure to call `enableScreens` from [react-native-screens](https://github.com/software-mansion/react-native-screens) to make it work. Defaults to `true`.
59+
5660
#### `backBehavior`
5761

5862
Behavior of back button handling.

versioned_docs/version-5.x/stack-navigator.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ Defines the style for rendering and transitions:
6868
- Sets `headerMode` to `screen` for the stack unless specified
6969
- Make the screens slide in from the bottom on iOS which is a common iOS pattern.
7070

71+
#### `detachInactiveScreens`
72+
73+
Boolean used to indicate whether inactive screens should be detached from the view hierarchy to save memory. Make sure to call `enableScreens` from [react-native-screens](https://github.com/software-mansion/react-native-screens) to make it work. Defaults to `true` on Android and `false` on iOS.
74+
7175
#### `headerMode`
7276

7377
Specifies how the header should be rendered:
@@ -84,6 +88,10 @@ The following [options](screen-options.md) can be used to configure the screens
8488

8589
String that can be used as a fallback for `headerTitle`.
8690

91+
#### `detachPreviousScreen`
92+
93+
Boolean used to indicate whether to detach the previous screen from the view hierarchy to save memory. Set it to `false` if you need the previous screen to be seen through the active screen. Only applicable if `detachInactiveScreens` isn't set to `false`. Defaults to `false` for the last screen when `mode='modal'`, otherwise `true`.
94+
8795
#### `header`
8896

8997
Function that given `HeaderProps` returns a React Element, to display as a header. Make sure to set `headerMode` to `screen` as well when using a custom header (see below for more details).

0 commit comments

Comments
 (0)