|
1 | 1 | import * as React from 'react'; |
2 | | -import { Animated, Button, useAnimatedValue } from 'react-native'; |
3 | | -import { |
4 | | - GestureHandlerRootView, |
5 | | - NativeDetector, |
6 | | - useGesture, |
7 | | -} from 'react-native-gesture-handler'; |
| 2 | +import { SafeAreaView, Platform } from 'react-native'; |
| 3 | +import { GestureHandlerRootView } from 'react-native-gesture-handler'; |
8 | 4 |
|
9 | | -export default function App() { |
10 | | - const [visible, setVisible] = React.useState(true); |
11 | | - |
12 | | - const value = useAnimatedValue(0); |
13 | | - const event = Animated.event( |
14 | | - [{ nativeEvent: { handlerData: { translationX: value } } }], |
15 | | - { |
16 | | - useNativeDriver: true, |
17 | | - } |
18 | | - ); |
| 5 | +import Navigator from './Navigator'; |
19 | 6 |
|
20 | | - const tap = useGesture('PanGestureHandler', { |
21 | | - // numberOfTaps: 2, |
22 | | - // needsPointerData: true, |
23 | | - // onGestureHandlerStateChange: (event) => { |
24 | | - // console.log('onHandlerStateChange', event.nativeEvent); |
25 | | - // }, |
26 | | - onGestureHandlerAnimatedEvent: event, |
27 | | - onGestureHandlerEvent: (e: any) => |
28 | | - console.log('onGestureHandlerEvent', e.nativeEvent), |
29 | | - // onGestureHandlerTouchEvent: (event) => console.log('onGestureTouchEvent', event.nativeEvent), |
30 | | - }); |
| 7 | +import NativeDetector from './NativeDetector'; |
| 8 | +import RuntimeDecoration from './RuntimeDecoration'; |
31 | 9 |
|
32 | | - return ( |
33 | | - <GestureHandlerRootView |
34 | | - style={{ flex: 1, backgroundColor: 'white', paddingTop: 150 }}> |
35 | | - <Button |
36 | | - title="Toggle" |
37 | | - onPress={() => { |
38 | | - setVisible(!visible); |
39 | | - }} |
40 | | - /> |
| 10 | +const EXAMPLES = [ |
| 11 | + { |
| 12 | + name: 'Runtime Decoration', |
| 13 | + component: RuntimeDecoration, |
| 14 | + }, |
| 15 | + { |
| 16 | + name: 'Native Detector', |
| 17 | + component: NativeDetector, |
| 18 | + }, |
| 19 | +]; |
41 | 20 |
|
42 | | - {visible && ( |
43 | | - <NativeDetector gesture={tap}> |
44 | | - <Animated.View |
45 | | - style={[ |
46 | | - { |
47 | | - width: 150, |
48 | | - height: 150, |
49 | | - backgroundColor: 'blue', |
50 | | - opacity: 0.5, |
51 | | - borderWidth: 10, |
52 | | - borderColor: 'green', |
53 | | - marginTop: 20, |
54 | | - marginLeft: 40, |
| 21 | +const Stack = Navigator.create(); |
| 22 | +Stack.setRoutes( |
| 23 | + Object.fromEntries( |
| 24 | + EXAMPLES.map((example, index) => [ |
| 25 | + example.name.toLowerCase().replace(/\s+/g, ''), |
| 26 | + { |
| 27 | + component: example.component, |
| 28 | + title: example.name, |
| 29 | + rightButtonAction: |
| 30 | + index === EXAMPLES.length - 1 |
| 31 | + ? undefined |
| 32 | + : () => { |
| 33 | + Stack.navigateTo( |
| 34 | + EXAMPLES[index + 1].name.toLowerCase().replace(/\s+/g, '') |
| 35 | + ); |
55 | 36 | }, |
56 | | - { transform: [{ translateX: value }] }, |
57 | | - ]} |
58 | | - /> |
59 | | - </NativeDetector> |
60 | | - )} |
| 37 | + }, |
| 38 | + ]) |
| 39 | + ) |
| 40 | +); |
| 41 | + |
| 42 | +export default function App() { |
| 43 | + return ( |
| 44 | + <GestureHandlerRootView style={{ flex: 1 }}> |
| 45 | + <SafeAreaView |
| 46 | + style={[{ flex: 1 }, Platform.OS === 'android' && { paddingTop: 50 }]}> |
| 47 | + <Stack.Navigator /> |
| 48 | + </SafeAreaView> |
61 | 49 | </GestureHandlerRootView> |
62 | 50 | ); |
63 | 51 | } |
0 commit comments