File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { useNavigation } from '@react-navigation/native' ;
1+ import { useNavigation , useRoute } from '@react-navigation/native' ;
22import { View , Text } from 'react-native' ;
33import { Button } from '@react-navigation/elements' ;
44
55export 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 >
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments