|
| 1 | +import { NavigationContainer } from '@react-navigation/native'; |
| 2 | +import { createNativeStackNavigator, NativeStackNavigationProp } from '@react-navigation/native-stack'; |
| 3 | +import React from 'react'; |
| 4 | +import { findNodeHandle, Text, View } from 'react-native'; |
| 5 | +import PressableWithFeedback from '../shared/PressableWithFeedback'; |
| 6 | + |
| 7 | +type StackParamList = { |
| 8 | + Home: undefined, |
| 9 | +} |
| 10 | + |
| 11 | +type RouteProps = { |
| 12 | + navigation: NativeStackNavigationProp<StackParamList>; |
| 13 | +} |
| 14 | + |
| 15 | +const Stack = createNativeStackNavigator<StackParamList>(); |
| 16 | + |
| 17 | +function HeaderTitle(): React.JSX.Element { |
| 18 | + return ( |
| 19 | + <PressableWithFeedback |
| 20 | + onLayout={event => { |
| 21 | + const { x, y, width, height } = event.nativeEvent.layout; |
| 22 | + console.log('Title onLayout', { x, y, width, height }); |
| 23 | + }} |
| 24 | + onPressIn={() => { |
| 25 | + console.log('Pressable onPressIn'); |
| 26 | + }} |
| 27 | + onPress={() => console.log('Pressable onPress')} |
| 28 | + onPressOut={() => console.log('Pressable onPressOut')} |
| 29 | + onResponderMove={() => console.log('Pressable onResponderMove')} |
| 30 | + ref={node => { |
| 31 | + console.log(findNodeHandle(node)); |
| 32 | + node?.measure((x, y, width, height, pageX, pageY) => { |
| 33 | + console.log('header component measure', { x, y, width, height, pageX, pageY }); |
| 34 | + }); |
| 35 | + }} |
| 36 | + > |
| 37 | + <View style={{ height: 40, justifyContent: 'center', alignItems: 'center' }}> |
| 38 | + <Text style={{ alignItems: 'center' }}>Regular Pressable</Text> |
| 39 | + </View> |
| 40 | + </PressableWithFeedback> |
| 41 | + ); |
| 42 | +} |
| 43 | + |
| 44 | +function HeaderLeft(): React.JSX.Element { |
| 45 | + return ( |
| 46 | + <HeaderTitle /> |
| 47 | + ); |
| 48 | +} |
| 49 | + |
| 50 | +function Home(_: RouteProps): React.JSX.Element { |
| 51 | + return ( |
| 52 | + <View style={{ flex: 1, backgroundColor: 'rgba(0, 0, 0, .8)' }} |
| 53 | + > |
| 54 | + <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center',marginTop: 48 }}> |
| 55 | + <PressableWithFeedback |
| 56 | + onPressIn={() => console.log('Pressable onPressIn')} |
| 57 | + onPress={() => console.log('Pressable onPress')} |
| 58 | + onPressOut={() => console.log('Pressable onPressOut')} |
| 59 | + > |
| 60 | + <View style={{ height: 40, width: 200, justifyContent: 'center', alignItems: 'center' }}> |
| 61 | + <Text style={{ alignItems: 'center' }}>Regular Pressable</Text> |
| 62 | + </View> |
| 63 | + </PressableWithFeedback> |
| 64 | + </View> |
| 65 | + </View> |
| 66 | + ); |
| 67 | +} |
| 68 | + |
| 69 | +function App(): React.JSX.Element { |
| 70 | + return ( |
| 71 | + <NavigationContainer> |
| 72 | + <Stack.Navigator> |
| 73 | + <Stack.Screen |
| 74 | + name="Home" |
| 75 | + component={Home} |
| 76 | + options={{ |
| 77 | + headerTransparent: true, |
| 78 | + headerTitle: HeaderTitle, |
| 79 | + headerLeft: HeaderLeft, |
| 80 | + headerRight: HeaderLeft, |
| 81 | + }} |
| 82 | + /> |
| 83 | + </Stack.Navigator> |
| 84 | + </NavigationContainer> |
| 85 | + ); |
| 86 | +} |
| 87 | + |
| 88 | +export default App; |
0 commit comments