-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathdelayedPressExample.tsx
More file actions
86 lines (78 loc) · 1.92 KB
/
delayedPressExample.tsx
File metadata and controls
86 lines (78 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React from 'react';
import { StyleSheet, View } from 'react-native';
import TestingBase from './testingBase';
import Animated, {
useAnimatedStyle,
useSharedValue,
withSequence,
withSpring,
} from 'react-native-reanimated';
const signalerConfig = {
duration: 200,
dampingRatio: 1,
stiffness: 500,
overshootClamping: true,
restDisplacementThreshold: 0.01,
restSpeedThreshold: 2,
};
export function DelayedPressExample() {
const startColor = '#fff';
const pressColor = '#ff0';
const longPressColor = '#f0f';
const animatedColor = useSharedValue(startColor);
const pressDelay = 1000;
const longPressDelay = 1000;
const onPressIn = () => {
console.log('Pressed with delay');
animatedColor.value = withSequence(
withSpring(pressColor, signalerConfig),
withSpring(startColor, signalerConfig)
);
};
const onLongPress = () => {
console.log('Long pressed with delay');
animatedColor.value = withSequence(
withSpring(longPressColor, signalerConfig),
withSpring(startColor, signalerConfig)
);
};
const signalerStyle = useAnimatedStyle(() => ({
backgroundColor: animatedColor.value,
}));
return (
<>
<Animated.View style={[signalerStyle, styles.signaler]} />
<View style={styles.container}>
<TestingBase
style={styles.pressable}
delayLongPress={longPressDelay}
unstable_pressDelay={pressDelay}
onPressIn={onPressIn}
onLongPress={onLongPress}
/>
</View>
</>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
gap: 40,
padding: 20,
},
pressable: {
width: 100,
height: 100,
backgroundColor: 'mediumpurple',
},
signaler: {
width: 50,
height: 50,
borderRadius: 25,
marginTop: 15,
borderWidth: StyleSheet.hairlineWidth,
},
});