|
1 | 1 | import * as React from 'react'; |
2 | 2 | import { Button, Text } from 'react-native'; |
3 | | -import type { ScreenProps } from '../types/Navigation'; |
| 3 | +import type { Routes } from '../types/Navigation'; |
4 | 4 | import { SafeAreaViewVisualizer } from './SafeAreaViewVisualizer'; |
| 5 | +import { useNavigation } from '@react-navigation/native'; |
| 6 | +import { NativeStackNavigationProp } from '@react-navigation/native-stack'; |
5 | 7 |
|
6 | | -export default function ReactNavigationDetailScreen({ |
7 | | - navigation, |
8 | | -}: ScreenProps<'Details'>) { |
9 | | - const isV5 = typeof navigation.setOptions === 'function'; |
| 8 | +export default function ReactNavigationDetailScreen() { |
10 | 9 | const [headerShown, setHeaderShown] = React.useState(true); |
| 10 | + const { navigate, goBack, setOptions, push } = |
| 11 | + useNavigation<NativeStackNavigationProp<Routes>>(); |
| 12 | + |
| 13 | + const isV5 = typeof setOptions === 'function'; |
11 | 14 |
|
12 | 15 | React.useLayoutEffect(() => { |
13 | 16 | if (isV5) { |
14 | | - navigation.setOptions({ headerShown }); |
| 17 | + setOptions({ headerShown }); |
15 | 18 | } |
16 | | - }, [navigation, isV5, headerShown]); |
| 19 | + }, [setOptions, isV5, headerShown]); |
17 | 20 |
|
18 | 21 | return ( |
19 | 22 | <SafeAreaViewVisualizer> |
20 | 23 | <Text>Details Screen</Text> |
21 | | - <Button |
22 | | - title="Go to Details... again" |
23 | | - onPress={() => navigation.push('Details')} |
24 | | - /> |
25 | | - <Button title="Go to Home" onPress={() => navigation.navigate('Home')} /> |
26 | | - <Button title="Go back" onPress={() => navigation.goBack()} /> |
| 24 | + <Button title="Go to Details... again" onPress={() => push('Details')} /> |
| 25 | + <Button title="Go to Home" onPress={() => navigate('Home')} /> |
| 26 | + <Button title="Go back" onPress={() => goBack()} /> |
27 | 27 | {isV5 && ( |
28 | 28 | <Button |
29 | 29 | title="Toggle header" |
|
0 commit comments