Skip to content

Commit cc7d37c

Browse files
rgoldiezbrentvatne
authored andcommitted
Updated v3 docs for drawerOpenProgress (react-navigation#365)
1 parent 4f1dc2d commit cc7d37c

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

docs/drawer-navigator.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@ sidebar_label: createDrawerNavigator
55
---
66

77
```js
8-
createDrawerNavigator(RouteConfigs, DrawerNavigatorConfig)
8+
createDrawerNavigator(RouteConfigs, DrawerNavigatorConfig);
99
```
1010

1111
### RouteConfigs
1212

1313
The route configs object is a mapping from route name to a route config, which tells the navigator what to present for that route, see [example](stack-navigator.html#routeconfigs) from `createStackNavigator`.
1414

15-
1615
### DrawerNavigatorConfig
1716

1817
- `drawerWidth` - Width of the drawer or a function returning it.
1918
- `drawerPosition` - Options are `left` or `right`. Default is `left` position.
20-
- `contentComponent` - Component used to render the content of the drawer, for example, navigation items. Receives the `navigation` prop for the drawer. Defaults to `DrawerItems`. For more information, see below.
19+
- `contentComponent` - Component used to render the content of the drawer, for example, navigation items. Receives the `navigation` prop and `drawerOpenProgress` for the drawer. Defaults to `DrawerItems`. For more information, see below.
2120
- `contentOptions` - Configure the drawer content, see below.
2221
- `useNativeAnimations` - Enable native animations. Default is `true`.
2322
- `drawerBackgroundColor` - Use the Drawer background for some color. The Default is `white`.
@@ -37,7 +36,7 @@ The default component for the drawer is scrollable and only contains links for t
3736
```js
3837
import { DrawerItems, SafeAreaView } from 'react-navigation';
3938

40-
const CustomDrawerContentComponent = (props) => (
39+
const CustomDrawerContentComponent = props => (
4140
<ScrollView>
4241
<SafeAreaView style={styles.container} forceInset={{ top: 'always', horizontal: 'never' }}>
4342
<DrawerItems {...props} />
@@ -52,6 +51,19 @@ const styles = StyleSheet.create({
5251
});
5352
```
5453

54+
`contentComponent` also received a prop called `drawerOpenProgress` which is an [animated value](https://facebook.github.io/react-native/docs/animated#value) 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:
55+
56+
```js
57+
const CustomDrawerContentComponent = props => {
58+
const translateX = props.drawerOpenProgress.interpolate({
59+
inputRange: [0, 1],
60+
outputRange: [-100, 0],
61+
});
62+
63+
return <Animated.View style={{ transform: [{ translateX }] }}>{/* ... drawer contents */}</Animated.View>;
64+
};
65+
```
66+
5567
### `contentOptions` for `DrawerItems`
5668

5769
- `items` - the array of routes, can be modified or overridden
@@ -100,6 +112,6 @@ React Element or a function, that given `{ focused: boolean, tintColor: string }
100112

101113
Specifies the [lock mode](https://facebook.github.io/react-native/docs/drawerlayoutandroid.html#drawerlockmode) of the drawer. This can also update dynamically by using screenProps.drawerLockMode on your top level router.
102114

103-
### Nesting drawer navigators inside others
115+
### Nesting drawer navigators inside others
104116

105-
If a drawer navigator is nested inside of another navigator that provides some UI, for example a tab navigator or stack navigator, then the drawer will be rendered below the UI from those navigators. The drawer will appear below the tab bar and below the header of the stack. You will need to make the drawer navigator the parent of any navigator where the drawer should be rendered on top of its UI.
117+
If a drawer navigator is nested inside of another navigator that provides some UI, for example a tab navigator or stack navigator, then the drawer will be rendered below the UI from those navigators. The drawer will appear below the tab bar and below the header of the stack. You will need to make the drawer navigator the parent of any navigator where the drawer should be rendered on top of its UI.

website/versioned_docs/version-3.x/drawer-navigator.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ original_id: drawer-navigator
66
---
77

88
```js
9-
createDrawerNavigator(RouteConfigs, DrawerNavigatorConfig)
9+
createDrawerNavigator(RouteConfigs, DrawerNavigatorConfig);
1010
```
1111

1212
### RouteConfigs
1313

1414
The route configs object is a mapping from route name to a route config, which tells the navigator what to present for that route, see [example](stack-navigator.html#routeconfigs) from `createStackNavigator`.
1515

16-
1716
### DrawerNavigatorConfig
1817

1918
- `drawerWidth` - Width of the drawer or a function returning it.
@@ -38,7 +37,7 @@ The default component for the drawer is scrollable and only contains links for t
3837
```js
3938
import { DrawerItems, SafeAreaView } from 'react-navigation';
4039

41-
const CustomDrawerContentComponent = (props) => (
40+
const CustomDrawerContentComponent = props => (
4241
<ScrollView>
4342
<SafeAreaView style={styles.container} forceInset={{ top: 'always', horizontal: 'never' }}>
4443
<DrawerItems {...props} />
@@ -53,6 +52,19 @@ const styles = StyleSheet.create({
5352
});
5453
```
5554

55+
`contentComponent` also received a prop called `drawerOpenProgress` which is an [animated value](https://facebook.github.io/react-native/docs/animated#value) 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:
56+
57+
```js
58+
const CustomDrawerContentComponent = props => {
59+
const translateX = props.drawerOpenProgress.interpolate({
60+
inputRange: [0, 1],
61+
outputRange: [-100, 0],
62+
});
63+
64+
return <Animated.View style={{ transform: [{ translateX }] }}>{/* ... drawer contents */}</Animated.View>;
65+
};
66+
```
67+
5668
### `contentOptions` for `DrawerItems`
5769

5870
- `items` - the array of routes, can be modified or overridden
@@ -101,6 +113,6 @@ React Element or a function, that given `{ focused: boolean, tintColor: string }
101113

102114
Specifies the [lock mode](https://facebook.github.io/react-native/docs/drawerlayoutandroid.html#drawerlockmode) of the drawer. This can also update dynamically by using screenProps.drawerLockMode on your top level router.
103115

104-
### Nesting drawer navigators inside others
116+
### Nesting drawer navigators inside others
105117

106-
If a drawer navigator is nested inside of another navigator that provides some UI, for example a tab navigator or stack navigator, then the drawer will be rendered below the UI from those navigators. The drawer will appear below the tab bar and below the header of the stack. You will need to make the drawer navigator the parent of any navigator where the drawer should be rendered on top of its UI.
118+
If a drawer navigator is nested inside of another navigator that provides some UI, for example a tab navigator or stack navigator, then the drawer will be rendered below the UI from those navigators. The drawer will appear below the tab bar and below the header of the stack. You will need to make the drawer navigator the parent of any navigator where the drawer should be rendered on top of its UI.

0 commit comments

Comments
 (0)