Skip to content

Commit 421c354

Browse files
committed
feat: show the navigation stack size
1 parent 5c00a06 commit 421c354

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/screens/details.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
import { useNavigation } from '@react-navigation/native';
1+
import { useNavigation, useRoute } from '@react-navigation/native';
22
import { View, Text } from 'react-native';
33
import { Button } from '@react-navigation/elements';
44

55
export type DetailsScreenProps = {
6-
message?: string;
6+
depth: number;
77
};
88

9-
export function DetailsScreen({message = "Details Screen"}: DetailsScreenProps) {
9+
export function DetailsScreen() {
1010
const navigation = useNavigation();
11+
const route = useRoute();
12+
13+
const { depth } = route.params as DetailsScreenProps;
14+
1115
return (
1216
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
13-
<Text>{message}</Text>
14-
<Button onPress={() => navigation.push('Details')}>Go Deeper</Button>
17+
<Text>You are currently {depth} screens deep</Text>
18+
<Button onPress={() => navigation.push('Details', {depth: (depth + 1)})}>Go Deeper</Button>
1519
<Button onPress={() => navigation.goBack('Details')}>Go Back</Button>
1620
<Button onPress={() => navigation.popTo('Home')}>Go Home</Button>
1721
</View>

src/screens/home.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function HomeScreen({message = "Home Screen"}: HomeScreenProps) {
1212
return (
1313
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
1414
<Text>{message}</Text>
15-
<Button onPress={() => navigation.push('Details')}>Go to Details</Button>
15+
<Button onPress={() => navigation.push('Details', {depth: 1})}>Go to Details</Button>
1616
</View>
1717
);
1818
}

0 commit comments

Comments
 (0)