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
Copy file name to clipboardExpand all lines: versioned_docs/version-6.x/drawer-navigator.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Drawer Navigator renders a navigation drawer on the side of the screen which can
12
12
</video>
13
13
</div>
14
14
15
-
This wraps [`react-native-drawer-layout`](drawer-layout.md). If you want to use the tab view without React Navigation integration, use the library directly instead.
15
+
This wraps [`react-native-drawer-layout`](drawer-layout.md). If you want to use the drawer without React Navigation integration, use the library directly instead.
Copy file name to clipboardExpand all lines: versioned_docs/version-6.x/multiple-drawers.md
+143-7
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,144 @@ title: Multiple drawers
4
4
sidebar_label: Multiple drawers
5
5
---
6
6
7
-
Sometimes we want to have multiple drawers on the same screen: one on the left and one on the right. This can be achieved by [nesting](nesting-navigators.md) 2 [drawer navigators](drawer-navigator.md).
7
+
Sometimes we want to have multiple drawers on the same screen: one on the left and one on the right. This can be achieved in 2 ways:
8
+
9
+
1. By using [`react-native-drawer-layout`](drawer-layout.md) directly (Recommended).
10
+
2. By [nesting](nesting-navigators.md) 2 [drawer navigators](drawer-navigator.md).
11
+
12
+
## Using `react-native-drawer-layout`
13
+
14
+
When we have multiple drawers, only one of them shows the list of screens. The second drawer may often be used to show some additional information such as the list of users etc.
15
+
16
+
In such cases, we can use [`react-native-drawer-layout`](drawer-layout.md) directly to render the second drawer. The drawer navigator will be used to render the first drawer and can be nested inside the second drawer:
renderDrawerContent={() =><>{/* Right drawer content */}</>}
52
+
>
53
+
<LeftDrawerScreen />
54
+
</Drawer>
55
+
);
56
+
}
57
+
58
+
exportdefaultfunctionApp() {
59
+
return (
60
+
<NavigationContainer>
61
+
<RightDrawerScreen />
62
+
</NavigationContainer>
63
+
);
64
+
}
65
+
```
66
+
67
+
But there is one problem. When we call `navigation.openDrawer()` in our `HomeScreen`, it always opens the left drawer. We don't have access to the right drawer via the `navigation` prop since it's not a navigator.
68
+
69
+
To solve this, we need to use context API to pass down a function to control the right drawer:
renderDrawerContent={() =><>{/* Right drawer content */}</>}
121
+
>
122
+
<RightDrawerContext.Provider value={value}>
123
+
<LeftDrawerScreen />
124
+
</RightDrawerContext.Provider>
125
+
</Drawer>
126
+
);
127
+
}
128
+
129
+
exportdefaultfunctionApp() {
130
+
return (
131
+
<NavigationContainer>
132
+
<RightDrawerScreen />
133
+
</NavigationContainer>
134
+
);
135
+
}
136
+
```
137
+
138
+
Here, we are using the `RightDrawerContext` to pass down the `openRightDrawer` function to the `HomeScreen`. Then we use `openRightDrawer` to open the right drawer.
8
139
9
140
## Nesting 2 drawer navigators
10
141
11
-
Here we have 2 drawers nested inside each other, one is positioned on left and the other on the right:
142
+
An alternative approach is to nest 2 [drawer navigators](drawer-navigator.md) inside each other. This is not recommended since it requires creating an additional screen and more nesting - which can make navigating and type checking more verbose. But this can be useful if both navigators include multiple screens.
143
+
144
+
Here we have 2 drawer navigators nested inside each other, one is positioned on left and the other on the right:
@@ -138,12 +273,13 @@ export default function App() {
138
273
</NavigationContainer>
139
274
);
140
275
}
141
-
142
276
```
143
277
144
278
Here, we are passing `"LeftDrawer"` and `"RightDrawer"` strings (you can use any string here) in the `id` prop of the drawer navigators. Then we use `navigation.getParent('LeftDrawer').openDrawer()` to open the left drawer and `navigation.getParent('RightDrawer').openDrawer()` to open the right drawer.
145
279
146
280
## Summary
147
281
148
-
- To have 2 drawers on the screen, you can use the [`drawerPosition`](drawer-navigator.md#drawerposition) option to position them on `"left"` and `"right"`.
149
-
- To open the desired drawer, you can use [`navigation.getParent`](navigation-prop.md#getparent) in combination with the [`id` prop](drawer-navigator.md#id).
282
+
- To have multiple drawers, you can use [`react-native-drawer-layout`](drawer-layout.md) directly in combination with a drawer navigator.
283
+
- The [`drawerPosition`](drawer-layout.md#drawerposition) prop can be used to position the drawer on the right.
284
+
- The methods to control the drawer can be passed down using context API.
285
+
- When nesting multiple navigators, you can use [`navigation.getParent`](navigation-prop.md#getparent) in combination with the [`id` prop](drawer-navigator.md#id) to refer to the desired drawer.
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/drawer-navigator.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Drawer Navigator renders a navigation drawer on the side of the screen which can
12
12
</video>
13
13
</div>
14
14
15
-
This wraps [`react-native-drawer-layout`](drawer-layout.md). If you want to use the tab view without React Navigation integration, use the library directly instead.
15
+
This wraps [`react-native-drawer-layout`](drawer-layout.md). If you want to use the drawer without React Navigation integration, use the library directly instead.
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/multiple-drawers.md
+143-7
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,144 @@ title: Multiple drawers
4
4
sidebar_label: Multiple drawers
5
5
---
6
6
7
-
Sometimes we want to have multiple drawers on the same screen: one on the left and one on the right. This can be achieved by [nesting](nesting-navigators.md) 2 [drawer navigators](drawer-navigator.md).
7
+
Sometimes we want to have multiple drawers on the same screen: one on the left and one on the right. This can be achieved in 2 ways:
8
+
9
+
1. By using [`react-native-drawer-layout`](drawer-layout.md) directly (Recommended).
10
+
2. By [nesting](nesting-navigators.md) 2 [drawer navigators](drawer-navigator.md).
11
+
12
+
## Using `react-native-drawer-layout`
13
+
14
+
When we have multiple drawers, only one of them shows the list of screens. The second drawer may often be used to show some additional information such as the list of users etc.
15
+
16
+
In such cases, we can use [`react-native-drawer-layout`](drawer-layout.md) directly to render the second drawer. The drawer navigator will be used to render the first drawer and can be nested inside the second drawer:
renderDrawerContent={() =><>{/* Right drawer content */}</>}
52
+
>
53
+
<LeftDrawerScreen />
54
+
</Drawer>
55
+
);
56
+
}
57
+
58
+
exportdefaultfunctionApp() {
59
+
return (
60
+
<NavigationContainer>
61
+
<RightDrawerScreen />
62
+
</NavigationContainer>
63
+
);
64
+
}
65
+
```
66
+
67
+
But there is one problem. When we call `navigation.openDrawer()` in our `HomeScreen`, it always opens the left drawer. We don't have access to the right drawer via the `navigation` prop since it's not a navigator.
68
+
69
+
To solve this, we need to use context API to pass down a function to control the right drawer:
renderDrawerContent={() =><>{/* Right drawer content */}</>}
121
+
>
122
+
<RightDrawerContext.Provider value={value}>
123
+
<LeftDrawerScreen />
124
+
</RightDrawerContext.Provider>
125
+
</Drawer>
126
+
);
127
+
}
128
+
129
+
exportdefaultfunctionApp() {
130
+
return (
131
+
<NavigationContainer>
132
+
<RightDrawerScreen />
133
+
</NavigationContainer>
134
+
);
135
+
}
136
+
```
137
+
138
+
Here, we are using the `RightDrawerContext` to pass down the `openRightDrawer` function to the `HomeScreen`. Then we use `openRightDrawer` to open the right drawer.
8
139
9
140
## Nesting 2 drawer navigators
10
141
11
-
Here we have 2 drawers nested inside each other, one is positioned on left and the other on the right:
142
+
An alternative approach is to nest 2 [drawer navigators](drawer-navigator.md) inside each other. This is not recommended since it requires creating an additional screen and more nesting - which can make navigating and type checking more verbose. But this can be useful if both navigators include multiple screens.
143
+
144
+
Here we have 2 drawer navigators nested inside each other, one is positioned on left and the other on the right:
@@ -138,12 +273,13 @@ export default function App() {
138
273
</NavigationContainer>
139
274
);
140
275
}
141
-
142
276
```
143
277
144
278
Here, we are passing `"LeftDrawer"` and `"RightDrawer"` strings (you can use any string here) in the `id` prop of the drawer navigators. Then we use `navigation.getParent('LeftDrawer').openDrawer()` to open the left drawer and `navigation.getParent('RightDrawer').openDrawer()` to open the right drawer.
145
279
146
280
## Summary
147
281
148
-
- To have 2 drawers on the screen, you can use the [`drawerPosition`](drawer-navigator.md#drawerposition) option to position them on `"left"` and `"right"`.
149
-
- To open the desired drawer, you can use [`navigation.getParent`](navigation-prop.md#getparent) in combination with the [`id` prop](drawer-navigator.md#id).
282
+
- To have multiple drawers, you can use [`react-native-drawer-layout`](drawer-layout.md) directly in combination with a drawer navigator.
283
+
- The [`drawerPosition`](drawer-layout.md#drawerposition) prop can be used to position the drawer on the right.
284
+
- The methods to control the drawer can be passed down using context API when using [`react-native-drawer-layout`](drawer-layout.md).
285
+
- When nesting multiple navigators, you can use [`navigation.getParent`](navigation-prop.md#getparent) in combination with the [`id` prop](drawer-navigator.md#id) to refer to the desired drawer.
0 commit comments