react-native-gesture-handler 2.16.2 → 2.17.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +9 -3
- package/android/build.gradle +103 -0
- package/android/gradle.properties +7 -0
- package/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.java +7 -7
- package/android/src/main/java/com/swmansion/gesturehandler/core/NativeViewGestureHandler.kt +16 -8
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +9 -5
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerInteractionManager.kt +4 -0
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt +1 -1
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerTouchEvent.kt +1 -0
- package/apple/RNGestureHandlerButtonComponentView.mm +10 -0
- package/apple/RNGestureHandlerModule.mm +2 -3
- package/lib/commonjs/components/GestureButtons.js +27 -12
- package/lib/commonjs/components/GestureButtons.js.map +1 -1
- package/lib/commonjs/handlers/createHandler.js +1 -3
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/handlers/gestureHandlerCommon.js +3 -3
- package/lib/commonjs/handlers/gestureHandlerCommon.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/Wrap.js +42 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/Wrap.js.map +1 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/attachHandlers.js +83 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/attachHandlers.js.map +1 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/dropHandlers.js +25 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/dropHandlers.js.map +1 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/index.js +143 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/index.js.map +1 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/needsToReattach.js +25 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/needsToReattach.js.map +1 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/types.js +6 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/types.js.map +1 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/updateHandlers.js +80 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/updateHandlers.js.map +1 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/useAnimatedGesture.js +180 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/useAnimatedGesture.js.map +1 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/useDetectorUpdater.js +55 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/useDetectorUpdater.js.map +1 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/useViewRefHandler.js +47 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/useViewRefHandler.js.map +1 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/utils.js +176 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/utils.js.map +1 -0
- package/lib/commonjs/handlers/gestures/gestureComposition.js +3 -1
- package/lib/commonjs/handlers/gestures/gestureComposition.js.map +1 -1
- package/lib/commonjs/handlers/gestures/gestureStateManager.js +8 -0
- package/lib/commonjs/handlers/gestures/gestureStateManager.js.map +1 -1
- package/lib/commonjs/handlers/gestures/reanimatedWrapper.js.map +1 -1
- package/lib/commonjs/utils.js +36 -0
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/detectors/RotationGestureDetector.js +6 -8
- package/lib/commonjs/web/detectors/RotationGestureDetector.js.map +1 -1
- package/lib/commonjs/web/detectors/ScaleGestureDetector.js +5 -6
- package/lib/commonjs/web/detectors/ScaleGestureDetector.js.map +1 -1
- package/lib/commonjs/web/handlers/FlingGestureHandler.js +1 -0
- package/lib/commonjs/web/handlers/FlingGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/GestureHandler.js +56 -64
- package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/LongPressGestureHandler.js +1 -0
- package/lib/commonjs/web/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/ManualGestureHandler.js +1 -0
- package/lib/commonjs/web/handlers/ManualGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/NativeViewGestureHandler.js +7 -4
- package/lib/commonjs/web/handlers/NativeViewGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/PanGestureHandler.js +28 -18
- package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/PinchGestureHandler.js +1 -0
- package/lib/commonjs/web/handlers/PinchGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/RotationGestureHandler.js +1 -0
- package/lib/commonjs/web/handlers/RotationGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/TapGestureHandler.js +18 -12
- package/lib/commonjs/web/handlers/TapGestureHandler.js.map +1 -1
- package/lib/commonjs/web/interfaces.js.map +1 -1
- package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js +1 -6
- package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js.map +1 -1
- package/lib/commonjs/web/tools/PointerEventManager.js +7 -2
- package/lib/commonjs/web/tools/PointerEventManager.js.map +1 -1
- package/lib/commonjs/web/tools/PointerTracker.js +89 -57
- package/lib/commonjs/web/tools/PointerTracker.js.map +1 -1
- package/lib/commonjs/web/tools/TouchEventManager.js +6 -2
- package/lib/commonjs/web/tools/TouchEventManager.js.map +1 -1
- package/lib/commonjs/web/tools/Vector.js +2 -1
- package/lib/commonjs/web/tools/Vector.js.map +1 -1
- package/lib/commonjs/web/utils.js +31 -0
- package/lib/commonjs/web/utils.js.map +1 -1
- package/lib/module/components/GestureButtons.js +24 -6
- package/lib/module/components/GestureButtons.js.map +1 -1
- package/lib/module/handlers/createHandler.js +2 -4
- package/lib/module/handlers/createHandler.js.map +1 -1
- package/lib/module/handlers/gestureHandlerCommon.js +1 -1
- package/lib/module/handlers/gestureHandlerCommon.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/Wrap.js +26 -0
- package/lib/module/handlers/gestures/GestureDetector/Wrap.js.map +1 -0
- package/lib/module/handlers/gestures/GestureDetector/attachHandlers.js +65 -0
- package/lib/module/handlers/gestures/GestureDetector/attachHandlers.js.map +1 -0
- package/lib/module/handlers/gestures/GestureDetector/dropHandlers.js +12 -0
- package/lib/module/handlers/gestures/GestureDetector/dropHandlers.js.map +1 -0
- package/lib/module/handlers/gestures/GestureDetector/index.js +115 -0
- package/lib/module/handlers/gestures/GestureDetector/index.js.map +1 -0
- package/lib/module/handlers/gestures/GestureDetector/needsToReattach.js +18 -0
- package/lib/module/handlers/gestures/GestureDetector/needsToReattach.js.map +1 -0
- package/lib/module/handlers/gestures/GestureDetector/types.js +2 -0
- package/lib/module/handlers/gestures/GestureDetector/types.js.map +1 -0
- package/lib/module/handlers/gestures/GestureDetector/updateHandlers.js +64 -0
- package/lib/module/handlers/gestures/GestureDetector/updateHandlers.js.map +1 -0
- package/lib/module/handlers/gestures/GestureDetector/useAnimatedGesture.js +165 -0
- package/lib/module/handlers/gestures/GestureDetector/useAnimatedGesture.js.map +1 -0
- package/lib/module/handlers/gestures/GestureDetector/useDetectorUpdater.js +41 -0
- package/lib/module/handlers/gestures/GestureDetector/useDetectorUpdater.js.map +1 -0
- package/lib/module/handlers/gestures/GestureDetector/useViewRefHandler.js +36 -0
- package/lib/module/handlers/gestures/GestureDetector/useViewRefHandler.js.map +1 -0
- package/lib/module/handlers/gestures/GestureDetector/utils.js +142 -0
- package/lib/module/handlers/gestures/GestureDetector/utils.js.map +1 -0
- package/lib/module/handlers/gestures/gestureComposition.js +3 -1
- package/lib/module/handlers/gestures/gestureComposition.js.map +1 -1
- package/lib/module/handlers/gestures/gestureStateManager.js +8 -0
- package/lib/module/handlers/gestures/gestureStateManager.js.map +1 -1
- package/lib/module/handlers/gestures/reanimatedWrapper.js.map +1 -1
- package/lib/module/utils.js +34 -0
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/detectors/RotationGestureDetector.js +6 -8
- package/lib/module/web/detectors/RotationGestureDetector.js.map +1 -1
- package/lib/module/web/detectors/ScaleGestureDetector.js +5 -6
- package/lib/module/web/detectors/ScaleGestureDetector.js.map +1 -1
- package/lib/module/web/handlers/FlingGestureHandler.js +1 -0
- package/lib/module/web/handlers/FlingGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/GestureHandler.js +56 -64
- package/lib/module/web/handlers/GestureHandler.js.map +1 -1
- package/lib/module/web/handlers/LongPressGestureHandler.js +1 -0
- package/lib/module/web/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/ManualGestureHandler.js +1 -0
- package/lib/module/web/handlers/ManualGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/NativeViewGestureHandler.js +7 -4
- package/lib/module/web/handlers/NativeViewGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/PanGestureHandler.js +28 -18
- package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/PinchGestureHandler.js +1 -0
- package/lib/module/web/handlers/PinchGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/RotationGestureHandler.js +1 -0
- package/lib/module/web/handlers/RotationGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/TapGestureHandler.js +18 -12
- package/lib/module/web/handlers/TapGestureHandler.js.map +1 -1
- package/lib/module/web/interfaces.js.map +1 -1
- package/lib/module/web/tools/GestureHandlerOrchestrator.js +1 -6
- package/lib/module/web/tools/GestureHandlerOrchestrator.js.map +1 -1
- package/lib/module/web/tools/PointerEventManager.js +8 -3
- package/lib/module/web/tools/PointerEventManager.js.map +1 -1
- package/lib/module/web/tools/PointerTracker.js +89 -57
- package/lib/module/web/tools/PointerTracker.js.map +1 -1
- package/lib/module/web/tools/TouchEventManager.js +7 -3
- package/lib/module/web/tools/TouchEventManager.js.map +1 -1
- package/lib/module/web/tools/Vector.js +2 -1
- package/lib/module/web/tools/Vector.js.map +1 -1
- package/lib/module/web/utils.js +29 -0
- package/lib/module/web/utils.js.map +1 -1
- package/lib/typescript/components/GestureButtons.d.ts +3 -34
- package/lib/typescript/handlers/gestureHandlerCommon.d.ts +3 -2
- package/lib/typescript/handlers/gestures/GestureDetector/Wrap.d.ts +13 -0
- package/lib/typescript/handlers/gestures/GestureDetector/attachHandlers.d.ts +13 -0
- package/lib/typescript/handlers/gestures/GestureDetector/dropHandlers.d.ts +2 -0
- package/lib/typescript/handlers/gestures/{GestureDetector.d.ts → GestureDetector/index.d.ts} +4 -12
- package/lib/typescript/handlers/gestures/GestureDetector/needsToReattach.d.ts +3 -0
- package/lib/typescript/handlers/gestures/GestureDetector/types.d.ts +20 -0
- package/lib/typescript/handlers/gestures/GestureDetector/updateHandlers.d.ts +4 -0
- package/lib/typescript/handlers/gestures/GestureDetector/useAnimatedGesture.d.ts +2 -0
- package/lib/typescript/handlers/gestures/GestureDetector/useDetectorUpdater.d.ts +5 -0
- package/lib/typescript/handlers/gestures/GestureDetector/useViewRefHandler.d.ts +3 -0
- package/lib/typescript/handlers/gestures/GestureDetector/utils.d.ts +12 -0
- package/lib/typescript/handlers/gestures/reanimatedWrapper.d.ts +1 -1
- package/lib/typescript/utils.d.ts +10 -0
- package/lib/typescript/web/handlers/GestureHandler.d.ts +1 -0
- package/lib/typescript/web/interfaces.d.ts +1 -0
- package/lib/typescript/web/tools/PointerTracker.d.ts +34 -31
- package/lib/typescript/web/utils.d.ts +4 -0
- package/package.json +5 -5
- package/src/components/GestureButtons.tsx +36 -4
- package/src/handlers/createHandler.tsx +1 -3
- package/src/handlers/gestureHandlerCommon.ts +4 -1
- package/src/handlers/gestures/GestureDetector/Wrap.tsx +35 -0
- package/src/handlers/gestures/GestureDetector/attachHandlers.ts +112 -0
- package/src/handlers/gestures/GestureDetector/dropHandlers.ts +14 -0
- package/src/handlers/gestures/GestureDetector/index.tsx +187 -0
- package/src/handlers/gestures/GestureDetector/needsToReattach.ts +27 -0
- package/src/handlers/gestures/GestureDetector/types.ts +32 -0
- package/src/handlers/gestures/GestureDetector/updateHandlers.ts +94 -0
- package/src/handlers/gestures/GestureDetector/useAnimatedGesture.ts +206 -0
- package/src/handlers/gestures/GestureDetector/useDetectorUpdater.ts +69 -0
- package/src/handlers/gestures/GestureDetector/useViewRefHandler.ts +54 -0
- package/src/handlers/gestures/GestureDetector/utils.ts +185 -0
- package/src/handlers/gestures/gestureComposition.ts +2 -0
- package/src/handlers/gestures/gestureStateManager.ts +12 -4
- package/src/handlers/gestures/reanimatedWrapper.ts +19 -17
- package/src/utils.ts +39 -0
- package/src/web/detectors/RotationGestureDetector.ts +6 -8
- package/src/web/detectors/ScaleGestureDetector.ts +5 -6
- package/src/web/handlers/FlingGestureHandler.ts +2 -0
- package/src/web/handlers/GestureHandler.ts +53 -62
- package/src/web/handlers/LongPressGestureHandler.ts +2 -0
- package/src/web/handlers/ManualGestureHandler.ts +2 -0
- package/src/web/handlers/NativeViewGestureHandler.ts +8 -4
- package/src/web/handlers/PanGestureHandler.ts +32 -19
- package/src/web/handlers/PinchGestureHandler.ts +2 -0
- package/src/web/handlers/RotationGestureHandler.ts +2 -0
- package/src/web/handlers/TapGestureHandler.ts +20 -12
- package/src/web/interfaces.ts +1 -0
- package/src/web/tools/GestureHandlerOrchestrator.ts +1 -7
- package/src/web/tools/PointerEventManager.ts +10 -3
- package/src/web/tools/PointerTracker.ts +81 -74
- package/src/web/tools/TouchEventManager.ts +5 -3
- package/src/web/tools/Vector.ts +2 -4
- package/src/web/utils.ts +34 -0
- package/lib/commonjs/handlers/gestures/GestureDetector.js +0 -704
- package/lib/commonjs/handlers/gestures/GestureDetector.js.map +0 -1
- package/lib/module/handlers/gestures/GestureDetector.js +0 -654
- package/lib/module/handlers/gestures/GestureDetector.js.map +0 -1
- package/src/handlers/gestures/GestureDetector.tsx +0 -889
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.updateHandlers = updateHandlers;
|
7
|
+
|
8
|
+
var _handlersRegistry = require("../../handlersRegistry");
|
9
|
+
|
10
|
+
var _RNGestureHandlerModule = _interopRequireDefault(require("../../../RNGestureHandlerModule"));
|
11
|
+
|
12
|
+
var _gestureHandlerCommon = require("../../gestureHandlerCommon");
|
13
|
+
|
14
|
+
var _ghQueueMicrotask = require("../../../ghQueueMicrotask");
|
15
|
+
|
16
|
+
var _utils = require("./utils");
|
17
|
+
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
|
+
|
20
|
+
function updateHandlers(preparedGesture, gestureConfig, newGestures) {
|
21
|
+
gestureConfig.prepare();
|
22
|
+
|
23
|
+
for (let i = 0; i < newGestures.length; i++) {
|
24
|
+
const handler = preparedGesture.attachedGestures[i];
|
25
|
+
(0, _utils.checkGestureCallbacksForWorklets)(handler); // only update handlerTag when it's actually different, it may be the same
|
26
|
+
// if gesture config object is wrapped with useMemo
|
27
|
+
|
28
|
+
if (newGestures[i].handlerTag !== handler.handlerTag) {
|
29
|
+
newGestures[i].handlerTag = handler.handlerTag;
|
30
|
+
newGestures[i].handlers.handlerTag = handler.handlerTag;
|
31
|
+
}
|
32
|
+
} // use queueMicrotask to extract handlerTags, because when it's ran, all refs should be updated
|
33
|
+
// and handlerTags in BaseGesture references should be updated in the loop above (we need to wait
|
34
|
+
// in case of external relations)
|
35
|
+
|
36
|
+
|
37
|
+
(0, _ghQueueMicrotask.ghQueueMicrotask)(() => {
|
38
|
+
if (!preparedGesture.isMounted) {
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
|
42
|
+
for (let i = 0; i < newGestures.length; i++) {
|
43
|
+
const handler = preparedGesture.attachedGestures[i];
|
44
|
+
handler.config = newGestures[i].config;
|
45
|
+
handler.handlers = newGestures[i].handlers;
|
46
|
+
|
47
|
+
_RNGestureHandlerModule.default.updateGestureHandler(handler.handlerTag, (0, _gestureHandlerCommon.filterConfig)(handler.config, _utils.ALLOWED_PROPS, (0, _utils.extractGestureRelations)(handler)));
|
48
|
+
|
49
|
+
(0, _handlersRegistry.registerHandler)(handler.handlerTag, handler, handler.config.testId);
|
50
|
+
}
|
51
|
+
|
52
|
+
if (preparedGesture.animatedHandlers) {
|
53
|
+
var _preparedGesture$anim;
|
54
|
+
|
55
|
+
const previousHandlersValue = (_preparedGesture$anim = preparedGesture.animatedHandlers.value) !== null && _preparedGesture$anim !== void 0 ? _preparedGesture$anim : [];
|
56
|
+
const newHandlersValue = preparedGesture.attachedGestures.filter(g => g.shouldUseReanimated) // ignore gestures that shouldn't run on UI
|
57
|
+
.map(g => g.handlers); // if amount of gesture configs changes, we need to update the callbacks in shared value
|
58
|
+
|
59
|
+
let shouldUpdateSharedValue = previousHandlersValue.length !== newHandlersValue.length;
|
60
|
+
|
61
|
+
if (!shouldUpdateSharedValue) {
|
62
|
+
// if the amount is the same, we need to check if any of the configs inside has changed
|
63
|
+
for (let i = 0; i < newHandlersValue.length; i++) {
|
64
|
+
if ( // we can use the `gestureId` prop as it's unique for every config instance
|
65
|
+
newHandlersValue[i].gestureId !== previousHandlersValue[i].gestureId) {
|
66
|
+
shouldUpdateSharedValue = true;
|
67
|
+
break;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
if (shouldUpdateSharedValue) {
|
73
|
+
preparedGesture.animatedHandlers.value = newHandlersValue;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
(0, _gestureHandlerCommon.scheduleFlushOperations)();
|
78
|
+
});
|
79
|
+
}
|
80
|
+
//# sourceMappingURL=updateHandlers.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["updateHandlers.ts"],"names":["updateHandlers","preparedGesture","gestureConfig","newGestures","prepare","i","length","handler","attachedGestures","handlerTag","handlers","isMounted","config","RNGestureHandlerModule","updateGestureHandler","ALLOWED_PROPS","testId","animatedHandlers","previousHandlersValue","value","newHandlersValue","filter","g","shouldUseReanimated","map","shouldUpdateSharedValue","gestureId"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AAKA;;AAEA;;;;AAMO,SAASA,cAAT,CACLC,eADK,EAELC,aAFK,EAGLC,WAHK,EAIL;AACAD,EAAAA,aAAa,CAACE,OAAd;;AAEA,OAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,WAAW,CAACG,MAAhC,EAAwCD,CAAC,EAAzC,EAA6C;AAC3C,UAAME,OAAO,GAAGN,eAAe,CAACO,gBAAhB,CAAiCH,CAAjC,CAAhB;AACA,iDAAiCE,OAAjC,EAF2C,CAI3C;AACA;;AACA,QAAIJ,WAAW,CAACE,CAAD,CAAX,CAAeI,UAAf,KAA8BF,OAAO,CAACE,UAA1C,EAAsD;AACpDN,MAAAA,WAAW,CAACE,CAAD,CAAX,CAAeI,UAAf,GAA4BF,OAAO,CAACE,UAApC;AACAN,MAAAA,WAAW,CAACE,CAAD,CAAX,CAAeK,QAAf,CAAwBD,UAAxB,GAAqCF,OAAO,CAACE,UAA7C;AACD;AACF,GAbD,CAeA;AACA;AACA;;;AACA,0CAAiB,MAAM;AACrB,QAAI,CAACR,eAAe,CAACU,SAArB,EAAgC;AAC9B;AACD;;AACD,SAAK,IAAIN,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,WAAW,CAACG,MAAhC,EAAwCD,CAAC,EAAzC,EAA6C;AAC3C,YAAME,OAAO,GAAGN,eAAe,CAACO,gBAAhB,CAAiCH,CAAjC,CAAhB;AAEAE,MAAAA,OAAO,CAACK,MAAR,GAAiBT,WAAW,CAACE,CAAD,CAAX,CAAeO,MAAhC;AACAL,MAAAA,OAAO,CAACG,QAAR,GAAmBP,WAAW,CAACE,CAAD,CAAX,CAAeK,QAAlC;;AAEAG,sCAAuBC,oBAAvB,CACEP,OAAO,CAACE,UADV,EAEE,wCACEF,OAAO,CAACK,MADV,EAEEG,oBAFF,EAGE,oCAAwBR,OAAxB,CAHF,CAFF;;AASA,6CAAgBA,OAAO,CAACE,UAAxB,EAAoCF,OAApC,EAA6CA,OAAO,CAACK,MAAR,CAAeI,MAA5D;AACD;;AAED,QAAIf,eAAe,CAACgB,gBAApB,EAAsC;AAAA;;AACpC,YAAMC,qBAAqB,4BACzBjB,eAAe,CAACgB,gBAAhB,CAAiCE,KADR,yEACiB,EAD5C;AAEA,YAAMC,gBAAgB,GAAGnB,eAAe,CAACO,gBAAhB,CACtBa,MADsB,CACdC,CAAD,IAAOA,CAAC,CAACC,mBADM,EACe;AADf,OAEtBC,GAFsB,CAEjBF,CAAD,IAAOA,CAAC,CAACZ,QAFS,CAAzB,CAHoC,CASpC;;AACA,UAAIe,uBAAuB,GACzBP,qBAAqB,CAACZ,MAAtB,KAAiCc,gBAAgB,CAACd,MADpD;;AAGA,UAAI,CAACmB,uBAAL,EAA8B;AAC5B;AACA,aAAK,IAAIpB,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGe,gBAAgB,CAACd,MAArC,EAA6CD,CAAC,EAA9C,EAAkD;AAChD,eACE;AACAe,UAAAA,gBAAgB,CAACf,CAAD,CAAhB,CAAoBqB,SAApB,KAAkCR,qBAAqB,CAACb,CAAD,CAArB,CAAyBqB,SAF7D,EAGE;AACAD,YAAAA,uBAAuB,GAAG,IAA1B;AACA;AACD;AACF;AACF;;AAED,UAAIA,uBAAJ,EAA6B;AAC3BxB,QAAAA,eAAe,CAACgB,gBAAhB,CAAiCE,KAAjC,GAAyCC,gBAAzC;AACD;AACF;;AAED;AACD,GAtDD;AAuDD","sourcesContent":["import { GestureType, HandlerCallbacks } from '../gesture';\nimport { registerHandler } from '../../handlersRegistry';\nimport RNGestureHandlerModule from '../../../RNGestureHandlerModule';\nimport {\n filterConfig,\n scheduleFlushOperations,\n} from '../../gestureHandlerCommon';\nimport { ComposedGesture } from '../gestureComposition';\nimport { ghQueueMicrotask } from '../../../ghQueueMicrotask';\nimport { AttachedGestureState } from './types';\nimport {\n extractGestureRelations,\n checkGestureCallbacksForWorklets,\n ALLOWED_PROPS,\n} from './utils';\n\nexport function updateHandlers(\n preparedGesture: AttachedGestureState,\n gestureConfig: ComposedGesture | GestureType,\n newGestures: GestureType[]\n) {\n gestureConfig.prepare();\n\n for (let i = 0; i < newGestures.length; i++) {\n const handler = preparedGesture.attachedGestures[i];\n checkGestureCallbacksForWorklets(handler);\n\n // only update handlerTag when it's actually different, it may be the same\n // if gesture config object is wrapped with useMemo\n if (newGestures[i].handlerTag !== handler.handlerTag) {\n newGestures[i].handlerTag = handler.handlerTag;\n newGestures[i].handlers.handlerTag = handler.handlerTag;\n }\n }\n\n // use queueMicrotask to extract handlerTags, because when it's ran, all refs should be updated\n // and handlerTags in BaseGesture references should be updated in the loop above (we need to wait\n // in case of external relations)\n ghQueueMicrotask(() => {\n if (!preparedGesture.isMounted) {\n return;\n }\n for (let i = 0; i < newGestures.length; i++) {\n const handler = preparedGesture.attachedGestures[i];\n\n handler.config = newGestures[i].config;\n handler.handlers = newGestures[i].handlers;\n\n RNGestureHandlerModule.updateGestureHandler(\n handler.handlerTag,\n filterConfig(\n handler.config,\n ALLOWED_PROPS,\n extractGestureRelations(handler)\n )\n );\n\n registerHandler(handler.handlerTag, handler, handler.config.testId);\n }\n\n if (preparedGesture.animatedHandlers) {\n const previousHandlersValue =\n preparedGesture.animatedHandlers.value ?? [];\n const newHandlersValue = preparedGesture.attachedGestures\n .filter((g) => g.shouldUseReanimated) // ignore gestures that shouldn't run on UI\n .map((g) => g.handlers) as unknown as HandlerCallbacks<\n Record<string, unknown>\n >[];\n\n // if amount of gesture configs changes, we need to update the callbacks in shared value\n let shouldUpdateSharedValue =\n previousHandlersValue.length !== newHandlersValue.length;\n\n if (!shouldUpdateSharedValue) {\n // if the amount is the same, we need to check if any of the configs inside has changed\n for (let i = 0; i < newHandlersValue.length; i++) {\n if (\n // we can use the `gestureId` prop as it's unique for every config instance\n newHandlersValue[i].gestureId !== previousHandlersValue[i].gestureId\n ) {\n shouldUpdateSharedValue = true;\n break;\n }\n }\n }\n\n if (shouldUpdateSharedValue) {\n preparedGesture.animatedHandlers.value = newHandlersValue;\n }\n }\n\n scheduleFlushOperations();\n });\n}\n"]}
|
@@ -0,0 +1,180 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useAnimatedGesture = useAnimatedGesture;
|
7
|
+
|
8
|
+
var _gesture = require("../gesture");
|
9
|
+
|
10
|
+
var _reanimatedWrapper = require("../reanimatedWrapper");
|
11
|
+
|
12
|
+
var _gestureStateManager = require("../gestureStateManager");
|
13
|
+
|
14
|
+
var _State = require("../../../State");
|
15
|
+
|
16
|
+
var _TouchEventType = require("../../../TouchEventType");
|
17
|
+
|
18
|
+
var _utils = require("../../../utils");
|
19
|
+
|
20
|
+
function getHandler(type, gesture) {
|
21
|
+
'worklet';
|
22
|
+
|
23
|
+
switch (type) {
|
24
|
+
case _gesture.CALLBACK_TYPE.BEGAN:
|
25
|
+
return gesture.onBegin;
|
26
|
+
|
27
|
+
case _gesture.CALLBACK_TYPE.START:
|
28
|
+
return gesture.onStart;
|
29
|
+
|
30
|
+
case _gesture.CALLBACK_TYPE.UPDATE:
|
31
|
+
return gesture.onUpdate;
|
32
|
+
|
33
|
+
case _gesture.CALLBACK_TYPE.CHANGE:
|
34
|
+
return gesture.onChange;
|
35
|
+
|
36
|
+
case _gesture.CALLBACK_TYPE.END:
|
37
|
+
return gesture.onEnd;
|
38
|
+
|
39
|
+
case _gesture.CALLBACK_TYPE.FINALIZE:
|
40
|
+
return gesture.onFinalize;
|
41
|
+
|
42
|
+
case _gesture.CALLBACK_TYPE.TOUCHES_DOWN:
|
43
|
+
return gesture.onTouchesDown;
|
44
|
+
|
45
|
+
case _gesture.CALLBACK_TYPE.TOUCHES_MOVE:
|
46
|
+
return gesture.onTouchesMove;
|
47
|
+
|
48
|
+
case _gesture.CALLBACK_TYPE.TOUCHES_UP:
|
49
|
+
return gesture.onTouchesUp;
|
50
|
+
|
51
|
+
case _gesture.CALLBACK_TYPE.TOUCHES_CANCELLED:
|
52
|
+
return gesture.onTouchesCancelled;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
function touchEventTypeToCallbackType(eventType) {
|
57
|
+
'worklet';
|
58
|
+
|
59
|
+
switch (eventType) {
|
60
|
+
case _TouchEventType.TouchEventType.TOUCHES_DOWN:
|
61
|
+
return _gesture.CALLBACK_TYPE.TOUCHES_DOWN;
|
62
|
+
|
63
|
+
case _TouchEventType.TouchEventType.TOUCHES_MOVE:
|
64
|
+
return _gesture.CALLBACK_TYPE.TOUCHES_MOVE;
|
65
|
+
|
66
|
+
case _TouchEventType.TouchEventType.TOUCHES_UP:
|
67
|
+
return _gesture.CALLBACK_TYPE.TOUCHES_UP;
|
68
|
+
|
69
|
+
case _TouchEventType.TouchEventType.TOUCHES_CANCELLED:
|
70
|
+
return _gesture.CALLBACK_TYPE.TOUCHES_CANCELLED;
|
71
|
+
}
|
72
|
+
|
73
|
+
return _gesture.CALLBACK_TYPE.UNDEFINED;
|
74
|
+
}
|
75
|
+
|
76
|
+
function runWorklet(type, gesture, event, ...args) {
|
77
|
+
'worklet';
|
78
|
+
|
79
|
+
const handler = getHandler(type, gesture);
|
80
|
+
|
81
|
+
if (gesture.isWorklet[type]) {
|
82
|
+
// @ts-ignore Logic below makes sure the correct event is send to the
|
83
|
+
// correct handler.
|
84
|
+
handler === null || handler === void 0 ? void 0 : handler(event, ...args);
|
85
|
+
} else if (handler) {
|
86
|
+
console.warn((0, _utils.tagMessage)('Animated gesture callback must be a worklet'));
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
function isStateChangeEvent(event) {
|
91
|
+
'worklet'; // @ts-ignore Yes, the oldState prop is missing on GestureTouchEvent, that's the point
|
92
|
+
|
93
|
+
return event.oldState != null;
|
94
|
+
}
|
95
|
+
|
96
|
+
function isTouchEvent(event) {
|
97
|
+
'worklet';
|
98
|
+
|
99
|
+
return event.eventType != null;
|
100
|
+
}
|
101
|
+
|
102
|
+
function useAnimatedGesture(preparedGesture, needsRebuild) {
|
103
|
+
if (!_reanimatedWrapper.Reanimated) {
|
104
|
+
return;
|
105
|
+
} // Hooks are called conditionally, but the condition is whether the
|
106
|
+
// react-native-reanimated is installed, which shouldn't change while running
|
107
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
108
|
+
|
109
|
+
|
110
|
+
const sharedHandlersCallbacks = _reanimatedWrapper.Reanimated.useSharedValue(null); // eslint-disable-next-line react-hooks/rules-of-hooks
|
111
|
+
|
112
|
+
|
113
|
+
const lastUpdateEvent = _reanimatedWrapper.Reanimated.useSharedValue([]); // not every gesture needs a state controller, init them lazily
|
114
|
+
|
115
|
+
|
116
|
+
const stateControllers = [];
|
117
|
+
|
118
|
+
const callback = event => {
|
119
|
+
'worklet';
|
120
|
+
|
121
|
+
const currentCallback = sharedHandlersCallbacks.value;
|
122
|
+
|
123
|
+
if (!currentCallback) {
|
124
|
+
return;
|
125
|
+
}
|
126
|
+
|
127
|
+
for (let i = 0; i < currentCallback.length; i++) {
|
128
|
+
const gesture = currentCallback[i];
|
129
|
+
|
130
|
+
if (event.handlerTag !== gesture.handlerTag) {
|
131
|
+
continue;
|
132
|
+
}
|
133
|
+
|
134
|
+
if (isStateChangeEvent(event)) {
|
135
|
+
if (event.oldState === _State.State.UNDETERMINED && event.state === _State.State.BEGAN) {
|
136
|
+
runWorklet(_gesture.CALLBACK_TYPE.BEGAN, gesture, event);
|
137
|
+
} else if ((event.oldState === _State.State.BEGAN || event.oldState === _State.State.UNDETERMINED) && event.state === _State.State.ACTIVE) {
|
138
|
+
runWorklet(_gesture.CALLBACK_TYPE.START, gesture, event);
|
139
|
+
lastUpdateEvent.value[gesture.handlerTag] = undefined;
|
140
|
+
} else if (event.oldState !== event.state && event.state === _State.State.END) {
|
141
|
+
if (event.oldState === _State.State.ACTIVE) {
|
142
|
+
runWorklet(_gesture.CALLBACK_TYPE.END, gesture, event, true);
|
143
|
+
}
|
144
|
+
|
145
|
+
runWorklet(_gesture.CALLBACK_TYPE.FINALIZE, gesture, event, true);
|
146
|
+
} else if ((event.state === _State.State.FAILED || event.state === _State.State.CANCELLED) && event.state !== event.oldState) {
|
147
|
+
if (event.oldState === _State.State.ACTIVE) {
|
148
|
+
runWorklet(_gesture.CALLBACK_TYPE.END, gesture, event, false);
|
149
|
+
}
|
150
|
+
|
151
|
+
runWorklet(_gesture.CALLBACK_TYPE.FINALIZE, gesture, event, false);
|
152
|
+
}
|
153
|
+
} else if (isTouchEvent(event)) {
|
154
|
+
if (!stateControllers[i]) {
|
155
|
+
stateControllers[i] = _gestureStateManager.GestureStateManager.create(event.handlerTag);
|
156
|
+
}
|
157
|
+
|
158
|
+
if (event.eventType !== _TouchEventType.TouchEventType.UNDETERMINED) {
|
159
|
+
runWorklet(touchEventTypeToCallbackType(event.eventType), gesture, event, stateControllers[i]);
|
160
|
+
}
|
161
|
+
} else {
|
162
|
+
runWorklet(_gesture.CALLBACK_TYPE.UPDATE, gesture, event);
|
163
|
+
|
164
|
+
if (gesture.onChange && gesture.changeEventCalculator) {
|
165
|
+
var _gesture$changeEventC;
|
166
|
+
|
167
|
+
runWorklet(_gesture.CALLBACK_TYPE.CHANGE, gesture, (_gesture$changeEventC = gesture.changeEventCalculator) === null || _gesture$changeEventC === void 0 ? void 0 : _gesture$changeEventC.call(gesture, event, lastUpdateEvent.value[gesture.handlerTag]));
|
168
|
+
lastUpdateEvent.value[gesture.handlerTag] = event;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
}; // eslint-disable-next-line react-hooks/rules-of-hooks
|
173
|
+
|
174
|
+
|
175
|
+
const event = _reanimatedWrapper.Reanimated.useEvent(callback, ['onGestureHandlerStateChange', 'onGestureHandlerEvent'], needsRebuild);
|
176
|
+
|
177
|
+
preparedGesture.animatedEventHandler = event;
|
178
|
+
preparedGesture.animatedHandlers = sharedHandlersCallbacks;
|
179
|
+
}
|
180
|
+
//# sourceMappingURL=useAnimatedGesture.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["useAnimatedGesture.ts"],"names":["getHandler","type","gesture","CALLBACK_TYPE","BEGAN","onBegin","START","onStart","UPDATE","onUpdate","CHANGE","onChange","END","onEnd","FINALIZE","onFinalize","TOUCHES_DOWN","onTouchesDown","TOUCHES_MOVE","onTouchesMove","TOUCHES_UP","onTouchesUp","TOUCHES_CANCELLED","onTouchesCancelled","touchEventTypeToCallbackType","eventType","TouchEventType","UNDEFINED","runWorklet","event","args","handler","isWorklet","console","warn","isStateChangeEvent","oldState","isTouchEvent","useAnimatedGesture","preparedGesture","needsRebuild","Reanimated","sharedHandlersCallbacks","useSharedValue","lastUpdateEvent","stateControllers","callback","currentCallback","value","i","length","handlerTag","State","UNDETERMINED","state","ACTIVE","undefined","FAILED","CANCELLED","GestureStateManager","create","changeEventCalculator","useEvent","animatedEventHandler","animatedHandlers"],"mappings":";;;;;;;AAAA;;AACA;;AAMA;;AAIA;;AACA;;AACA;;AAGA,SAASA,UAAT,CACEC,IADF,EAEEC,OAFF,EAGE;AACA;;AACA,UAAQD,IAAR;AACE,SAAKE,uBAAcC,KAAnB;AACE,aAAOF,OAAO,CAACG,OAAf;;AACF,SAAKF,uBAAcG,KAAnB;AACE,aAAOJ,OAAO,CAACK,OAAf;;AACF,SAAKJ,uBAAcK,MAAnB;AACE,aAAON,OAAO,CAACO,QAAf;;AACF,SAAKN,uBAAcO,MAAnB;AACE,aAAOR,OAAO,CAACS,QAAf;;AACF,SAAKR,uBAAcS,GAAnB;AACE,aAAOV,OAAO,CAACW,KAAf;;AACF,SAAKV,uBAAcW,QAAnB;AACE,aAAOZ,OAAO,CAACa,UAAf;;AACF,SAAKZ,uBAAca,YAAnB;AACE,aAAOd,OAAO,CAACe,aAAf;;AACF,SAAKd,uBAAce,YAAnB;AACE,a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uBAAcK,MAAf,EAAuBN,OAAvB,EAAgC2B,KAAhC,CAAV;;AAEA,YAAI3B,OAAO,CAACS,QAAR,IAAoBT,OAAO,CAAC2D,qBAAhC,EAAuD;AAAA;;AACrDjC,UAAAA,UAAU,CACRzB,uBAAcO,MADN,EAERR,OAFQ,2BAGRA,OAAO,CAAC2D,qBAHA,0DAGR,2BAAA3D,OAAO,EACL2B,KADK,EAELe,eAAe,CAACI,KAAhB,CAAsB9C,OAAO,CAACiD,UAA9B,CAFK,CAHC,CAAV;AASAP,UAAAA,eAAe,CAACI,KAAhB,CAAsB9C,OAAO,CAACiD,UAA9B,IAA4CtB,KAA5C;AACD;AACF;AACF;AACF,GA7ED,CApBA,CAmGA;;;AACA,QAAMA,KAAK,GAAGY,8BAAWqB,QAAX,CACZhB,QADY,EAEZ,CAAC,6BAAD,EAAgC,uBAAhC,CAFY,EAGZN,YAHY,CAAd;;AAMAD,EAAAA,eAAe,CAACwB,oBAAhB,GAAuClC,KAAvC;AACAU,EAAAA,eAAe,CAACyB,gBAAhB,GAAmCtB,uBAAnC;AACD","sourcesContent":["import { HandlerCallbacks, CALLBACK_TYPE } from '../gesture';\nimport { Reanimated } from '../reanimatedWrapper';\nimport {\n GestureTouchEvent,\n GestureUpdateEvent,\n GestureStateChangeEvent,\n} from '../../gestureHandlerCommon';\nimport {\n GestureStateManager,\n GestureStateManagerType,\n} from '../gestureStateManager';\nimport { State } from '../../../State';\nimport { TouchEventType } from '../../../TouchEventType';\nimport { tagMessage } from '../../../utils';\nimport { AttachedGestureState } from './types';\n\nfunction getHandler(\n type: CALLBACK_TYPE,\n gesture: HandlerCallbacks<Record<string, unknown>>\n) {\n 'worklet';\n switch (type) {\n case CALLBACK_TYPE.BEGAN:\n return gesture.onBegin;\n case CALLBACK_TYPE.START:\n return gesture.onStart;\n case CALLBACK_TYPE.UPDATE:\n return gesture.onUpdate;\n case CALLBACK_TYPE.CHANGE:\n return gesture.onChange;\n case CALLBACK_TYPE.END:\n return gesture.onEnd;\n case CALLBACK_TYPE.FINALIZE:\n return gesture.onFinalize;\n case CALLBACK_TYPE.TOUCHES_DOWN:\n return gesture.onTouchesDown;\n case CALLBACK_TYPE.TOUCHES_MOVE:\n return gesture.onTouchesMove;\n case CALLBACK_TYPE.TOUCHES_UP:\n return gesture.onTouchesUp;\n case CALLBACK_TYPE.TOUCHES_CANCELLED:\n return gesture.onTouchesCancelled;\n }\n}\n\nfunction touchEventTypeToCallbackType(\n eventType: TouchEventType\n): CALLBACK_TYPE {\n 'worklet';\n switch (eventType) {\n case TouchEventType.TOUCHES_DOWN:\n return CALLBACK_TYPE.TOUCHES_DOWN;\n case TouchEventType.TOUCHES_MOVE:\n return CALLBACK_TYPE.TOUCHES_MOVE;\n case TouchEventType.TOUCHES_UP:\n return CALLBACK_TYPE.TOUCHES_UP;\n case TouchEventType.TOUCHES_CANCELLED:\n return CALLBACK_TYPE.TOUCHES_CANCELLED;\n }\n return CALLBACK_TYPE.UNDEFINED;\n}\n\nfunction runWorklet(\n type: CALLBACK_TYPE,\n gesture: HandlerCallbacks<Record<string, unknown>>,\n event: GestureStateChangeEvent | GestureUpdateEvent | GestureTouchEvent,\n ...args: unknown[]\n) {\n 'worklet';\n const handler = getHandler(type, gesture);\n if (gesture.isWorklet[type]) {\n // @ts-ignore Logic below makes sure the correct event is send to the\n // correct handler.\n handler?.(event, ...args);\n } else if (handler) {\n console.warn(tagMessage('Animated gesture callback must be a worklet'));\n }\n}\n\nfunction isStateChangeEvent(\n event: GestureUpdateEvent | GestureStateChangeEvent | GestureTouchEvent\n): event is GestureStateChangeEvent {\n 'worklet';\n // @ts-ignore Yes, the oldState prop is missing on GestureTouchEvent, that's the point\n return event.oldState != null;\n}\n\nfunction isTouchEvent(\n event: GestureUpdateEvent | GestureStateChangeEvent | GestureTouchEvent\n): event is GestureTouchEvent {\n 'worklet';\n return event.eventType != null;\n}\n\nexport function useAnimatedGesture(\n preparedGesture: AttachedGestureState,\n needsRebuild: boolean\n) {\n if (!Reanimated) {\n return;\n }\n\n // Hooks are called conditionally, but the condition is whether the\n // react-native-reanimated is installed, which shouldn't change while running\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const sharedHandlersCallbacks = Reanimated.useSharedValue<\n HandlerCallbacks<Record<string, unknown>>[] | null\n >(null);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const lastUpdateEvent = Reanimated.useSharedValue<\n (GestureUpdateEvent | undefined)[]\n >([]);\n\n // not every gesture needs a state controller, init them lazily\n const stateControllers: GestureStateManagerType[] = [];\n\n const callback = (\n event: GestureStateChangeEvent | GestureUpdateEvent | GestureTouchEvent\n ) => {\n 'worklet';\n\n const currentCallback = sharedHandlersCallbacks.value;\n if (!currentCallback) {\n return;\n }\n\n for (let i = 0; i < currentCallback.length; i++) {\n const gesture = currentCallback[i];\n\n if (event.handlerTag !== gesture.handlerTag) {\n continue;\n }\n\n if (isStateChangeEvent(event)) {\n if (\n event.oldState === State.UNDETERMINED &&\n event.state === State.BEGAN\n ) {\n runWorklet(CALLBACK_TYPE.BEGAN, gesture, event);\n } else if (\n (event.oldState === State.BEGAN ||\n event.oldState === State.UNDETERMINED) &&\n event.state === State.ACTIVE\n ) {\n runWorklet(CALLBACK_TYPE.START, gesture, event);\n lastUpdateEvent.value[gesture.handlerTag] = undefined;\n } else if (\n event.oldState !== event.state &&\n event.state === State.END\n ) {\n if (event.oldState === State.ACTIVE) {\n runWorklet(CALLBACK_TYPE.END, gesture, event, true);\n }\n runWorklet(CALLBACK_TYPE.FINALIZE, gesture, event, true);\n } else if (\n (event.state === State.FAILED || event.state === State.CANCELLED) &&\n event.state !== event.oldState\n ) {\n if (event.oldState === State.ACTIVE) {\n runWorklet(CALLBACK_TYPE.END, gesture, event, false);\n }\n runWorklet(CALLBACK_TYPE.FINALIZE, gesture, event, false);\n }\n } else if (isTouchEvent(event)) {\n if (!stateControllers[i]) {\n stateControllers[i] = GestureStateManager.create(event.handlerTag);\n }\n\n if (event.eventType !== TouchEventType.UNDETERMINED) {\n runWorklet(\n touchEventTypeToCallbackType(event.eventType),\n gesture,\n event,\n stateControllers[i]\n );\n }\n } else {\n runWorklet(CALLBACK_TYPE.UPDATE, gesture, event);\n\n if (gesture.onChange && gesture.changeEventCalculator) {\n runWorklet(\n CALLBACK_TYPE.CHANGE,\n gesture,\n gesture.changeEventCalculator?.(\n event,\n lastUpdateEvent.value[gesture.handlerTag]\n )\n );\n\n lastUpdateEvent.value[gesture.handlerTag] = event;\n }\n }\n }\n };\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const event = Reanimated.useEvent(\n callback,\n ['onGestureHandlerStateChange', 'onGestureHandlerEvent'],\n needsRebuild\n );\n\n preparedGesture.animatedEventHandler = event;\n preparedGesture.animatedHandlers = sharedHandlersCallbacks;\n}\n"]}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useDetectorUpdater = useDetectorUpdater;
|
7
|
+
|
8
|
+
var _react = require("react");
|
9
|
+
|
10
|
+
var _reactNative = require("react-native");
|
11
|
+
|
12
|
+
var _attachHandlers = require("./attachHandlers");
|
13
|
+
|
14
|
+
var _updateHandlers = require("./updateHandlers");
|
15
|
+
|
16
|
+
var _needsToReattach = require("./needsToReattach");
|
17
|
+
|
18
|
+
var _dropHandlers = require("./dropHandlers");
|
19
|
+
|
20
|
+
var _utils = require("./utils");
|
21
|
+
|
22
|
+
// Returns a function that's responsible for updating the attached gestures
|
23
|
+
// If the view has changed, it will reattach the handlers to the new view
|
24
|
+
// If the view remains the same, it will update the handlers with the new config
|
25
|
+
function useDetectorUpdater(state, preparedGesture, gesturesToAttach, gestureConfig, webEventHandlersRef) {
|
26
|
+
const forceRender = (0, _utils.useForceRender)();
|
27
|
+
const updateAttachedGestures = (0, _react.useCallback)( // skipConfigUpdate is used to prevent unnecessary updates when only checking if the view has changed
|
28
|
+
skipConfigUpdate => {
|
29
|
+
// if the underlying view has changed we need to reattach handlers to the new view
|
30
|
+
const viewTag = (0, _reactNative.findNodeHandle)(state.viewRef);
|
31
|
+
const didUnderlyingViewChange = viewTag !== state.previousViewTag;
|
32
|
+
|
33
|
+
if (didUnderlyingViewChange || (0, _needsToReattach.needsToReattach)(preparedGesture, gesturesToAttach)) {
|
34
|
+
(0, _utils.validateDetectorChildren)(state.viewRef);
|
35
|
+
(0, _dropHandlers.dropHandlers)(preparedGesture);
|
36
|
+
(0, _attachHandlers.attachHandlers)({
|
37
|
+
preparedGesture,
|
38
|
+
gestureConfig,
|
39
|
+
gesturesToAttach,
|
40
|
+
webEventHandlersRef,
|
41
|
+
viewTag
|
42
|
+
});
|
43
|
+
|
44
|
+
if (didUnderlyingViewChange) {
|
45
|
+
state.previousViewTag = viewTag;
|
46
|
+
state.forceRebuildReanimatedEvent = true;
|
47
|
+
forceRender();
|
48
|
+
}
|
49
|
+
} else if (!skipConfigUpdate) {
|
50
|
+
(0, _updateHandlers.updateHandlers)(preparedGesture, gestureConfig, gesturesToAttach);
|
51
|
+
}
|
52
|
+
}, [forceRender, gestureConfig, gesturesToAttach, preparedGesture, state, webEventHandlersRef]);
|
53
|
+
return updateAttachedGestures;
|
54
|
+
}
|
55
|
+
//# sourceMappingURL=useDetectorUpdater.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["useDetectorUpdater.ts"],"names":["useDetectorUpdater","state","preparedGesture","gesturesToAttach","gestureConfig","webEventHandlersRef","forceRender","updateAttachedGestures","skipConfigUpdate","viewTag","viewRef","didUnderlyingViewChange","previousViewTag","forceRebuildReanimatedEvent"],"mappings":";;;;;;;AAAA;;AACA;;AASA;;AACA;;AACA;;AACA;;AACA;;AAEA;AACA;AACA;AACO,SAASA,kBAAT,CACLC,KADK,EAELC,eAFK,EAGLC,gBAHK,EAILC,aAJK,EAKLC,mBALK,EAML;AACA,QAAMC,WAAW,GAAG,4BAApB;AACA,QAAMC,sBAAsB,GAAG,yBAC7B;AACCC,EAAAA,gBAAD,IAAgC;AAC9B;AACA,UAAMC,OAAO,GAAG,iCAAeR,KAAK,CAACS,OAArB,CAAhB;AACA,UAAMC,uBAAuB,GAAGF,OAAO,KAAKR,KAAK,CAACW,eAAlD;;AAEA,QACED,uBAAuB,IACvB,sCAAgBT,eAAhB,EAAiCC,gBAAjC,CAFF,EAGE;AACA,2CAAyBF,KAAK,CAACS,OAA/B;AACA,sCAAaR,eAAb;AACA,0CAAe;AACbA,QAAAA,eADa;AAEbE,QAAAA,aAFa;AAGbD,QAAAA,gBAHa;AAIbE,QAAAA,mBAJa;AAKbI,QAAAA;AALa,OAAf;;AAQA,UAAIE,uBAAJ,EAA6B;AAC3BV,QAAAA,KAAK,CAACW,eAAN,GAAwBH,OAAxB;AACAR,QAAAA,KAAK,CAACY,2BAAN,GAAoC,IAApC;AACAP,QAAAA,WAAW;AACZ;AACF,KAnBD,MAmBO,IAAI,CAACE,gBAAL,EAAuB;AAC5B,0CAAeN,eAAf,EAAgCE,aAAhC,EAA+CD,gBAA/C;AACD;AACF,GA7B4B,EA8B7B,CACEG,WADF,EAEEF,aAFF,EAGED,gBAHF,EAIED,eAJF,EAKED,KALF,EAMEI,mBANF,CA9B6B,CAA/B;AAwCA,SAAOE,sBAAP;AACD","sourcesContent":["import React, { useCallback } from 'react';\nimport { findNodeHandle } from 'react-native';\nimport { GestureType } from '../gesture';\nimport { ComposedGesture } from '../gestureComposition';\n\nimport {\n AttachedGestureState,\n GestureDetectorState,\n WebEventHandler,\n} from './types';\nimport { attachHandlers } from './attachHandlers';\nimport { updateHandlers } from './updateHandlers';\nimport { needsToReattach } from './needsToReattach';\nimport { dropHandlers } from './dropHandlers';\nimport { useForceRender, validateDetectorChildren } from './utils';\n\n// Returns a function that's responsible for updating the attached gestures\n// If the view has changed, it will reattach the handlers to the new view\n// If the view remains the same, it will update the handlers with the new config\nexport function useDetectorUpdater(\n state: GestureDetectorState,\n preparedGesture: AttachedGestureState,\n gesturesToAttach: GestureType[],\n gestureConfig: ComposedGesture | GestureType,\n webEventHandlersRef: React.RefObject<WebEventHandler>\n) {\n const forceRender = useForceRender();\n const updateAttachedGestures = useCallback(\n // skipConfigUpdate is used to prevent unnecessary updates when only checking if the view has changed\n (skipConfigUpdate?: boolean) => {\n // if the underlying view has changed we need to reattach handlers to the new view\n const viewTag = findNodeHandle(state.viewRef) as number;\n const didUnderlyingViewChange = viewTag !== state.previousViewTag;\n\n if (\n didUnderlyingViewChange ||\n needsToReattach(preparedGesture, gesturesToAttach)\n ) {\n validateDetectorChildren(state.viewRef);\n dropHandlers(preparedGesture);\n attachHandlers({\n preparedGesture,\n gestureConfig,\n gesturesToAttach,\n webEventHandlersRef,\n viewTag,\n });\n\n if (didUnderlyingViewChange) {\n state.previousViewTag = viewTag;\n state.forceRebuildReanimatedEvent = true;\n forceRender();\n }\n } else if (!skipConfigUpdate) {\n updateHandlers(preparedGesture, gestureConfig, gesturesToAttach);\n }\n },\n [\n forceRender,\n gestureConfig,\n gesturesToAttach,\n preparedGesture,\n state,\n webEventHandlersRef,\n ]\n );\n\n return updateAttachedGestures;\n}\n"]}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useViewRefHandler = useViewRefHandler;
|
7
|
+
|
8
|
+
var _utils = require("../../../utils");
|
9
|
+
|
10
|
+
var _getShadowNodeFromRef = require("../../../getShadowNodeFromRef");
|
11
|
+
|
12
|
+
var _react = require("react");
|
13
|
+
|
14
|
+
var _reactNative = require("react-native");
|
15
|
+
|
16
|
+
// Ref handler for the Wrap component attached under the GestureDetector.
|
17
|
+
// It's responsible for setting the viewRef on the state and triggering the reattaching of handlers
|
18
|
+
// if the view has changed.
|
19
|
+
function useViewRefHandler(state, updateAttachedGestures) {
|
20
|
+
const refHandler = (0, _react.useCallback)(ref => {
|
21
|
+
if (ref === null) {
|
22
|
+
return;
|
23
|
+
}
|
24
|
+
|
25
|
+
state.viewRef = ref; // if it's the first render, also set the previousViewTag to prevent reattaching gestures when not needed
|
26
|
+
|
27
|
+
if (state.previousViewTag === -1) {
|
28
|
+
state.previousViewTag = (0, _reactNative.findNodeHandle)(state.viewRef);
|
29
|
+
} // Pass true as `skipConfigUpdate`. Here we only want to trigger the eventual reattaching of handlers
|
30
|
+
// in case the view has changed. If the view doesn't change, the update will be handled by detector.
|
31
|
+
|
32
|
+
|
33
|
+
if (!state.firstRender) {
|
34
|
+
updateAttachedGestures(true);
|
35
|
+
}
|
36
|
+
|
37
|
+
if (__DEV__ && (0, _utils.isFabric)() && global.isFormsStackingContext) {
|
38
|
+
const node = (0, _getShadowNodeFromRef.getShadowNodeFromRef)(ref);
|
39
|
+
|
40
|
+
if (global.isFormsStackingContext(node) === false) {
|
41
|
+
console.error((0, _utils.tagMessage)('GestureDetector has received a child that may get view-flattened. ' + '\nTo prevent it from misbehaving you need to wrap the child with a `<View collapsable={false}>`.'));
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}, [state, updateAttachedGestures]);
|
45
|
+
return refHandler;
|
46
|
+
}
|
47
|
+
//# sourceMappingURL=useViewRefHandler.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["useViewRefHandler.ts"],"names":["useViewRefHandler","state","updateAttachedGestures","refHandler","ref","viewRef","previousViewTag","firstRender","__DEV__","global","isFormsStackingContext","node","console","error"],"mappings":";;;;;;;AAAA;;AACA;;AAGA;;AACA;;AAMA;AACA;AACA;AACO,SAASA,iBAAT,CACLC,KADK,EAELC,sBAFK,EAGL;AACA,QAAMC,UAAU,GAAG,wBAChBC,GAAD,IAAiC;AAC/B,QAAIA,GAAG,KAAK,IAAZ,EAAkB;AAChB;AACD;;AAEDH,IAAAA,KAAK,CAACI,OAAN,GAAgBD,GAAhB,CAL+B,CAO/B;;AACA,QAAIH,KAAK,CAACK,eAAN,KAA0B,CAAC,CAA/B,EAAkC;AAChCL,MAAAA,KAAK,CAACK,eAAN,GAAwB,iCAAeL,KAAK,CAACI,OAArB,CAAxB;AACD,KAV8B,CAY/B;AACA;;;AACA,QAAI,CAACJ,KAAK,CAACM,WAAX,EAAwB;AACtBL,MAAAA,sBAAsB,CAAC,IAAD,CAAtB;AACD;;AAED,QAAIM,OAAO,IAAI,sBAAX,IAAyBC,MAAM,CAACC,sBAApC,EAA4D;AAC1D,YAAMC,IAAI,GAAG,gDAAqBP,GAArB,CAAb;;AACA,UAAIK,MAAM,CAACC,sBAAP,CAA8BC,IAA9B,MAAwC,KAA5C,EAAmD;AACjDC,QAAAA,OAAO,CAACC,KAAR,CACE,uBACE,uEACE,kGAFJ,CADF;AAMD;AACF;AACF,GA9BgB,EA+BjB,CAACZ,KAAD,EAAQC,sBAAR,CA/BiB,CAAnB;AAkCA,SAAOC,UAAP;AACD","sourcesContent":["import { isFabric, tagMessage } from '../../../utils';\nimport { getShadowNodeFromRef } from '../../../getShadowNodeFromRef';\n\nimport { GestureDetectorState } from './types';\nimport React, { useCallback } from 'react';\nimport { findNodeHandle } from 'react-native';\n\ndeclare const global: {\n isFormsStackingContext: (node: unknown) => boolean | null; // JSI function\n};\n\n// Ref handler for the Wrap component attached under the GestureDetector.\n// It's responsible for setting the viewRef on the state and triggering the reattaching of handlers\n// if the view has changed.\nexport function useViewRefHandler(\n state: GestureDetectorState,\n updateAttachedGestures: (skipConfigUpdate?: boolean) => void\n) {\n const refHandler = useCallback(\n (ref: React.Component | null) => {\n if (ref === null) {\n return;\n }\n\n state.viewRef = ref;\n\n // if it's the first render, also set the previousViewTag to prevent reattaching gestures when not needed\n if (state.previousViewTag === -1) {\n state.previousViewTag = findNodeHandle(state.viewRef) as number;\n }\n\n // Pass true as `skipConfigUpdate`. Here we only want to trigger the eventual reattaching of handlers\n // in case the view has changed. If the view doesn't change, the update will be handled by detector.\n if (!state.firstRender) {\n updateAttachedGestures(true);\n }\n\n if (__DEV__ && isFabric() && global.isFormsStackingContext) {\n const node = getShadowNodeFromRef(ref);\n if (global.isFormsStackingContext(node) === false) {\n console.error(\n tagMessage(\n 'GestureDetector has received a child that may get view-flattened. ' +\n '\\nTo prevent it from misbehaving you need to wrap the child with a `<View collapsable={false}>`.'\n )\n );\n }\n }\n },\n [state, updateAttachedGestures]\n );\n\n return refHandler;\n}\n"]}
|
@@ -0,0 +1,176 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.extractGestureRelations = extractGestureRelations;
|
7
|
+
exports.checkGestureCallbacksForWorklets = checkGestureCallbacksForWorklets;
|
8
|
+
exports.validateDetectorChildren = validateDetectorChildren;
|
9
|
+
exports.useForceRender = useForceRender;
|
10
|
+
exports.useWebEventHandlers = useWebEventHandlers;
|
11
|
+
exports.ALLOWED_PROPS = void 0;
|
12
|
+
|
13
|
+
var _reactNative = require("react-native");
|
14
|
+
|
15
|
+
var _utils = require("../../../utils");
|
16
|
+
|
17
|
+
var _gesture = require("../gesture");
|
18
|
+
|
19
|
+
var _FlingGestureHandler = require("../../FlingGestureHandler");
|
20
|
+
|
21
|
+
var _ForceTouchGestureHandler = require("../../ForceTouchGestureHandler");
|
22
|
+
|
23
|
+
var _LongPressGestureHandler = require("../../LongPressGestureHandler");
|
24
|
+
|
25
|
+
var _PanGestureHandler = require("../../PanGestureHandler");
|
26
|
+
|
27
|
+
var _TapGestureHandler = require("../../TapGestureHandler");
|
28
|
+
|
29
|
+
var _hoverGesture = require("../hoverGesture");
|
30
|
+
|
31
|
+
var _NativeViewGestureHandler = require("../../NativeViewGestureHandler");
|
32
|
+
|
33
|
+
var _gestureHandlerCommon = require("../../gestureHandlerCommon");
|
34
|
+
|
35
|
+
var _EnableNewWebImplementation = require("../../../EnableNewWebImplementation");
|
36
|
+
|
37
|
+
var _getReactNativeVersion = require("../../../getReactNativeVersion");
|
38
|
+
|
39
|
+
var _RNRenderer = require("../../../RNRenderer");
|
40
|
+
|
41
|
+
var _react = require("react");
|
42
|
+
|
43
|
+
var _reanimatedWrapper = require("../reanimatedWrapper");
|
44
|
+
|
45
|
+
var _eventReceiver = require("../eventReceiver");
|
46
|
+
|
47
|
+
const ALLOWED_PROPS = [..._gestureHandlerCommon.baseGestureHandlerWithDetectorProps, ..._TapGestureHandler.tapGestureHandlerProps, ..._PanGestureHandler.panGestureHandlerProps, ..._PanGestureHandler.panGestureHandlerCustomNativeProps, ..._LongPressGestureHandler.longPressGestureHandlerProps, ..._ForceTouchGestureHandler.forceTouchGestureHandlerProps, ..._FlingGestureHandler.flingGestureHandlerProps, ..._hoverGesture.hoverGestureHandlerProps, ..._NativeViewGestureHandler.nativeViewGestureHandlerProps];
|
48
|
+
exports.ALLOWED_PROPS = ALLOWED_PROPS;
|
49
|
+
|
50
|
+
function convertToHandlerTag(ref) {
|
51
|
+
if (typeof ref === 'number') {
|
52
|
+
return ref;
|
53
|
+
} else if (ref instanceof _gesture.BaseGesture) {
|
54
|
+
return ref.handlerTag;
|
55
|
+
} else {
|
56
|
+
var _ref$current$handlerT, _ref$current;
|
57
|
+
|
58
|
+
// @ts-ignore in this case it should be a ref either to gesture object or
|
59
|
+
// a gesture handler component, in both cases handlerTag property exists
|
60
|
+
return (_ref$current$handlerT = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.handlerTag) !== null && _ref$current$handlerT !== void 0 ? _ref$current$handlerT : -1;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
function extractValidHandlerTags(interactionGroup) {
|
65
|
+
var _interactionGroup$map, _interactionGroup$map2;
|
66
|
+
|
67
|
+
return (_interactionGroup$map = interactionGroup === null || interactionGroup === void 0 ? void 0 : (_interactionGroup$map2 = interactionGroup.map(convertToHandlerTag)) === null || _interactionGroup$map2 === void 0 ? void 0 : _interactionGroup$map2.filter(tag => tag > 0)) !== null && _interactionGroup$map !== void 0 ? _interactionGroup$map : [];
|
68
|
+
}
|
69
|
+
|
70
|
+
function extractGestureRelations(gesture) {
|
71
|
+
const requireToFail = extractValidHandlerTags(gesture.config.requireToFail);
|
72
|
+
const simultaneousWith = extractValidHandlerTags(gesture.config.simultaneousWith);
|
73
|
+
const blocksHandlers = extractValidHandlerTags(gesture.config.blocksHandlers);
|
74
|
+
return {
|
75
|
+
waitFor: requireToFail,
|
76
|
+
simultaneousHandlers: simultaneousWith,
|
77
|
+
blocksHandlers: blocksHandlers
|
78
|
+
};
|
79
|
+
}
|
80
|
+
|
81
|
+
function checkGestureCallbacksForWorklets(gesture) {
|
82
|
+
if (!__DEV__) {
|
83
|
+
return;
|
84
|
+
} // if a gesture is explicitly marked to run on the JS thread there is no need to check
|
85
|
+
// if callbacks are worklets as the user is aware they will be ran on the JS thread
|
86
|
+
|
87
|
+
|
88
|
+
if (gesture.config.runOnJS) {
|
89
|
+
return;
|
90
|
+
}
|
91
|
+
|
92
|
+
const areSomeNotWorklets = gesture.handlers.isWorklet.includes(false);
|
93
|
+
const areSomeWorklets = gesture.handlers.isWorklet.includes(true); // if some of the callbacks are worklets and some are not, and the gesture is not
|
94
|
+
// explicitly marked with `.runOnJS(true)` show an error
|
95
|
+
|
96
|
+
if (areSomeNotWorklets && areSomeWorklets) {
|
97
|
+
console.error((0, _utils.tagMessage)(`Some of the callbacks in the gesture are worklets and some are not. Either make sure that all calbacks are marked as 'worklet' if you wish to run them on the UI thread or use '.runOnJS(true)' modifier on the gesture explicitly to run all callbacks on the JS thread.`));
|
98
|
+
}
|
99
|
+
|
100
|
+
if (_reanimatedWrapper.Reanimated === undefined) {
|
101
|
+
// if Reanimated is not available, we can't run worklets, so we shouldn't show the warning
|
102
|
+
return;
|
103
|
+
}
|
104
|
+
|
105
|
+
const areAllNotWorklets = !areSomeWorklets && areSomeNotWorklets; // if none of the callbacks are worklets and the gesture is not explicitly marked with
|
106
|
+
// `.runOnJS(true)` show a warning
|
107
|
+
|
108
|
+
if (areAllNotWorklets) {
|
109
|
+
console.warn((0, _utils.tagMessage)(`None of the callbacks in the gesture are worklets. If you wish to run them on the JS thread use '.runOnJS(true)' modifier on the gesture to make this explicit. Otherwise, mark the callbacks as 'worklet' to run them on the UI thread.`));
|
110
|
+
}
|
111
|
+
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
112
|
+
|
113
|
+
|
114
|
+
function validateDetectorChildren(ref) {
|
115
|
+
// finds the first native view under the Wrap component and traverses the fiber tree upwards
|
116
|
+
// to check whether there is more than one native view as a pseudo-direct child of GestureDetector
|
117
|
+
// i.e. this is not ok:
|
118
|
+
// Wrap
|
119
|
+
// |
|
120
|
+
// / \
|
121
|
+
// / \
|
122
|
+
// / \
|
123
|
+
// / \
|
124
|
+
// NativeView NativeView
|
125
|
+
//
|
126
|
+
// but this is fine:
|
127
|
+
// Wrap
|
128
|
+
// |
|
129
|
+
// NativeView
|
130
|
+
// |
|
131
|
+
// / \
|
132
|
+
// / \
|
133
|
+
// / \
|
134
|
+
// / \
|
135
|
+
// NativeView NativeView
|
136
|
+
if (__DEV__ && _reactNative.Platform.OS !== 'web') {
|
137
|
+
const REACT_NATIVE_VERSION = (0, _getReactNativeVersion.getReactNativeVersion)(); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
138
|
+
|
139
|
+
const wrapType = REACT_NATIVE_VERSION.minor > 63 || REACT_NATIVE_VERSION.major > 0 ? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
140
|
+
ref._reactInternals.elementType : // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
141
|
+
ref._reactInternalFiber.elementType; // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
142
|
+
|
143
|
+
let instance = _RNRenderer.RNRenderer.findHostInstance_DEPRECATED(ref)._internalFiberInstanceHandleDEV; // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
144
|
+
|
145
|
+
|
146
|
+
while (instance && instance.elementType !== wrapType) {
|
147
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
148
|
+
if (instance.sibling) {
|
149
|
+
throw new Error('GestureDetector has more than one native view as its children. This can happen if you are using a custom component that renders multiple views, like React.Fragment. You should wrap content of GestureDetector with a <View> or <Animated.View>.');
|
150
|
+
} // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
151
|
+
|
152
|
+
|
153
|
+
instance = instance.return;
|
154
|
+
}
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
function useForceRender() {
|
159
|
+
const [renderState, setRenderState] = (0, _react.useState)(false);
|
160
|
+
const forceRender = (0, _react.useCallback)(() => {
|
161
|
+
setRenderState(!renderState);
|
162
|
+
}, [renderState, setRenderState]);
|
163
|
+
return forceRender;
|
164
|
+
}
|
165
|
+
|
166
|
+
function useWebEventHandlers() {
|
167
|
+
return (0, _react.useRef)({
|
168
|
+
onGestureHandlerEvent: e => {
|
169
|
+
(0, _eventReceiver.onGestureHandlerEvent)(e.nativeEvent);
|
170
|
+
},
|
171
|
+
onGestureHandlerStateChange: (0, _EnableNewWebImplementation.isNewWebImplementationEnabled)() ? e => {
|
172
|
+
(0, _eventReceiver.onGestureHandlerEvent)(e.nativeEvent);
|
173
|
+
} : undefined
|
174
|
+
});
|
175
|
+
}
|
176
|
+
//# sourceMappingURL=utils.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["utils.ts"],"names":["ALLOWED_PROPS","baseGestureHandlerWithDetectorProps","tapGestureHandlerProps","panGestureHandlerProps","panGestureHandlerCustomNativeProps","longPressGestureHandlerProps","forceTouchGestureHandlerProps","flingGestureHandlerProps","hoverGestureHandlerProps","nativeViewGestureHandlerProps","convertToHandlerTag","ref","BaseGesture","handlerTag","current","extractValidHandlerTags","interactionGroup","map","filter","tag","extractGestureRelations","gesture","requireToFail","config","simultaneousWith","blocksHandlers","waitFor","simultaneousHandlers","checkGestureCallbacksForWorklets","__DEV__","runOnJS","areSomeNotWorklets","handlers","isWorklet","includes","areSomeWorklets","console","error","Reanimated","undefined","areAllNotWorklets","warn","validateDetectorChildren","Platform","OS","REACT_NATIVE_VERSION","wrapType","minor","major","_reactInternals","elementType","_reactInternalFiber","instance","RNRenderer","findHostInstance_DEPRECATED","_internalFiberInstanceHandleDEV","sibling","Error","return","useForceRender","renderState","setRenderState","forceRender","useWebEventHandlers","onGestureHandlerEvent","e","nativeEvent","onGestureHandlerStateChange"],"mappings":";;;;;;;;;;;;AAAA;;AAEA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAIA;;AACA;;AACA;;AACA;;AAIA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAGO,MAAMA,aAAa,GAAG,CAC3B,GAAGC,yDADwB,EAE3B,GAAGC,yCAFwB,EAG3B,GAAGC,yCAHwB,EAI3B,GAAGC,qDAJwB,EAK3B,GAAGC,qDALwB,EAM3B,GAAGC,uDANwB,EAO3B,GAAGC,6CAPwB,EAQ3B,GAAGC,sCARwB,EAS3B,GAAGC,uDATwB,CAAtB;;;AAYP,SAASC,mBAAT,CAA6BC,GAA7B,EAAsD;AACpD,MAAI,OAAOA,GAAP,KAAe,QAAnB,EAA6B;AAC3B,WAAOA,GAAP;AACD,GAFD,MAEO,IAAIA,GAAG,YAAYC,oBAAnB,EAAgC;AACrC,WAAOD,GAAG,CAACE,UAAX;AACD,GAFM,MAEA;AAAA;;AACL;AACA;AACA,oDAAOF,GAAG,CAACG,OAAX,iDAAO,aAAaD,UAApB,yEAAkC,CAAC,CAAnC;AACD;AACF;;AAED,SAASE,uBAAT,CAAiCC,gBAAjC,EAA6E;AAAA;;AAC3E,kCACEA,gBADF,aACEA,gBADF,iDACEA,gBAAgB,CAAEC,GAAlB,CAAsBP,mBAAtB,CADF,2DACE,uBAA4CQ,MAA5C,CAAoDC,GAAD,IAASA,GAAG,GAAG,CAAlE,CADF,yEAC0E,EAD1E;AAGD;;AAEM,SAASC,uBAAT,CAAiCC,OAAjC,EAAuD;AAC5D,QAAMC,aAAa,GAAGP,uBAAuB,CAACM,OAAO,CAACE,MA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KAA/B,EAAsC;AACpC,UAAMC,oBAAoB,GAAG,mDAA7B,CADoC,CAEpC;;AACA,UAAMC,QAAQ,GACZD,oBAAoB,CAACE,KAArB,GAA6B,EAA7B,IAAmCF,oBAAoB,CAACG,KAArB,GAA6B,CAAhE,GACI;AACArC,IAAAA,GAAG,CAACsC,eAAJ,CAAoBC,WAFxB,GAGI;AACAvC,IAAAA,GAAG,CAACwC,mBAAJ,CAAwBD,WAL9B,CAHoC,CASpC;;AACA,QAAIE,QAAQ,GACVC,uBAAWC,2BAAX,CACE3C,GADF,EAEE4C,+BAHJ,CAVoC,CAepC;;;AACA,WAAOH,QAAQ,IAAIA,QAAQ,CAACF,WAAT,KAAyBJ,QAA5C,EAAsD;AACpD;AACA,UAAIM,QAAQ,CAACI,OAAb,EAAsB;AACpB,cAAM,IAAIC,KAAJ,CACJ,mPADI,CAAN;AAGD,OANmD,CAQpD;;;AACAL,MAAAA,QAAQ,GAAGA,QAAQ,CAACM,MAApB;AACD;AACF;AACF;;AAEM,SAASC,cAAT,GAA0B;AAC/B,QAAM,CAACC,WAAD,EAAcC,cAAd,IAAgC,qBAAS,KAAT,CAAtC;AACA,QAAMC,WAAW,GAAG,wBAAY,MAAM;AACpCD,IAAAA,cAAc,CAAC,CAACD,WAAF,CAAd;AACD,GAFmB,EAEjB,CAACA,WAAD,EAAcC,cAAd,CAFiB,CAApB;AAIA,SAAOC,WAAP;AACD;;AAEM,SAASC,mBAAT,GAA+B;AACpC,SAAO,mBAAwB;AAC7BC,IAAAA,qBAAqB,EAAGC,CAAD,IAAyC;AAC9D,gDAAsBA,CAAC,CAACC,WAAxB;AACD,KAH4B;AAI7BC,IAAAA,2BAA2B,EAAE,mEACxBF,CAAD,IAAyC;AACvC,gDAAsBA,CAAC,CAACC,WAAxB;AACD,KAHwB,GAIzB3B;AARyB,GAAxB,CAAP;AAUD","sourcesContent":["import { Platform } from 'react-native';\n\nimport { tagMessage } from '../../../utils';\nimport { GestureRef, BaseGesture, GestureType } from '../gesture';\n\nimport { flingGestureHandlerProps } from '../../FlingGestureHandler';\nimport { forceTouchGestureHandlerProps } from '../../ForceTouchGestureHandler';\nimport { longPressGestureHandlerProps } from '../../LongPressGestureHandler';\nimport {\n panGestureHandlerProps,\n panGestureHandlerCustomNativeProps,\n} from '../../PanGestureHandler';\nimport { tapGestureHandlerProps } from '../../TapGestureHandler';\nimport { hoverGestureHandlerProps } from '../hoverGesture';\nimport { nativeViewGestureHandlerProps } from '../../NativeViewGestureHandler';\nimport {\n HandlerStateChangeEvent,\n baseGestureHandlerWithDetectorProps,\n} from '../../gestureHandlerCommon';\nimport { isNewWebImplementationEnabled } from '../../../EnableNewWebImplementation';\nimport { getReactNativeVersion } from '../../../getReactNativeVersion';\nimport { RNRenderer } from '../../../RNRenderer';\nimport { useCallback, useRef, useState } from 'react';\nimport { Reanimated } from '../reanimatedWrapper';\nimport { onGestureHandlerEvent } from '../eventReceiver';\nimport { WebEventHandler } from './types';\n\nexport const ALLOWED_PROPS = [\n ...baseGestureHandlerWithDetectorProps,\n ...tapGestureHandlerProps,\n ...panGestureHandlerProps,\n ...panGestureHandlerCustomNativeProps,\n ...longPressGestureHandlerProps,\n ...forceTouchGestureHandlerProps,\n ...flingGestureHandlerProps,\n ...hoverGestureHandlerProps,\n ...nativeViewGestureHandlerProps,\n];\n\nfunction convertToHandlerTag(ref: GestureRef): number {\n if (typeof ref === 'number') {\n return ref;\n } else if (ref instanceof BaseGesture) {\n return ref.handlerTag;\n } else {\n // @ts-ignore in this case it should be a ref either to gesture object or\n // a gesture handler component, in both cases handlerTag property exists\n return ref.current?.handlerTag ?? -1;\n }\n}\n\nfunction extractValidHandlerTags(interactionGroup: GestureRef[] | undefined) {\n return (\n interactionGroup?.map(convertToHandlerTag)?.filter((tag) => tag > 0) ?? []\n );\n}\n\nexport function extractGestureRelations(gesture: GestureType) {\n const requireToFail = extractValidHandlerTags(gesture.config.requireToFail);\n const simultaneousWith = extractValidHandlerTags(\n gesture.config.simultaneousWith\n );\n const blocksHandlers = extractValidHandlerTags(gesture.config.blocksHandlers);\n\n return {\n waitFor: requireToFail,\n simultaneousHandlers: simultaneousWith,\n blocksHandlers: blocksHandlers,\n };\n}\n\nexport function checkGestureCallbacksForWorklets(gesture: GestureType) {\n if (!__DEV__) {\n return;\n }\n // if a gesture is explicitly marked to run on the JS thread there is no need to check\n // if callbacks are worklets as the user is aware they will be ran on the JS thread\n if (gesture.config.runOnJS) {\n return;\n }\n\n const areSomeNotWorklets = gesture.handlers.isWorklet.includes(false);\n const areSomeWorklets = gesture.handlers.isWorklet.includes(true);\n\n // if some of the callbacks are worklets and some are not, and the gesture is not\n // explicitly marked with `.runOnJS(true)` show an error\n if (areSomeNotWorklets && areSomeWorklets) {\n console.error(\n tagMessage(\n `Some of the callbacks in the gesture are worklets and some are not. Either make sure that all calbacks are marked as 'worklet' if you wish to run them on the UI thread or use '.runOnJS(true)' modifier on the gesture explicitly to run all callbacks on the JS thread.`\n )\n );\n }\n\n if (Reanimated === undefined) {\n // if Reanimated is not available, we can't run worklets, so we shouldn't show the warning\n return;\n }\n\n const areAllNotWorklets = !areSomeWorklets && areSomeNotWorklets;\n // if none of the callbacks are worklets and the gesture is not explicitly marked with\n // `.runOnJS(true)` show a warning\n if (areAllNotWorklets) {\n console.warn(\n tagMessage(\n `None of the callbacks in the gesture are worklets. If you wish to run them on the JS thread use '.runOnJS(true)' modifier on the gesture to make this explicit. Otherwise, mark the callbacks as 'worklet' to run them on the UI thread.`\n )\n );\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function validateDetectorChildren(ref: any) {\n // finds the first native view under the Wrap component and traverses the fiber tree upwards\n // to check whether there is more than one native view as a pseudo-direct child of GestureDetector\n // i.e. this is not ok:\n // Wrap\n // |\n // / \\\n // / \\\n // / \\\n // / \\\n // NativeView NativeView\n //\n // but this is fine:\n // Wrap\n // |\n // NativeView\n // |\n // / \\\n // / \\\n // / \\\n // / \\\n // NativeView NativeView\n if (__DEV__ && Platform.OS !== 'web') {\n const REACT_NATIVE_VERSION = getReactNativeVersion();\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const wrapType =\n REACT_NATIVE_VERSION.minor > 63 || REACT_NATIVE_VERSION.major > 0\n ? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n ref._reactInternals.elementType\n : // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n ref._reactInternalFiber.elementType;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n let instance =\n RNRenderer.findHostInstance_DEPRECATED(\n ref\n )._internalFiberInstanceHandleDEV;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n while (instance && instance.elementType !== wrapType) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (instance.sibling) {\n throw new Error(\n 'GestureDetector has more than one native view as its children. This can happen if you are using a custom component that renders multiple views, like React.Fragment. You should wrap content of GestureDetector with a <View> or <Animated.View>.'\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n instance = instance.return;\n }\n }\n}\n\nexport function useForceRender() {\n const [renderState, setRenderState] = useState(false);\n const forceRender = useCallback(() => {\n setRenderState(!renderState);\n }, [renderState, setRenderState]);\n\n return forceRender;\n}\n\nexport function useWebEventHandlers() {\n return useRef<WebEventHandler>({\n onGestureHandlerEvent: (e: HandlerStateChangeEvent<unknown>) => {\n onGestureHandlerEvent(e.nativeEvent);\n },\n onGestureHandlerStateChange: isNewWebImplementationEnabled()\n ? (e: HandlerStateChangeEvent<unknown>) => {\n onGestureHandlerEvent(e.nativeEvent);\n }\n : undefined,\n });\n}\n"]}
|