Commit ee6107f
authored
[Web] Separate Reanimated from JS (#3683)
## Description
Web portion of functionality from PR #3682
> Currently we have 2 ways of handling events - Animated and
JS/Reanimated. Handling both JS and Reanimated in the same places
results in more complex codebase. It also introduces problems with
composing gestures. We decided to spit those implementations.
## Test plan
```tsx
import * as React from 'react';
import { Animated, Button } from 'react-native';
import {
GestureHandlerRootView,
NativeDetector,
useGesture,
} from 'react-native-gesture-handler';
export default function App() {
const [visible, setVisible] = React.useState(true);
const av = React.useRef(new Animated.Value(0)).current
const event = Animated.event(
[{ handlerData: { translationX: av } }],
{
useNativeDriver: false,
}
);
const gesture = useGesture('PanGestureHandler', {
onBegin: (e: unknown) => {
'worklet';
console.log('onBegin', e);
},
onStart: (e: unknown) => {
'worklet';
console.log('onStart', e);
},
// onUpdate: event,
onUpdate: (e: unknown) => {
'worklet';
console.log('onUpdate', e);
},
onEnd: (e: unknown) => {
'worklet';
console.log('onEnd', e);
},
onFinalize: (e: unknown) => {
'worklet';
console.log('onFinalize', e);
},
onTouchesDown: (e: unknown) => {
'worklet';
console.log('onTouchesDown', e);
},
onTouchesMove: (e: unknown) => {
'worklet';
console.log('onTouchesMoved', e);
},
onTouchesUp: (e: unknown) => {
'worklet';
console.log('onTouchesUp', e);
},
onTouchesCancelled: (e: unknown) => {
'worklet';
console.log('onTouchesCancelled', e);
},
});
return (
<GestureHandlerRootView
style={{ flex: 1, backgroundColor: 'white', paddingTop: 8 }}>
<Button
title="Toggle visibility"
onPress={() => {
setVisible(!visible);
}}
/>
{visible && (
<NativeDetector gesture={gesture}>
<Animated.View
style={[
{
width: 150,
height: 150,
backgroundColor: 'blue',
opacity: 0.5,
borderWidth: 10,
borderColor: 'green',
marginTop: 20,
marginLeft: 40,
},
{ transform: [{ translateX: av }] },
]}
/>
</NativeDetector>
)}
</GestureHandlerRootView>
);
}
```1 parent abccee8 commit ee6107f
File tree
3 files changed
+73
-25
lines changed- packages/react-native-gesture-handler/src
- handlers/gestures/GestureDetector
- web
- handlers
3 files changed
+73
-25
lines changedLines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
178 | 181 | | |
179 | 182 | | |
Lines changed: 64 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
99 | | - | |
| 100 | + | |
| 101 | + | |
100 | 102 | | |
101 | 103 | | |
102 | 104 | | |
| |||
380 | 382 | | |
381 | 383 | | |
382 | 384 | | |
383 | | - | |
384 | | - | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
385 | 390 | | |
386 | 391 | | |
387 | 392 | | |
388 | 393 | | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
398 | 407 | | |
399 | 408 | | |
400 | 409 | | |
| |||
407 | 416 | | |
408 | 417 | | |
409 | 418 | | |
| 419 | + | |
| 420 | + | |
410 | 421 | | |
411 | 422 | | |
412 | 423 | | |
| |||
422 | 433 | | |
423 | 434 | | |
424 | 435 | | |
425 | | - | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
426 | 442 | | |
427 | 443 | | |
428 | 444 | | |
429 | 445 | | |
430 | 446 | | |
431 | 447 | | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
436 | 457 | | |
437 | 458 | | |
438 | 459 | | |
| |||
637 | 658 | | |
638 | 659 | | |
639 | 660 | | |
640 | | - | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
641 | 666 | | |
642 | | - | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
643 | 677 | | |
644 | 678 | | |
645 | 679 | | |
| |||
691 | 725 | | |
692 | 726 | | |
693 | 727 | | |
694 | | - | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
695 | 733 | | |
696 | 734 | | |
697 | 735 | | |
| |||
874 | 912 | | |
875 | 913 | | |
876 | 914 | | |
877 | | - | |
| 915 | + | |
| 916 | + | |
878 | 917 | | |
879 | 918 | | |
880 | 919 | | |
| |||
991 | 1030 | | |
992 | 1031 | | |
993 | 1032 | | |
994 | | - | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
995 | 1036 | | |
996 | 1037 | | |
997 | 1038 | | |
| |||
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
127 | | - | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
130 | 134 | | |
131 | 135 | | |
132 | 136 | | |
| |||
0 commit comments