-
Notifications
You must be signed in to change notification settings - Fork 515
/
Copy pathInteractableView.js
117 lines (103 loc) · 3.12 KB
/
InteractableView.js
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import React, { Component } from 'react';
import ReactNative, { requireNativeComponent, Animated, NativeModules, UIManager, Platform } from 'react-native';
// this is required in order to perform imperative commands
const NativeViewManager = NativeModules.InteractableViewManager;
const NativeInteractableView = requireNativeComponent('InteractableView', null);
class WrappedInteractableView extends Component {
render() {
return (
<NativeInteractableView
{...this.props}
ref={(ref) => this._nativeViewRef = ref}
/>
);
}
getScrollableNode() {
return ReactNative.findNodeHandle(this._nativeViewRef);
}
}
// this is required in order to support native events:
const AnimatedInteractableView = Animated.createAnimatedComponent(WrappedInteractableView);
class WrappedAnimatedInteractableView extends Component {
constructor(props) {
super(props);
if (this.props.animatedValueX || this.props.animatedValueY) {
this._animatedEvent = Animated.event(
[{
nativeEvent: {
x: this.props.animatedValueX,
y: this.props.animatedValueY
}
}],
{ useNativeDriver: !!this.props.animatedNativeDriver }
);
}
}
componentWillMount() {
// this.chokeTheBridge();
}
// this helps us verify that useNativeDriver actually works and we don't rely on the bridge
chokeTheBridge() {
let j = 0;
setInterval(() => {
for (var index = 0; index < 1e9; index++) {
j++;
}
}, 500);
}
render() {
return (
<AnimatedInteractableView
dragToss={0.1}
{...this.props}
animatedValueX={undefined}
animatedValueY={undefined}
onAnimatedEvent={this._animatedEvent}
reportOnAnimatedEvents={!!this._animatedEvent}
/>
);
}
setVelocity(params) {
if (Platform.OS === 'ios') {
NativeViewManager.setVelocity(ReactNative.findNodeHandle(this), params);
} else if (Platform.OS === 'android') {
UIManager.dispatchViewManagerCommand(
ReactNative.findNodeHandle(this),
UIManager.InteractableView.Commands.setVelocity,
[params],
);
}
}
snapTo(params) {
if (Platform.OS === 'ios') {
NativeViewManager.snapTo(ReactNative.findNodeHandle(this), params);
} else if (Platform.OS === 'android') {
UIManager.dispatchViewManagerCommand(
ReactNative.findNodeHandle(this),
UIManager.InteractableView.Commands.snapTo,
[params],
);
}
}
changePosition(params) {
if (Platform.OS === 'ios') {
NativeViewManager.changePosition(ReactNative.findNodeHandle(this), params);
} else if (Platform.OS === 'android') {
UIManager.dispatchViewManagerCommand(
ReactNative.findNodeHandle(this),
UIManager.InteractableView.Commands.changePosition,
[params],
);
}
}
bringToFront() {
if (Platform.OS === 'android') {
UIManager.dispatchViewManagerCommand(
ReactNative.findNodeHandle(this),
UIManager.InteractableView.Commands.bringToFront,
[],
);
}
}
}
export default WrappedAnimatedInteractableView;