Skip to content

Commit 14af773

Browse files
committed
Document layout and screenLayout props
1 parent fadf41c commit 14af773

File tree

5 files changed

+372
-27
lines changed

5 files changed

+372
-27
lines changed

versioned_docs/version-7.x/custom-navigators.md

+35-5
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,25 @@ import {
5757
} from '@react-navigation/native';
5858

5959
function TabNavigator({
60+
id,
6061
initialRouteName,
6162
children,
63+
layout,
64+
screenListeners,
6265
screenOptions,
66+
screenLayout,
6367
tabBarStyle,
6468
contentStyle,
6569
}) {
6670
const { state, navigation, descriptors, NavigationContent } =
6771
useNavigationBuilder(TabRouter, {
72+
id,
73+
initialRouteName,
6874
children,
75+
layout,
76+
screenListeners,
6977
screenOptions,
70-
initialRouteName,
78+
screenLayout,
7179
});
7280

7381
return (
@@ -235,9 +243,14 @@ type Props = DefaultNavigatorOptions<
235243
TabNavigationConfig;
236244

237245
function TabNavigator({
246+
id,
238247
initialRouteName,
239248
children,
249+
layout,
250+
screenListeners,
240251
screenOptions,
252+
screenLayout,
253+
backBehavior,
241254
tabBarStyle,
242255
contentStyle,
243256
}: Props) {
@@ -249,9 +262,14 @@ function TabNavigator({
249262
TabNavigationOptions,
250263
TabNavigationEventMap
251264
>(TabRouter, {
265+
id,
266+
initialRouteName,
252267
children,
268+
layout,
269+
screenListeners,
253270
screenOptions,
254-
initialRouteName,
271+
screenLayout,
272+
backBehavior,
255273
});
256274

257275
return (
@@ -343,18 +361,26 @@ import {
343361
import { BottomTabView } from '@react-navigation/bottom-tabs';
344362

345363
function BottomTabNavigator({
364+
id,
346365
initialRouteName,
347-
backBehavior,
348366
children,
367+
layout,
368+
screenListeners,
349369
screenOptions,
370+
screenLayout,
371+
backBehavior,
350372
...rest
351373
}) {
352374
const { state, descriptors, navigation, NavigationContent } =
353375
useNavigationBuilder(TabRouter, {
376+
id,
354377
initialRouteName,
355-
backBehavior,
356378
children,
379+
layout,
380+
screenListeners,
357381
screenOptions,
382+
screenLayout,
383+
backBehavior,
358384
});
359385

360386
return (
@@ -383,10 +409,14 @@ import MyRouter from './MyRouter';
383409

384410
const { state, descriptors, navigation, NavigationContent } =
385411
useNavigationBuilder(MyRouter, {
412+
id,
386413
initialRouteName,
387-
backBehavior,
388414
children,
415+
layout,
416+
screenListeners,
389417
screenOptions,
418+
screenLayout,
419+
backBehavior,
390420
});
391421

392422
// ...

versioned_docs/version-7.x/group.md

+79-4
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,11 @@ Options to configure how the screens inside the group get presented in the navig
148148
const MyStack = createNativeStackNavigator({
149149
groups: {
150150
Modal: {
151+
// highlight-start
151152
screenOptions: {
152153
presentation: 'modal',
153154
},
155+
// highlight-end
154156
screens: {
155157
/* screens */
156158
},
@@ -162,11 +164,13 @@ const MyStack = createNativeStackNavigator({
162164
</TabItem>
163165
<TabItem value="dynamic" label="Dynamic">
164166

165-
```js
167+
```jsx
166168
<Stack.Group
169+
// highlight-start
167170
screenOptions={{
168171
presentation: 'modal',
169172
}}
173+
// highlight-end
170174
>
171175
{/* screens */}
172176
</Stack.Group>
@@ -184,9 +188,11 @@ When you pass a function, it'll receive the [`route`](route-object.md) and [`nav
184188
const MyStack = createNativeStackNavigator({
185189
groups: {
186190
Modal: {
191+
// highlight-start
187192
screenOptions: ({ route, navigation }) => ({
188193
title: route.params.title,
189194
}),
195+
// highlight-end
190196
screens: {
191197
/* screens */
192198
},
@@ -198,11 +204,13 @@ const MyStack = createNativeStackNavigator({
198204
</TabItem>
199205
<TabItem value="dynamic" label="Dynamic">
200206

201-
```js
207+
```jsx
202208
<Stack.Group
209+
// highlight-start
203210
screenOptions={({ route, navigation }) => ({
204211
title: route.params.title,
205212
})}
213+
// highlight-end
206214
>
207215
{/* screens */}
208216
</Stack.Group>
@@ -215,6 +223,68 @@ These options are merged with the `options` specified in the individual screens,
215223

216224
See [Options for screens](screen-options.md) for more details and examples.
217225

226+
### Screen layout
227+
228+
A screen layout is a wrapper around each screen in the group. It makes it easier to provide things such as a common error boundary and suspense fallback for all screens in a group:
229+
230+
<Tabs groupId="config" queryString="config">
231+
<TabItem value="static" label="Static" default>
232+
233+
```js
234+
const MyStack = createNativeStackNavigator({
235+
groups: {
236+
Modal: {
237+
// highlight-start
238+
screenLayout: ({ children }) => (
239+
<ErrorBoundary>
240+
<React.Suspense
241+
fallback={
242+
<View style={styles.fallback}>
243+
<Text style={styles.text}>Loading…</Text>
244+
</View>
245+
}
246+
>
247+
{children}
248+
</React.Suspense>
249+
</ErrorBoundary>
250+
),
251+
// highlight-end
252+
screens: {
253+
/* screens */
254+
},
255+
},
256+
},
257+
});
258+
```
259+
260+
</TabItem>
261+
<TabItem value="dynamic" label="Dynamic">
262+
263+
```jsx
264+
<Stack.Group
265+
// highlight-start
266+
screenLayout={({ children }) => (
267+
<ErrorBoundary>
268+
<React.Suspense
269+
fallback={
270+
<View style={styles.fallback}>
271+
<Text style={styles.text}>Loading…</Text>
272+
</View>
273+
}
274+
>
275+
{children}
276+
</React.Suspense>
277+
</ErrorBoundary>
278+
)}
279+
// highlight-end
280+
>
281+
{/* screens */}
282+
</Stack.Group>
283+
```
284+
285+
</TabItem>
286+
</Tabs>
287+
218288
### Navigation key
219289

220290
Optional key for a group of screens. If the key changes, all existing screens in this group will be removed (if used in a stack navigator) or reset (if used in a tab or drawer navigator):
@@ -227,11 +297,13 @@ The name of the group is used as the `navigationKey`:
227297
```js
228298
const MyStack = createNativeStackNavigator({
229299
groups: {
300+
// highlight-next-line
230301
User: {
231302
screens: {
232303
/* screens */
233304
},
234305
},
306+
// highlight-next-line
235307
Guest: {
236308
screens: {
237309
/* screens */
@@ -246,8 +318,11 @@ This means if a screen is defined in 2 groups and the groups use the [`if`](stat
246318
</TabItem>
247319
<TabItem value="dynamic" label="Dynamic">
248320

249-
```js
250-
<Stack.Group navigationKey={isSignedIn ? 'user' : 'guest'}>
321+
```jsx
322+
<Stack.Group
323+
// highlight-next-line
324+
navigationKey={isSignedIn ? 'user' : 'guest'}
325+
>
251326
{/* screens */}
252327
</Stack.Group>
253328
```

0 commit comments

Comments
 (0)