-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathindex.tsx
More file actions
69 lines (64 loc) · 1.66 KB
/
index.tsx
File metadata and controls
69 lines (64 loc) · 1.66 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
import React, { Component } from 'react';
import { Animated, StyleSheet, View, Text } from 'react-native';
import {
State,
ForceTouchGestureHandler,
ForceTouchGestureHandlerStateChangeEvent,
} from 'react-native-gesture-handler';
import { USE_NATIVE_DRIVER } from '../../config';
export default class Example extends Component {
private force = new Animated.Value(0);
private onGestureEvent = Animated.event(
[
{
nativeEvent: {
force: this.force,
},
},
],
{ useNativeDriver: USE_NATIVE_DRIVER }
);
private onHandlerStateChange = (
event: ForceTouchGestureHandlerStateChangeEvent
) => {
if (event.nativeEvent.oldState === State.ACTIVE) {
this.force.setValue(0);
}
};
render() {
return (
<View style={styles.view}>
<Text style={{ textAlign: 'center', width: '80%' }}>
{' '}
Force touch works only on some Apple devices (iPhones 6s+ excluding
XR) and should be used only as a supportive one{' '}
</Text>
<ForceTouchGestureHandler
feedbackOnActivation
onGestureEvent={this.onGestureEvent}
onHandlerStateChange={this.onHandlerStateChange}>
<Animated.View
style={[
styles.box,
{ transform: [{ scale: Animated.add(1, this.force) }] },
]}
/>
</ForceTouchGestureHandler>
</View>
);
}
}
const styles = StyleSheet.create({
view: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
box: {
width: 150,
height: 150,
backgroundColor: 'mediumspringgreen',
margin: 10,
zIndex: 200,
},
});