Skip to content

Commit

Permalink
chore: migrate examples to react-navigation v7 (#2194)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
alduzy authored Jun 21, 2024
1 parent 8d9a278 commit a955764
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion apps/examples/src/screens/Animations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const NavigateScreen = ({

return (
<View style={{ ...styles.container, backgroundColor: 'pink' }}>
<Button title="Go back" onPress={() => navigation.navigate('Main')} />
<Button title="Go back" onPress={() => navigation.popTo('Main')} />
</View>
);
};
Expand Down
6 changes: 3 additions & 3 deletions apps/test-examples/src/Test1097.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function Second({ navigation }: { navigation: NavigationProp<ParamListBase> }) {
<ScrollView contentInsetAdjustmentBehavior="automatic">
<Button
title="Tap me for first screen"
onPress={() => navigation.navigate('First')}
onPress={() => navigation.popTo('First')}
/>
<Button
title="Tap me for third screen"
Expand Down Expand Up @@ -165,7 +165,7 @@ function Third({ navigation }: { navigation: NavigationProp<ParamListBase> }) {
keyboardDismissMode="on-drag">
<Button
title="Tap me for the first screen"
onPress={() => navigation.navigate('First')}
onPress={() => navigation.popTo('First')}
/>
<Button
title="Focus search bar"
Expand Down Expand Up @@ -197,7 +197,7 @@ function Third({ navigation }: { navigation: NavigationProp<ParamListBase> }) {
/>
<Button
title="Tap me for the first screen"
onPress={() => navigation.navigate('First')}
onPress={() => navigation.popTo('First')}
/>
<Button
title="Focus search bar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function Second({
headerSearchBarOptions: {
autoCapitalize: 'none',
autoFocus: true,
onClose: () => navigation.navigate('First'),
onClose: () => navigation.popTo('First'),
onChangeText: e => setText(e.nativeEvent.text),
barTintColor: text,
},
Expand Down
2 changes: 1 addition & 1 deletion apps/test-examples/src/Test556.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Second({ navigation }) {
return (
<Button
title="Tap me for second screen"
onPress={() => navigation.navigate('First')}
onPress={() => navigation.popTo('First')}
/>
);
}
4 changes: 2 additions & 2 deletions apps/test-examples/src/Test624.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function ThirdScreen({ navigation }) {
<View style={styles.flexOne}>
<TouchableOpacity
style={[styles.centeredContainer, styles.buttonExtras]}
onPress={() => navigation.navigate('Second')}>
onPress={() => navigation.popTo('Second')}>
<Text style={styles.buttonText}>Tap me for second screen</Text>
</TouchableOpacity>
</View>
Expand Down Expand Up @@ -122,7 +122,7 @@ function NestedSecond({ navigation }) {
<View style={styles.centeredContainer}>
<TouchableOpacity
style={[styles.centeredContainer, styles.buttonExtras]}
onPress={() => navigation.navigate('NestedFirst')}>
onPress={() => navigation.popTo('NestedFirst')}>
<Text style={styles.buttonText}>Tap me for second screen</Text>
</TouchableOpacity>
</View>
Expand Down
2 changes: 1 addition & 1 deletion apps/test-examples/src/Test645.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function DetailsScreen({ navigation }) {
function SettingsScreen({ navigation }) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button onPress={() => navigation.navigate('Home')} title="Go to Home" />
<Button onPress={() => navigation.popTo('Main', {screen: 'Home'})} title="Go to Home" />
<Text>Details</Text>
</View>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/test-examples/src/Test648.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function Second({ navigation }) {
<ScrollView>
<Button
title="Tap me for first screen"
onPress={() => navigation.navigate('First')}
onPress={() => navigation.popTo('First')}
/>
</ScrollView>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/test-examples/src/Test649.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function Second({ navigation }) {
<ScrollView>
<Button
title="Tap me for first screen"
onPress={() => navigation.navigate('First')}
onPress={() => navigation.popTo('First')}
/>
</ScrollView>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/test-examples/src/Test654.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function Second({ navigation }) {
return (
<Button
title="Tap me for second screen"
onPress={() => navigation.navigate('First')}
onPress={() => navigation.popTo('First')}
/>
);
}

0 comments on commit a955764

Please sign in to comment.