Commit a724f16
authored
Add
## Description
This PR adds `runOnJS` to gesture config.
## Test plan
<details>
<summary>Tested on the following example:</summary>
```tsx
import * as React from 'react';
import { Animated, Button, StyleSheet, View, Text } from 'react-native';
import {
GestureHandlerRootView,
NativeDetector,
usePan,
useSimultaneous,
} from 'react-native-gesture-handler';
import { useSharedValue } from 'react-native-reanimated';
const runtimeKind = (_worklet: boolean) => {
'worklet';
return _worklet ? 'worklet' : 'JS';
};
function SingleExampleWithState() {
const [js, setJs] = React.useState(false);
const gesture = usePan({
onUpdate: () => {
'worklet';
console.log(
`[SingleExampleWithState] I run on a ${runtimeKind(globalThis._WORKLET)} runtime!`
);
},
runOnJS: js,
});
return (
<View style={[styles.container, styles.center]}>
<Button
title="Change runtime"
onPress={() => {
setJs((v) => !v);
}}
/>
<NativeDetector gesture={gesture}>
<Animated.View style={[styles.box]} />
</NativeDetector>
</View>
);
}
function SingleExampleWithSharedValue() {
const js = useSharedValue(false);
const gesture = usePan({
onUpdate: () => {
'worklet';
console.log(
`[SingleExampleWithSharedValue] I run on a ${runtimeKind(globalThis._WORKLET)} runtime!`
);
},
runOnJS: js,
});
return (
<View style={[styles.container, styles.center]}>
<Button
title="Change runtime"
onPress={() => {
js.value = !js.value;
}}
/>
<NativeDetector gesture={gesture}>
<Animated.View style={[styles.box]} />
</NativeDetector>
</View>
);
}
function ComposedExample() {
const [pan1JS, setPan1JS] = React.useState(false);
const pan2JS = useSharedValue(false);
const pan1 = usePan({
onUpdate: () => {
'worklet';
console.log(
`[ComposedExample | Pan1] I run on a ${runtimeKind(globalThis._WORKLET)} runtime!`
);
},
runOnJS: pan1JS,
});
const pan2 = usePan({
onUpdate: () => {
'worklet';
console.log(
`[ComposedExample | Pan2] I run on a ${runtimeKind(globalThis._WORKLET)} runtime!`
);
},
runOnJS: pan2JS,
});
const gesture = useSimultaneous(pan1, pan2);
return (
<View style={[styles.container, styles.center]}>
<View style={[styles.center, { flexDirection: 'row', gap: 10 }]}>
<Button
title="Change Pan1 runtime"
onPress={() => {
setPan1JS((v) => !v);
}}
/>
<Button
title="Change Pan2 runtime"
onPress={() => {
pan2JS.value = !pan2JS.value;
}}
/>
</View>
<NativeDetector gesture={gesture}>
<Animated.View style={[styles.box]} />
</NativeDetector>
</View>
);
}
export default function App() {
return (
<GestureHandlerRootView style={[{ flex: 1 }, styles.center]}>
<SingleExampleWithState />
<SingleExampleWithSharedValue />
<ComposedExample />
</GestureHandlerRootView>
);
}
const styles = StyleSheet.create({
container: { gap: 10 },
center: {
display: 'flex',
justifyContent: 'space-around',
alignItems: 'center',
},
box: {
width: 150,
height: 150,
borderRadius: 20,
backgroundColor: 'pink',
},
});
```
</details>runOnJS to config (#3743)1 parent 07edd7a commit a724f16
File tree
10 files changed
+139
-104
lines changed- packages/react-native-gesture-handler
- android/src/main/java/com/swmansion/gesturehandler/core
- apple
- src/v3
- NativeDetector
- hooks
- relations
- utils
10 files changed
+139
-104
lines changedLines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
902 | 902 | | |
903 | 903 | | |
904 | 904 | | |
905 | | - | |
906 | | - | |
| 905 | + | |
| 906 | + | |
907 | 907 | | |
908 | 908 | | |
909 | 909 | | |
| |||
920 | 920 | | |
921 | 921 | | |
922 | 922 | | |
923 | | - | |
| 923 | + | |
924 | 924 | | |
925 | 925 | | |
926 | 926 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
| 150 | + | |
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
Lines changed: 5 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | | - | |
31 | | - | |
32 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | | - | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
Lines changed: 6 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | | - | |
9 | | - | |
10 | 7 | | |
11 | 8 | | |
12 | | - | |
13 | 9 | | |
| 10 | + | |
14 | 11 | | |
15 | 12 | | |
16 | 13 | | |
| |||
30 | 27 | | |
31 | 28 | | |
32 | 29 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 30 | + | |
| 31 | + | |
40 | 32 | | |
41 | | - | |
| 33 | + | |
42 | 34 | | |
43 | 35 | | |
44 | 36 | | |
| |||
69 | 61 | | |
70 | 62 | | |
71 | 63 | | |
72 | | - | |
| 64 | + | |
73 | 65 | | |
74 | 66 | | |
75 | 67 | | |
| |||
92 | 84 | | |
93 | 85 | | |
94 | 86 | | |
95 | | - | |
| 87 | + | |
96 | 88 | | |
97 | 89 | | |
98 | 90 | | |
| |||
Lines changed: 23 additions & 72 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | 6 | | |
11 | 7 | | |
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 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
80 | 16 | | |
81 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
82 | 33 | | |
83 | 34 | | |
84 | 35 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
Lines changed: 76 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
41 | 50 | | |
42 | 51 | | |
43 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
125 | 130 | | |
126 | 131 | | |
127 | 132 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
| 133 | + | |
132 | 134 | | |
133 | 135 | | |
134 | 136 | | |
| |||
176 | 178 | | |
177 | 179 | | |
178 | 180 | | |
179 | | - | |
| 181 | + | |
| 182 | + | |
180 | 183 | | |
181 | 184 | | |
182 | 185 | | |
183 | 186 | | |
184 | 187 | | |
185 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
186 | 191 | | |
187 | | - | |
| 192 | + | |
188 | 193 | | |
189 | 194 | | |
190 | 195 | | |
| |||
0 commit comments