Skip to content

Commit a42ebcb

Browse files
committed
chore: migrate examples to react-navigation v7 (#2194)
## Description This PR intents to migrate examples to react-navigation v7. Documentation: https://reactnavigation.org/docs/7.x/upgrading-from-6.x/ As for now I have only found ~~two~~ few files that needed changes. I ensured that nothing crashes in the example. ## Changes - migrated navigating to nested screen - replaced `navigate` with `popTo` when explicitly going back to a specific screen - ensured nothing crashes <!-- ## Screenshots / GIFs Here you can add screenshots / GIFs documenting your change. You can add before / after section if you're changing some behavior. ### Before ### After --> ## Test code and steps to reproduce <!-- Please include code that can be used to test this change and short description how this example should work. This snippet should be as minimal as possible and ready to be pasted into editor (don't exclude exports or remove "not important" parts of reproduction example) --> ## Checklist - [x] Ensured that CI passes
1 parent e02b45b commit a42ebcb

File tree

9 files changed

+12
-12
lines changed

9 files changed

+12
-12
lines changed

apps/examples/src/screens/Animations.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const NavigateScreen = ({
113113

114114
return (
115115
<View style={{ ...styles.container, backgroundColor: 'pink' }}>
116-
<Button title="Go back" onPress={() => navigation.navigate('Main')} />
116+
<Button title="Go back" onPress={() => navigation.popTo('Main')} />
117117
</View>
118118
);
119119
};

apps/test-examples/src/Test1097.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function Second({ navigation }: { navigation: NavigationProp<ParamListBase> }) {
123123
<ScrollView contentInsetAdjustmentBehavior="automatic">
124124
<Button
125125
title="Tap me for first screen"
126-
onPress={() => navigation.navigate('First')}
126+
onPress={() => navigation.popTo('First')}
127127
/>
128128
<Button
129129
title="Tap me for third screen"
@@ -165,7 +165,7 @@ function Third({ navigation }: { navigation: NavigationProp<ParamListBase> }) {
165165
keyboardDismissMode="on-drag">
166166
<Button
167167
title="Tap me for the first screen"
168-
onPress={() => navigation.navigate('First')}
168+
onPress={() => navigation.popTo('First')}
169169
/>
170170
<Button
171171
title="Focus search bar"
@@ -197,7 +197,7 @@ function Third({ navigation }: { navigation: NavigationProp<ParamListBase> }) {
197197
/>
198198
<Button
199199
title="Tap me for the first screen"
200-
onPress={() => navigation.navigate('First')}
200+
onPress={() => navigation.popTo('First')}
201201
/>
202202
<Button
203203
title="Focus search bar"

apps/test-examples/src/Test1166/AndroidDifferentScreenSearch.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function Second({
6060
headerSearchBarOptions: {
6161
autoCapitalize: 'none',
6262
autoFocus: true,
63-
onClose: () => navigation.navigate('First'),
63+
onClose: () => navigation.popTo('First'),
6464
onChangeText: e => setText(e.nativeEvent.text),
6565
barTintColor: text,
6666
},

apps/test-examples/src/Test556.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function Second({ navigation }) {
2929
return (
3030
<Button
3131
title="Tap me for second screen"
32-
onPress={() => navigation.navigate('First')}
32+
onPress={() => navigation.popTo('First')}
3333
/>
3434
);
3535
}

apps/test-examples/src/Test624.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function ThirdScreen({ navigation }) {
7171
<View style={styles.flexOne}>
7272
<TouchableOpacity
7373
style={[styles.centeredContainer, styles.buttonExtras]}
74-
onPress={() => navigation.navigate('Second')}>
74+
onPress={() => navigation.popTo('Second')}>
7575
<Text style={styles.buttonText}>Tap me for second screen</Text>
7676
</TouchableOpacity>
7777
</View>
@@ -122,7 +122,7 @@ function NestedSecond({ navigation }) {
122122
<View style={styles.centeredContainer}>
123123
<TouchableOpacity
124124
style={[styles.centeredContainer, styles.buttonExtras]}
125-
onPress={() => navigation.navigate('NestedFirst')}>
125+
onPress={() => navigation.popTo('NestedFirst')}>
126126
<Text style={styles.buttonText}>Tap me for second screen</Text>
127127
</TouchableOpacity>
128128
</View>

apps/test-examples/src/Test645.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function DetailsScreen({ navigation }) {
3636
function SettingsScreen({ navigation }) {
3737
return (
3838
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
39-
<Button onPress={() => navigation.navigate('Home')} title="Go to Home" />
39+
<Button onPress={() => navigation.popTo('Main', {screen: 'Home'})} title="Go to Home" />
4040
<Text>Details</Text>
4141
</View>
4242
);

apps/test-examples/src/Test648.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function Second({ navigation }) {
3636
<ScrollView>
3737
<Button
3838
title="Tap me for first screen"
39-
onPress={() => navigation.navigate('First')}
39+
onPress={() => navigation.popTo('First')}
4040
/>
4141
</ScrollView>
4242
);

apps/test-examples/src/Test649.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function Second({ navigation }) {
3535
<ScrollView>
3636
<Button
3737
title="Tap me for first screen"
38-
onPress={() => navigation.navigate('First')}
38+
onPress={() => navigation.popTo('First')}
3939
/>
4040
</ScrollView>
4141
);

apps/test-examples/src/Test654.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function Second({ navigation }) {
3737
return (
3838
<Button
3939
title="Tap me for second screen"
40-
onPress={() => navigation.navigate('First')}
40+
onPress={() => navigation.popTo('First')}
4141
/>
4242
);
4343
}

0 commit comments

Comments
 (0)