Skip to content

Commit 8a08603

Browse files
committed
docs: Added screem options examples
1 parent 8e76fcc commit 8a08603

File tree

1 file changed

+84
-1
lines changed

1 file changed

+84
-1
lines changed

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

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ title: Stack Navigator
44
sidebar_label: Stack
55
---
66

7+
import Tabs from '@theme/Tabs';
8+
import TabItem from '@theme/TabItem';
9+
710
Stack Navigator provides a way for your app to transition between screens where each new screen is placed on top of a stack.
811

912
By default the stack navigator is configured to have the familiar iOS and Android look & feel: new screens slide in from the right on iOS, use OS default animation on Android. But the [animations can be customized](#animation-related-options) to match your needs.
@@ -214,9 +217,89 @@ If you need to disable this optimization for specific screens (e.g. you want to
214217
### Options
215218

216219
The following [options](screen-options.md) can be used to configure the screens in the navigator. These can be specified under:
217-
* [`screenOptions`](screen-options.md#options-prop-on-screen) prop of `Stack.navigator` or
220+
* [`screenOptions`](screen-options.md#options-prop-on-screen) prop of `Stack.navigator`
221+
222+
Example:
223+
224+
<Tabs groupId="config" queryString="config">
225+
<TabItem value="static" label="Static" default>
226+
227+
```js
228+
const Stack = createNativeStackNavigator({
229+
screenOptions: {
230+
headerStyle: {
231+
backgroundColor: 'papayawhip',
232+
},
233+
},
234+
screens: {
235+
Home: HomeScreen,
236+
Profile: ProfileScreen,
237+
},
238+
});
239+
```
240+
241+
</TabItem>
242+
<TabItem value="dynamic" label="Dynamic">
243+
244+
```js
245+
<Stack.Navigator
246+
screenOptions={{ headerStyle: { backgroundColor: 'papayawhip' } }}
247+
>
248+
<Stack.Screen name="Home" component={HomeScreen} />
249+
<Stack.Screen name="Profile" component={ProfileScreen} />
250+
</Stack.Navigator>
251+
```
252+
253+
</TabItem>
254+
</Tabs>
255+
256+
218257
* [`options`](screen-options.md#screenoptions-prop-on-the-navigator) prop of `Stack.Screen`.
219258

259+
Example:
260+
<Tabs groupId="config" queryString="config">
261+
<TabItem value="static" label="Static" default>
262+
263+
```js name="Screen title option"
264+
const Stack = createNativeStackNavigator({
265+
screens: {
266+
Home: {
267+
screen: HomeScreen,
268+
options: {
269+
title: 'Awesome app',
270+
},
271+
},
272+
Profile: {
273+
screen: ProfileScreen,
274+
options: {
275+
title: 'My profile',
276+
},
277+
},
278+
},
279+
});
280+
```
281+
282+
</TabItem>
283+
<TabItem value="dynamic" label="Dynamic">
284+
285+
```js name="Screen title option"
286+
<Stack.Navigator>
287+
<Stack.Screen
288+
name="Home"
289+
component={HomeScreen}
290+
options={{ title: 'Awesome app' }}
291+
/>
292+
<Stack.Screen
293+
name="Profile"
294+
component={ProfileScreen}
295+
options={{ title: 'My profile' }}
296+
/>
297+
</Stack.Navigator>
298+
```
299+
300+
</TabItem>
301+
</Tabs>
302+
220303
#### `title`
221304

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

0 commit comments

Comments
 (0)