|
1 | | -import { useState } from 'react'; |
| 1 | +import { useRef, useState } from 'react'; |
2 | 2 | import { StyleSheet, View } from 'react-native'; |
3 | 3 | import { GestureDetector, usePinchGesture } from 'react-native-gesture-handler'; |
4 | 4 |
|
5 | 5 | import TestingScreen from '../TestingScreen'; |
| 6 | +import { CallbackIDs } from '../utils'; |
6 | 7 |
|
7 | 8 | export default function PinchScreen() { |
8 | 9 | const [text, setText] = useState(''); |
| 10 | + const callbacks = useRef(new Set<string>()); |
9 | 11 |
|
10 | 12 | const pinchGesture = usePinchGesture({ |
11 | 13 | onBegin: () => { |
12 | | - setText((prev) => prev + '1'); |
| 14 | + callbacks.current.add(CallbackIDs.onBegin); |
13 | 15 | }, |
14 | 16 | onActivate: () => { |
15 | | - setText((prev) => prev + '2'); |
| 17 | + callbacks.current.add(CallbackIDs.onActivate); |
16 | 18 | }, |
17 | 19 | onUpdate: () => { |
18 | | - // Skip subsequent updates |
19 | | - if (text[text.length - 1] === '3') { |
20 | | - return; |
21 | | - } |
22 | | - setText((prev) => prev + '3'); |
| 20 | + callbacks.current.add(CallbackIDs.onUpdate); |
23 | 21 | }, |
24 | 22 | onDeactivate: () => { |
25 | | - setText((prev) => prev + '4'); |
| 23 | + callbacks.current.add(CallbackIDs.onDeactivate); |
26 | 24 | }, |
27 | 25 | onFinalize: () => { |
28 | | - setText((prev) => prev + '5'); |
| 26 | + callbacks.current.add(CallbackIDs.onFinalize); |
29 | 27 | }, |
30 | 28 | runOnJS: true, |
31 | 29 | }); |
32 | 30 |
|
33 | 31 | return ( |
34 | | - <TestingScreen text={text} setText={setText}> |
| 32 | + <TestingScreen |
| 33 | + text={text} |
| 34 | + buttonCallback={() => { |
| 35 | + setText(`{Pinch: ${Array.from(callbacks.current).join('')}}`); |
| 36 | + callbacks.current.clear(); |
| 37 | + }}> |
35 | 38 | <GestureDetector gesture={pinchGesture}> |
36 | 39 | <View style={styles.gestureBox} testID="pinch-box" /> |
37 | 40 | </GestureDetector> |
|
0 commit comments