Skip to content

Commit 79ff31a

Browse files
committed
Migrate more files to use static2dynamic
1 parent ba9c946 commit 79ff31a

14 files changed

+359
-2839
lines changed

versioned_docs/version-7.x/drawer-actions.md

Lines changed: 26 additions & 497 deletions
Large diffs are not rendered by default.

versioned_docs/version-7.x/navigation-actions.md

Lines changed: 220 additions & 1042 deletions
Large diffs are not rendered by default.

versioned_docs/version-7.x/navigation-context.md

Lines changed: 5 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ Most of the time, you won't use `NavigationContext` directly, as the provided `u
1313

1414
Example:
1515

16-
<Tabs groupId="config" queryString="config">
17-
<TabItem value="static" label="Static" default>
18-
19-
```js name="Navigation context" snack
16+
```js name="Navigation context" snack static2dynamic
2017
import * as React from 'react';
2118
import { View, Text } from 'react-native';
2219
import { Button } from '@react-navigation/elements';
@@ -48,7 +45,9 @@ function SomeComponent() {
4845
</Button>
4946
</View>
5047
);
48+
// codeblock-focus-start
5149
}
50+
// codeblock-focus-end
5251

5352
function ProfileScreen() {
5453
const navigation = useNavigation();
@@ -60,82 +59,19 @@ function ProfileScreen() {
6059
);
6160
}
6261

63-
const Stack = createNativeStackNavigator({
62+
const RootStack = createNativeStackNavigator({
6463
initialRouteName: 'Home',
6564
screens: {
6665
Home: HomeScreen,
6766
Profile: ProfileScreen,
6867
},
6968
});
7069

71-
const Navigation = createStaticNavigation(Stack);
70+
const Navigation = createStaticNavigation(RootStack);
7271

7372
function App() {
7473
return <Navigation />;
7574
}
7675

7776
export default App;
7877
```
79-
80-
</TabItem>
81-
<TabItem value="dynamic" label="Dynamic">
82-
83-
```js name="Navigation context" snack
84-
import * as React from 'react';
85-
import { View, Text } from 'react-native';
86-
import { Button } from '@react-navigation/elements';
87-
// codeblock-focus-start
88-
import { NavigationContext } from '@react-navigation/native';
89-
// codeblock-focus-end
90-
import { NavigationContainer } from '@react-navigation/native';
91-
import { createNativeStackNavigator } from '@react-navigation/native-stack';
92-
93-
function HomeScreen() {
94-
return <SomeComponent />;
95-
}
96-
97-
// codeblock-focus-start
98-
99-
function SomeComponent() {
100-
// We can access navigation object via context
101-
const navigation = React.useContext(NavigationContext);
102-
// codeblock-focus-end
103-
104-
return (
105-
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
106-
<Text>Some component inside HomeScreen</Text>
107-
<Button onPress={() => navigation.navigate('Profile')}>
108-
Go to Profile
109-
</Button>
110-
</View>
111-
);
112-
}
113-
114-
function ProfileScreen() {
115-
const navigation = React.useContext(NavigationContext);
116-
117-
return (
118-
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
119-
<Button onPress={() => navigation.goBack()}>Go back</Button>
120-
</View>
121-
);
122-
}
123-
124-
const Stack = createNativeStackNavigator();
125-
126-
function App() {
127-
return (
128-
<NavigationContainer>
129-
<Stack.Navigator initialRouteName="Home">
130-
<Stack.Screen name="Home" component={HomeScreen} />
131-
<Stack.Screen name="Profile" component={ProfileScreen} />
132-
</Stack.Navigator>
133-
</NavigationContainer>
134-
);
135-
}
136-
137-
export default App;
138-
```
139-
140-
</TabItem>
141-
</Tabs>

versioned_docs/version-7.x/screen-options.md

Lines changed: 14 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ You can pass a prop named `options` to the `Screen` component to configure a scr
2222
```js name="Screen title option" snack static2dynamic
2323
import * as React from 'react';
2424
import { View, Text } from 'react-native';
25-
import Button from '@react-navigation/elements';
25+
import { Button } from '@react-navigation/elements';
2626
import {
2727
createStaticNavigation,
2828
useNavigation,
@@ -54,7 +54,7 @@ function ProfileScreen() {
5454
}
5555

5656
// codeblock-focus-start
57-
const Stack = createNativeStackNavigator({
57+
const RootStack = createNativeStackNavigator({
5858
screens: {
5959
Home: {
6060
screen: HomeScreen,
@@ -71,7 +71,7 @@ const Stack = createNativeStackNavigator({
7171
},
7272
});
7373

74-
const Navigation = createStaticNavigation(Stack);
74+
const Navigation = createStaticNavigation(RootStack);
7575

7676
export default function App() {
7777
return <Navigation />;
@@ -81,11 +81,8 @@ export default function App() {
8181

8282
You can also pass a function to `options`. The function will receive the [`navigation` object](navigation-object.md) and the [`route` object](route-object.md) for that screen, as well as the [`theme` object](themes.md). This can be useful if you want to perform navigation in your options:
8383

84-
<Tabs groupId="config" queryString="config">
85-
<TabItem value="static" label="Static" default>
86-
87-
```js
88-
const Stack = createNativeStackNavigator({
84+
```js static2dynamic
85+
const RootStack = createNativeStackNavigator({
8986
screens: {
9087
Home: {
9188
screen: HomeScreen,
@@ -100,25 +97,6 @@ const Stack = createNativeStackNavigator({
10097
});
10198
```
10299

103-
</TabItem>
104-
<TabItem value="dynamic" label="Dynamic">
105-
106-
```js
107-
<Stack.Screen
108-
name="Home"
109-
component={HomeScreen}
110-
options={({ navigation }) => ({
111-
title: 'Awesome app',
112-
headerLeft: () => (
113-
<DrawerButton onPress={() => navigation.toggleDrawer()} />
114-
),
115-
})}
116-
/>
117-
```
118-
119-
</TabItem>
120-
</Tabs>
121-
122100
### `screenOptions` prop on `Group`
123101

124102
You can pass a prop named `screenOptions` to the `Group` component to configure screens inside the group, where you can specify an object with different options. The options specified in `screenOptions` apply to all of the screens in the group.
@@ -139,7 +117,7 @@ import {
139117
import { createNativeStackNavigator } from '@react-navigation/native-stack';
140118

141119
// codeblock-focus-start
142-
const Stack = createNativeStackNavigator({
120+
const RootStack = createNativeStackNavigator({
143121
groups: {
144122
App: {
145123
screenOptions: {
@@ -180,7 +158,9 @@ function ScreenWithButton(screenName, navigateTo) {
180158
);
181159
};
182160
}
183-
const Navigation = createStaticNavigation(Stack);
161+
162+
const Navigation = createStaticNavigation(RootStack);
163+
184164
export default function App() {
185165
return <Navigation />;
186166
}
@@ -299,11 +279,8 @@ You can pass a prop named `screenOptions` to the navigator component, where you
299279

300280
Example:
301281

302-
<Tabs groupId="config" queryString="config">
303-
<TabItem value="static" label="Static" default>
304-
305-
```js
306-
const Stack = createNativeStackNavigator({
282+
```js static2dynamic
283+
const RootStack = createNativeStackNavigator({
307284
screenOptions: {
308285
headerStyle: {
309286
backgroundColor: 'papayawhip',
@@ -316,35 +293,17 @@ const Stack = createNativeStackNavigator({
316293
});
317294
```
318295

319-
</TabItem>
320-
<TabItem value="dynamic" label="Dynamic">
321-
322-
```js
323-
<Stack.Navigator
324-
screenOptions={{ headerStyle: { backgroundColor: 'papayawhip' } }}
325-
>
326-
<Stack.Screen name="Home" component={HomeScreen} />
327-
<Stack.Screen name="Profile" component={ProfileScreen} />
328-
</Stack.Navigator>
329-
```
330-
331-
</TabItem>
332-
</Tabs>
333-
334296
Similar to `options`, you can also pass a function to `screenOptions`. The function will receive the [`navigation` object](navigation-object.md) and the [`route` object](route-object.md) for each screen. This can be useful if you want to configure options for all the screens in one place based on the route:
335297

336-
<Tabs groupId="config" queryString="config">
337-
<TabItem value="static" label="Static" default>
338-
339-
```js name="Screen options for tab navigator" snack dependencies=@expo/vector-icons
298+
```js name="Screen options for tab navigator" snack dependencies=@expo/vector-icons static2dynamic
340299
import * as React from 'react';
341300
import { View } from 'react-native';
342301
import { createStaticNavigation } from '@react-navigation/native';
343302
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
344303
import { MaterialCommunityIcons } from '@expo/vector-icons';
345304

346305
// codeblock-focus-start
347-
const Tab = createBottomTabNavigator({
306+
const MyTabs = createBottomTabNavigator({
348307
screenOptions: ({ route }) => ({
349308
tabBarIcon: ({ color, size }) => {
350309
const icons = {
@@ -372,63 +331,13 @@ function EmptyScreen() {
372331
return <View />;
373332
}
374333

375-
const Navigation = createStaticNavigation(Tab);
334+
const Navigation = createStaticNavigation(MyTabs);
376335

377336
export default function App() {
378337
return <Navigation />;
379338
}
380339
```
381340

382-
</TabItem>
383-
<TabItem value="dynamic" label="Dynamic">
384-
385-
```js name="Screen options for tab navigator" snack dependencies=@expo/vector-icons
386-
import * as React from 'react';
387-
import { View } from 'react-native';
388-
import { NavigationContainer } from '@react-navigation/native';
389-
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
390-
import { MaterialCommunityIcons } from '@expo/vector-icons';
391-
392-
const Tab = createBottomTabNavigator();
393-
394-
function EmptyScreen() {
395-
return <View />;
396-
}
397-
398-
export default function App() {
399-
return (
400-
<NavigationContainer>
401-
// codeblock-focus-start
402-
<Tab.Navigator
403-
screenOptions={({ route }) => ({
404-
tabBarIcon: ({ color, size }) => {
405-
const icons = {
406-
Home: 'home',
407-
Profile: 'account',
408-
};
409-
410-
return (
411-
<MaterialCommunityIcons
412-
name={icons[route.name]}
413-
color={color}
414-
size={size}
415-
/>
416-
);
417-
},
418-
})}
419-
>
420-
<Tab.Screen name="Home" component={EmptyScreen} />
421-
<Tab.Screen name="Profile" component={EmptyScreen} />
422-
</Tab.Navigator>
423-
// codeblock-focus-end
424-
</NavigationContainer>
425-
);
426-
}
427-
```
428-
429-
</TabItem>
430-
</Tabs>
431-
432341
### `navigation.setOptions` method
433342

434343
The `navigation` object has a `setOptions` method that lets you update the options for a screen from within a component. See [navigation object's docs](navigation-object.md#setoptions) for more details.

0 commit comments

Comments
 (0)