react-native-gesture-handler 2.16.1 → 2.17.0
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 +105 -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/RNGestureHandlerModule.js +4 -97
- package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/RNGestureHandlerModule.web.js +109 -0
- package/lib/commonjs/RNGestureHandlerModule.web.js.map +1 -0
- package/lib/commonjs/RNRenderer.js +10 -5
- package/lib/commonjs/RNRenderer.js.map +1 -1
- package/lib/commonjs/RNRenderer.web.js +11 -0
- package/lib/commonjs/RNRenderer.web.js.map +1 -0
- package/lib/commonjs/components/GestureButtons.js +27 -12
- package/lib/commonjs/components/GestureButtons.js.map +1 -1
- package/lib/commonjs/components/GestureComponents.js +82 -19
- package/lib/commonjs/components/GestureComponents.js.map +1 -1
- package/lib/commonjs/components/GestureComponents.web.js +52 -0
- package/lib/commonjs/components/GestureComponents.web.js.map +1 -0
- package/lib/commonjs/components/GestureHandlerButton.js +3 -13
- package/lib/commonjs/components/GestureHandlerButton.js.map +1 -1
- package/lib/commonjs/components/GestureHandlerButton.web.js +24 -0
- package/lib/commonjs/components/GestureHandlerButton.web.js.map +1 -0
- package/lib/commonjs/components/GestureHandlerRootView.js +6 -0
- package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
- package/lib/commonjs/components/{GestureHandlerRootView.native.js → GestureHandlerRootView.web.js} +1 -7
- package/lib/commonjs/components/GestureHandlerRootView.web.js.map +1 -0
- package/lib/commonjs/getReactNativeVersion.js +12 -1
- package/lib/commonjs/getReactNativeVersion.js.map +1 -1
- package/lib/commonjs/getReactNativeVersion.web.js +11 -0
- package/lib/commonjs/getReactNativeVersion.web.js.map +1 -0
- package/lib/commonjs/getShadowNodeFromRef.js +34 -5
- package/lib/commonjs/getShadowNodeFromRef.js.map +1 -1
- package/lib/commonjs/getShadowNodeFromRef.web.js +15 -0
- package/lib/commonjs/getShadowNodeFromRef.web.js.map +1 -0
- package/lib/commonjs/handlers/PressabilityDebugView.js +7 -5
- package/lib/commonjs/handlers/PressabilityDebugView.js.map +1 -1
- package/lib/commonjs/handlers/PressabilityDebugView.web.js +12 -0
- package/lib/commonjs/handlers/PressabilityDebugView.web.js.map +1 -0
- package/lib/commonjs/handlers/createHandler.js +1 -3
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/handlers/customDirectEventTypes.js +8 -5
- package/lib/commonjs/handlers/customDirectEventTypes.js.map +1 -1
- package/lib/commonjs/handlers/customDirectEventTypes.web.js +11 -0
- package/lib/commonjs/handlers/customDirectEventTypes.web.js.map +1 -0
- 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/RNGestureHandlerModule.js +4 -84
- package/lib/module/RNGestureHandlerModule.js.map +1 -1
- package/lib/module/RNGestureHandlerModule.web.js +85 -0
- package/lib/module/RNGestureHandlerModule.web.js.map +1 -0
- package/lib/module/RNRenderer.js +3 -3
- package/lib/module/RNRenderer.js.map +1 -1
- package/lib/module/RNRenderer.web.js +4 -0
- package/lib/module/RNRenderer.web.js.map +1 -0
- package/lib/module/components/GestureButtons.js +24 -6
- package/lib/module/components/GestureButtons.js.map +1 -1
- package/lib/module/components/GestureComponents.js +80 -18
- package/lib/module/components/GestureComponents.js.map +1 -1
- package/lib/module/components/GestureComponents.web.js +28 -0
- package/lib/module/components/GestureComponents.web.js.map +1 -0
- package/lib/module/components/GestureHandlerButton.js +2 -8
- package/lib/module/components/GestureHandlerButton.js.map +1 -1
- package/lib/module/components/GestureHandlerButton.web.js +9 -0
- package/lib/module/components/GestureHandlerButton.web.js.map +1 -0
- package/lib/module/components/GestureHandlerRootView.js +5 -0
- package/lib/module/components/GestureHandlerRootView.js.map +1 -1
- package/lib/module/components/{GestureHandlerRootView.native.js → GestureHandlerRootView.web.js} +1 -6
- package/lib/module/components/GestureHandlerRootView.web.js.map +1 -0
- package/lib/module/getReactNativeVersion.js +7 -1
- package/lib/module/getReactNativeVersion.js.map +1 -1
- package/lib/module/getReactNativeVersion.web.js +4 -0
- package/lib/module/getReactNativeVersion.web.js.map +1 -0
- package/lib/module/getShadowNodeFromRef.js +33 -4
- package/lib/module/getShadowNodeFromRef.js.map +1 -1
- package/lib/module/getShadowNodeFromRef.web.js +8 -0
- package/lib/module/getShadowNodeFromRef.web.js.map +1 -0
- package/lib/module/handlers/PressabilityDebugView.js +2 -4
- package/lib/module/handlers/PressabilityDebugView.js.map +1 -1
- package/lib/module/handlers/PressabilityDebugView.web.js +5 -0
- package/lib/module/handlers/PressabilityDebugView.web.js.map +1 -0
- package/lib/module/handlers/createHandler.js +2 -4
- package/lib/module/handlers/createHandler.js.map +1 -1
- package/lib/module/handlers/customDirectEventTypes.js +2 -4
- package/lib/module/handlers/customDirectEventTypes.js.map +1 -1
- package/lib/module/handlers/customDirectEventTypes.web.js +5 -0
- package/lib/module/handlers/customDirectEventTypes.web.js.map +1 -0
- 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/RNGestureHandlerModule.d.ts +2 -15
- package/lib/typescript/RNGestureHandlerModule.web.d.ts +15 -0
- package/lib/typescript/RNRenderer.d.ts +1 -3
- package/lib/typescript/RNRenderer.web.d.ts +3 -0
- package/lib/typescript/components/GestureButtons.d.ts +3 -34
- package/lib/typescript/components/GestureComponents.d.ts +21 -7
- package/lib/typescript/components/GestureComponents.web.d.ts +8 -0
- package/lib/typescript/components/GestureHandlerButton.d.ts +3 -3
- package/lib/typescript/components/GestureHandlerButton.web.d.ts +4 -0
- package/lib/typescript/getReactNativeVersion.d.ts +4 -1
- package/lib/typescript/getReactNativeVersion.web.d.ts +1 -0
- package/lib/typescript/getShadowNodeFromRef.d.ts +1 -1
- package/lib/typescript/getShadowNodeFromRef.web.d.ts +1 -0
- package/lib/typescript/handlers/PressabilityDebugView.d.ts +1 -1
- package/lib/typescript/handlers/PressabilityDebugView.web.d.ts +1 -0
- package/lib/typescript/handlers/customDirectEventTypes.d.ts +1 -2
- package/lib/typescript/handlers/customDirectEventTypes.web.d.ts +2 -0
- 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/RNGestureHandlerModule.ts +4 -104
- package/src/RNGestureHandlerModule.web.ts +105 -0
- package/src/RNRenderer.ts +3 -3
- package/src/RNRenderer.web.ts +3 -0
- package/src/components/GestureButtons.tsx +36 -4
- package/src/components/GestureComponents.tsx +131 -24
- package/src/components/GestureComponents.web.tsx +41 -0
- package/src/components/GestureHandlerButton.tsx +4 -5
- package/src/components/GestureHandlerButton.web.tsx +6 -0
- package/src/components/GestureHandlerRootView.tsx +6 -0
- package/src/components/{GestureHandlerRootView.native.tsx → GestureHandlerRootView.web.tsx} +0 -6
- package/src/getReactNativeVersion.ts +9 -1
- package/src/getReactNativeVersion.web.ts +3 -0
- package/src/getShadowNodeFromRef.ts +41 -4
- package/src/getShadowNodeFromRef.web.ts +7 -0
- package/src/handlers/PressabilityDebugView.tsx +2 -4
- package/src/handlers/PressabilityDebugView.web.tsx +4 -0
- package/src/handlers/createHandler.tsx +1 -3
- package/src/handlers/customDirectEventTypes.ts +2 -5
- package/src/handlers/customDirectEventTypes.web.ts +5 -0
- 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/RNGestureHandlerModule.native.js +0 -16
- package/lib/commonjs/RNGestureHandlerModule.native.js.map +0 -1
- package/lib/commonjs/RNRenderer.native.js +0 -16
- package/lib/commonjs/RNRenderer.native.js.map +0 -1
- package/lib/commonjs/components/GestureComponents.native.js +0 -115
- package/lib/commonjs/components/GestureComponents.native.js.map +0 -1
- package/lib/commonjs/components/GestureHandlerButton.native.js +0 -14
- package/lib/commonjs/components/GestureHandlerButton.native.js.map +0 -1
- package/lib/commonjs/components/GestureHandlerRootView.native.js.map +0 -1
- package/lib/commonjs/getReactNativeVersion.native.js +0 -22
- package/lib/commonjs/getReactNativeVersion.native.js.map +0 -1
- package/lib/commonjs/getShadowNodeFromRef.native.js +0 -44
- package/lib/commonjs/getShadowNodeFromRef.native.js.map +0 -1
- package/lib/commonjs/handlers/PressabilityDebugView.native.js +0 -14
- package/lib/commonjs/handlers/PressabilityDebugView.native.js.map +0 -1
- package/lib/commonjs/handlers/customDirectEventTypes.native.js +0 -14
- package/lib/commonjs/handlers/customDirectEventTypes.native.js.map +0 -1
- package/lib/commonjs/handlers/gestures/GestureDetector.js +0 -704
- package/lib/commonjs/handlers/gestures/GestureDetector.js.map +0 -1
- package/lib/module/RNGestureHandlerModule.native.js +0 -5
- package/lib/module/RNGestureHandlerModule.native.js.map +0 -1
- package/lib/module/RNRenderer.native.js +0 -4
- package/lib/module/RNRenderer.native.js.map +0 -1
- package/lib/module/components/GestureComponents.native.js +0 -90
- package/lib/module/components/GestureComponents.native.js.map +0 -1
- package/lib/module/components/GestureHandlerButton.native.js +0 -3
- package/lib/module/components/GestureHandlerButton.native.js.map +0 -1
- package/lib/module/components/GestureHandlerRootView.native.js.map +0 -1
- package/lib/module/getReactNativeVersion.native.js +0 -10
- package/lib/module/getReactNativeVersion.native.js.map +0 -1
- package/lib/module/getShadowNodeFromRef.native.js +0 -37
- package/lib/module/getShadowNodeFromRef.native.js.map +0 -1
- package/lib/module/handlers/PressabilityDebugView.native.js +0 -3
- package/lib/module/handlers/PressabilityDebugView.native.js.map +0 -1
- package/lib/module/handlers/customDirectEventTypes.native.js +0 -3
- package/lib/module/handlers/customDirectEventTypes.native.js.map +0 -1
- package/lib/module/handlers/gestures/GestureDetector.js +0 -654
- package/lib/module/handlers/gestures/GestureDetector.js.map +0 -1
- package/lib/typescript/RNGestureHandlerModule.native.d.ts +0 -2
- package/lib/typescript/RNRenderer.native.d.ts +0 -1
- package/lib/typescript/components/GestureComponents.native.d.ts +0 -22
- package/lib/typescript/components/GestureHandlerButton.native.d.ts +0 -4
- package/lib/typescript/getReactNativeVersion.native.d.ts +0 -4
- package/lib/typescript/getShadowNodeFromRef.native.d.ts +0 -1
- package/lib/typescript/handlers/PressabilityDebugView.native.d.ts +0 -1
- package/lib/typescript/handlers/customDirectEventTypes.native.d.ts +0 -1
- package/src/RNGestureHandlerModule.native.ts +0 -5
- package/src/RNRenderer.native.ts +0 -3
- package/src/components/GestureComponents.native.tsx +0 -148
- package/src/components/GestureHandlerButton.native.tsx +0 -5
- package/src/getReactNativeVersion.native.ts +0 -11
- package/src/getShadowNodeFromRef.native.ts +0 -44
- package/src/handlers/PressabilityDebugView.native.tsx +0 -2
- package/src/handlers/customDirectEventTypes.native.ts +0 -2
- package/src/handlers/gestures/GestureDetector.tsx +0 -894
- /package/lib/typescript/components/{GestureHandlerRootView.native.d.ts → GestureHandlerRootView.web.d.ts} +0 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
var _Reanimated$default$c, _Reanimated$default;
|
2
|
+
|
3
|
+
import React from 'react';
|
4
|
+
import { Reanimated } from '../reanimatedWrapper';
|
5
|
+
import { tagMessage } from '../../../utils';
|
6
|
+
export class Wrap extends React.Component {
|
7
|
+
render() {
|
8
|
+
try {
|
9
|
+
// I don't think that fighting with types over such a simple function is worth it
|
10
|
+
// The only thing it does is add 'collapsable: false' to the child component
|
11
|
+
// to make sure it is in the native view hierarchy so the detector can find
|
12
|
+
// correct viewTag to attach to.
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
14
|
+
const child = React.Children.only(this.props.children);
|
15
|
+
return /*#__PURE__*/React.cloneElement(child, {
|
16
|
+
collapsable: false
|
17
|
+
}, // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
18
|
+
child.props.children);
|
19
|
+
} catch (e) {
|
20
|
+
throw new Error(tagMessage(`GestureDetector got more than one view as a child. If you want the gesture to work on multiple views, wrap them with a common parent and attach the gesture to that view.`));
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
}
|
25
|
+
export const AnimatedWrap = (_Reanimated$default$c = Reanimated === null || Reanimated === void 0 ? void 0 : (_Reanimated$default = Reanimated.default) === null || _Reanimated$default === void 0 ? void 0 : _Reanimated$default.createAnimatedComponent(Wrap)) !== null && _Reanimated$default$c !== void 0 ? _Reanimated$default$c : Wrap;
|
26
|
+
//# sourceMappingURL=Wrap.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["Wrap.tsx"],"names":["React","Reanimated","tagMessage","Wrap","Component","render","child","Children","only","props","children","cloneElement","collapsable","e","Error","AnimatedWrap","default","createAnimatedComponent"],"mappings":";;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,UAAT,QAA2B,sBAA3B;AACA,SAASC,UAAT,QAA2B,gBAA3B;AAEA,OAAO,MAAMC,IAAN,SAAmBH,KAAK,CAACI,SAAzB,CAIJ;AACDC,EAAAA,MAAM,GAAG;AACP,QAAI;AACF;AACA;AACA;AACA;AACA;AACA,YAAMC,KAAU,GAAGN,KAAK,CAACO,QAAN,CAAeC,IAAf,CAAoB,KAAKC,KAAL,CAAWC,QAA/B,CAAnB;AACA,0BAAOV,KAAK,CAACW,YAAN,CACLL,KADK,EAEL;AAAEM,QAAAA,WAAW,EAAE;AAAf,OAFK,EAGL;AACAN,MAAAA,KAAK,CAACG,KAAN,CAAYC,QAJP,CAAP;AAMD,KAbD,CAaE,OAAOG,CAAP,EAAU;AACV,YAAM,IAAIC,KAAJ,CACJZ,UAAU,CACP,2KADO,CADN,CAAN;AAKD;AACF;;AAtBA;AAyBH,OAAO,MAAMa,YAAY,4BACvBd,UADuB,aACvBA,UADuB,8CACvBA,UAAU,CAAEe,OADW,wDACvB,oBAAqBC,uBAArB,CAA6Cd,IAA7C,CADuB,yEAC+BA,IADjD","sourcesContent":["import React from 'react';\nimport { Reanimated } from '../reanimatedWrapper';\nimport { tagMessage } from '../../../utils';\n\nexport class Wrap extends React.Component<{\n onGestureHandlerEvent?: unknown;\n // implicit `children` prop has been removed in @types/react^18.0.0\n children?: React.ReactNode;\n}> {\n render() {\n try {\n // I don't think that fighting with types over such a simple function is worth it\n // The only thing it does is add 'collapsable: false' to the child component\n // to make sure it is in the native view hierarchy so the detector can find\n // correct viewTag to attach to.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const child: any = React.Children.only(this.props.children);\n return React.cloneElement(\n child,\n { collapsable: false },\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n child.props.children\n );\n } catch (e) {\n throw new Error(\n tagMessage(\n `GestureDetector got more than one view as a child. If you want the gesture to work on multiple views, wrap them with a common parent and attach the gesture to that view.`\n )\n );\n }\n }\n}\n\nexport const AnimatedWrap =\n Reanimated?.default?.createAnimatedComponent(Wrap) ?? Wrap;\n"]}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import { registerHandler } from '../../handlersRegistry';
|
2
|
+
import RNGestureHandlerModule from '../../../RNGestureHandlerModule';
|
3
|
+
import { filterConfig, scheduleFlushOperations } from '../../gestureHandlerCommon';
|
4
|
+
import { ActionType } from '../../../ActionType';
|
5
|
+
import { Platform } from 'react-native';
|
6
|
+
import { ghQueueMicrotask } from '../../../ghQueueMicrotask';
|
7
|
+
import { extractGestureRelations, checkGestureCallbacksForWorklets, ALLOWED_PROPS } from './utils';
|
8
|
+
export function attachHandlers({
|
9
|
+
preparedGesture,
|
10
|
+
gestureConfig,
|
11
|
+
gesturesToAttach,
|
12
|
+
viewTag,
|
13
|
+
webEventHandlersRef
|
14
|
+
}) {
|
15
|
+
gestureConfig.initialize(); // use queueMicrotask to extract handlerTags, because all refs should be initialized
|
16
|
+
// when it's ran
|
17
|
+
|
18
|
+
ghQueueMicrotask(() => {
|
19
|
+
if (!preparedGesture.isMounted) {
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
|
23
|
+
gestureConfig.prepare();
|
24
|
+
});
|
25
|
+
|
26
|
+
for (const handler of gesturesToAttach) {
|
27
|
+
checkGestureCallbacksForWorklets(handler);
|
28
|
+
RNGestureHandlerModule.createGestureHandler(handler.handlerName, handler.handlerTag, filterConfig(handler.config, ALLOWED_PROPS));
|
29
|
+
registerHandler(handler.handlerTag, handler, handler.config.testId);
|
30
|
+
} // use queueMicrotask to extract handlerTags, because all refs should be initialized
|
31
|
+
// when it's ran
|
32
|
+
|
33
|
+
|
34
|
+
ghQueueMicrotask(() => {
|
35
|
+
if (!preparedGesture.isMounted) {
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
|
39
|
+
for (const handler of gesturesToAttach) {
|
40
|
+
RNGestureHandlerModule.updateGestureHandler(handler.handlerTag, filterConfig(handler.config, ALLOWED_PROPS, extractGestureRelations(handler)));
|
41
|
+
}
|
42
|
+
|
43
|
+
scheduleFlushOperations();
|
44
|
+
});
|
45
|
+
|
46
|
+
for (const gesture of gesturesToAttach) {
|
47
|
+
const actionType = gesture.shouldUseReanimated ? ActionType.REANIMATED_WORKLET : ActionType.JS_FUNCTION_NEW_API;
|
48
|
+
|
49
|
+
if (Platform.OS === 'web') {
|
50
|
+
RNGestureHandlerModule.attachGestureHandler(gesture.handlerTag, viewTag, ActionType.JS_FUNCTION_OLD_API, // ignored on web
|
51
|
+
webEventHandlersRef);
|
52
|
+
} else {
|
53
|
+
RNGestureHandlerModule.attachGestureHandler(gesture.handlerTag, viewTag, actionType);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
preparedGesture.attachedGestures = gesturesToAttach;
|
58
|
+
|
59
|
+
if (preparedGesture.animatedHandlers) {
|
60
|
+
const isAnimatedGesture = g => g.shouldUseReanimated;
|
61
|
+
|
62
|
+
preparedGesture.animatedHandlers.value = gesturesToAttach.filter(isAnimatedGesture).map(g => g.handlers);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
//# sourceMappingURL=attachHandlers.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["attachHandlers.ts"],"names":["registerHandler","RNGestureHandlerModule","filterConfig","scheduleFlushOperations","ActionType","Platform","ghQueueMicrotask","extractGestureRelations","checkGestureCallbacksForWorklets","ALLOWED_PROPS","attachHandlers","preparedGesture","gestureConfig","gesturesToAttach","viewTag","webEventHandlersRef","initialize","isMounted","prepare","handler","createGestureHandler","handlerName","handlerTag","config","testId","updateGestureHandler","gesture","actionType","shouldUseReanimated","REANIMATED_WORKLET","JS_FUNCTION_NEW_API","OS","attachGestureHandler","JS_FUNCTION_OLD_API","attachedGestures","animatedHandlers","isAnimatedGesture","g","value","filter","map","handlers"],"mappings":"AAEA,SAASA,eAAT,QAAgC,wBAAhC;AACA,OAAOC,sBAAP,MAAmC,iCAAnC;AACA,SACEC,YADF,EAEEC,uBAFF,QAGO,4BAHP;AAKA,SAASC,UAAT,QAA2B,qBAA3B;AACA,SAASC,QAAT,QAAyB,cAAzB;AAEA,SAASC,gBAAT,QAAiC,2BAAjC;AAEA,SACEC,uBADF,EAEEC,gCAFF,EAGEC,aAHF,QAIO,SAJP;AAcA,OAAO,SAASC,cAAT,CAAwB;AAC7BC,EAAAA,eAD6B;AAE7BC,EAAAA,aAF6B;AAG7BC,EAAAA,gBAH6B;AAI7BC,EAAAA,OAJ6B;AAK7BC,EAAAA;AAL6B,CAAxB,EAMkB;AACvBH,EAAAA,aAAa,CAACI,UAAd,GADuB,CAGvB;AACA;;AACAV,EAAAA,gBAAgB,CAAC,MAAM;AACrB,QAAI,CAACK,eAAe,CAACM,SAArB,EAAgC;AAC9B;AACD;;AACDL,IAAAA,aAAa,CAACM,OAAd;AACD,GALe,CAAhB;;AAOA,OAAK,MAAMC,OAAX,IAAsBN,gBAAtB,EAAwC;AACtCL,IAAAA,gCAAgC,CAACW,OAAD,CAAhC;AACAlB,IAAAA,sBAAsB,CAACmB,oBAAvB,CACED,OA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,gBAAhB,CAAiCG,KAAjC,GAAyCzB,gBAAgB,CACtD0B,MADsC,CAC/BH,iBAD+B,EAEtCI,GAFsC,CAEjCH,CAAD,IAAOA,CAAC,CAACI,QAFyB,CAAzC;AAKD;AACF","sourcesContent":["import React from 'react';\nimport { 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 { ActionType } from '../../../ActionType';\nimport { Platform } from 'react-native';\nimport type RNGestureHandlerModuleWeb from '../../../RNGestureHandlerModule.web';\nimport { ghQueueMicrotask } from '../../../ghQueueMicrotask';\nimport { AttachedGestureState, WebEventHandler } from './types';\nimport {\n extractGestureRelations,\n checkGestureCallbacksForWorklets,\n ALLOWED_PROPS,\n} from './utils';\n\ninterface AttachHandlersConfig {\n preparedGesture: AttachedGestureState;\n gestureConfig: ComposedGesture | GestureType;\n gesturesToAttach: GestureType[];\n viewTag: number;\n webEventHandlersRef: React.RefObject<WebEventHandler>;\n}\n\nexport function attachHandlers({\n preparedGesture,\n gestureConfig,\n gesturesToAttach,\n viewTag,\n webEventHandlersRef,\n}: AttachHandlersConfig) {\n gestureConfig.initialize();\n\n // use queueMicrotask to extract handlerTags, because all refs should be initialized\n // when it's ran\n ghQueueMicrotask(() => {\n if (!preparedGesture.isMounted) {\n return;\n }\n gestureConfig.prepare();\n });\n\n for (const handler of gesturesToAttach) {\n checkGestureCallbacksForWorklets(handler);\n RNGestureHandlerModule.createGestureHandler(\n handler.handlerName,\n handler.handlerTag,\n filterConfig(handler.config, ALLOWED_PROPS)\n );\n\n registerHandler(handler.handlerTag, handler, handler.config.testId);\n }\n\n // use queueMicrotask to extract handlerTags, because all refs should be initialized\n // when it's ran\n ghQueueMicrotask(() => {\n if (!preparedGesture.isMounted) {\n return;\n }\n for (const handler of gesturesToAttach) {\n RNGestureHandlerModule.updateGestureHandler(\n handler.handlerTag,\n filterConfig(\n handler.config,\n ALLOWED_PROPS,\n extractGestureRelations(handler)\n )\n );\n }\n\n scheduleFlushOperations();\n });\n\n for (const gesture of gesturesToAttach) {\n const actionType = gesture.shouldUseReanimated\n ? ActionType.REANIMATED_WORKLET\n : ActionType.JS_FUNCTION_NEW_API;\n\n if (Platform.OS === 'web') {\n (\n RNGestureHandlerModule.attachGestureHandler as typeof RNGestureHandlerModuleWeb.attachGestureHandler\n )(\n gesture.handlerTag,\n viewTag,\n ActionType.JS_FUNCTION_OLD_API, // ignored on web\n webEventHandlersRef\n );\n } else {\n RNGestureHandlerModule.attachGestureHandler(\n gesture.handlerTag,\n viewTag,\n actionType\n );\n }\n }\n\n preparedGesture.attachedGestures = gesturesToAttach;\n\n if (preparedGesture.animatedHandlers) {\n const isAnimatedGesture = (g: GestureType) => g.shouldUseReanimated;\n\n preparedGesture.animatedHandlers.value = gesturesToAttach\n .filter(isAnimatedGesture)\n .map((g) => g.handlers) as unknown as HandlerCallbacks<\n Record<string, unknown>\n >[];\n }\n}\n"]}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { unregisterHandler } from '../../handlersRegistry';
|
2
|
+
import RNGestureHandlerModule from '../../../RNGestureHandlerModule';
|
3
|
+
import { scheduleFlushOperations } from '../../gestureHandlerCommon';
|
4
|
+
export function dropHandlers(preparedGesture) {
|
5
|
+
for (const handler of preparedGesture.attachedGestures) {
|
6
|
+
RNGestureHandlerModule.dropGestureHandler(handler.handlerTag);
|
7
|
+
unregisterHandler(handler.handlerTag, handler.config.testId);
|
8
|
+
}
|
9
|
+
|
10
|
+
scheduleFlushOperations();
|
11
|
+
}
|
12
|
+
//# sourceMappingURL=dropHandlers.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["dropHandlers.ts"],"names":["unregisterHandler","RNGestureHandlerModule","scheduleFlushOperations","dropHandlers","preparedGesture","handler","attachedGestures","dropGestureHandler","handlerTag","config","testId"],"mappings":"AAAA,SAASA,iBAAT,QAAkC,wBAAlC;AACA,OAAOC,sBAAP,MAAmC,iCAAnC;AACA,SAASC,uBAAT,QAAwC,4BAAxC;AAGA,OAAO,SAASC,YAAT,CAAsBC,eAAtB,EAA6D;AAClE,OAAK,MAAMC,OAAX,IAAsBD,eAAe,CAACE,gBAAtC,EAAwD;AACtDL,IAAAA,sBAAsB,CAACM,kBAAvB,CAA0CF,OAAO,CAACG,UAAlD;AAEAR,IAAAA,iBAAiB,CAACK,OAAO,CAACG,UAAT,EAAqBH,OAAO,CAACI,MAAR,CAAeC,MAApC,CAAjB;AACD;;AAEDR,EAAAA,uBAAuB;AACxB","sourcesContent":["import { unregisterHandler } from '../../handlersRegistry';\nimport RNGestureHandlerModule from '../../../RNGestureHandlerModule';\nimport { scheduleFlushOperations } from '../../gestureHandlerCommon';\nimport { AttachedGestureState } from './types';\n\nexport function dropHandlers(preparedGesture: AttachedGestureState) {\n for (const handler of preparedGesture.attachedGestures) {\n RNGestureHandlerModule.dropGestureHandler(handler.handlerTag);\n\n unregisterHandler(handler.handlerTag, handler.config.testId);\n }\n\n scheduleFlushOperations();\n}\n"]}
|
@@ -0,0 +1,115 @@
|
|
1
|
+
/* eslint-disable react/no-unused-prop-types */
|
2
|
+
import React, { useContext, useEffect, useLayoutEffect, useMemo, useRef } from 'react';
|
3
|
+
import { Platform, findNodeHandle } from 'react-native';
|
4
|
+
import { isJestEnv } from '../../../utils';
|
5
|
+
import GestureHandlerRootViewContext from '../../../GestureHandlerRootViewContext';
|
6
|
+
import { useAnimatedGesture } from './useAnimatedGesture';
|
7
|
+
import { attachHandlers } from './attachHandlers';
|
8
|
+
import { needsToReattach } from './needsToReattach';
|
9
|
+
import { dropHandlers } from './dropHandlers';
|
10
|
+
import { useWebEventHandlers } from './utils';
|
11
|
+
import { Wrap, AnimatedWrap } from './Wrap';
|
12
|
+
import { useDetectorUpdater } from './useDetectorUpdater';
|
13
|
+
import { useViewRefHandler } from './useViewRefHandler';
|
14
|
+
|
15
|
+
function propagateDetectorConfig(props, gesture) {
|
16
|
+
const keysToPropagate = ['userSelect', 'enableContextMenu', 'touchAction'];
|
17
|
+
|
18
|
+
for (const key of keysToPropagate) {
|
19
|
+
const value = props[key];
|
20
|
+
|
21
|
+
if (value === undefined) {
|
22
|
+
continue;
|
23
|
+
}
|
24
|
+
|
25
|
+
for (const g of gesture.toGestureArray()) {
|
26
|
+
const config = g.config;
|
27
|
+
config[key] = value;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
/**
|
33
|
+
* `GestureDetector` is responsible for creating and updating native gesture handlers based on the config of provided gesture.
|
34
|
+
*
|
35
|
+
* ### Props
|
36
|
+
* - `gesture`
|
37
|
+
* - `userSelect` (**Web only**)
|
38
|
+
* - `enableContextMenu` (**Web only**)
|
39
|
+
* - `touchAction` (**Web only**)
|
40
|
+
*
|
41
|
+
* ### Remarks
|
42
|
+
* - Gesture Detector will use first native view in its subtree to recognize gestures, however if this view is used only to group its children it may get automatically collapsed.
|
43
|
+
* - Using the same instance of a gesture across multiple Gesture Detectors is not possible.
|
44
|
+
*
|
45
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/gesture-detector
|
46
|
+
*/
|
47
|
+
export const GestureDetector = props => {
|
48
|
+
const rootViewContext = useContext(GestureHandlerRootViewContext);
|
49
|
+
|
50
|
+
if (__DEV__ && !rootViewContext && !isJestEnv() && Platform.OS !== 'web') {
|
51
|
+
throw new Error('GestureDetector must be used as a descendant of GestureHandlerRootView. Otherwise the gestures will not be recognized. See https://docs.swmansion.com/react-native-gesture-handler/docs/installation for more details.');
|
52
|
+
} // Gesture config should be wrapped with useMemo to prevent unnecessary re-renders
|
53
|
+
|
54
|
+
|
55
|
+
const gestureConfig = props.gesture;
|
56
|
+
propagateDetectorConfig(props, gestureConfig);
|
57
|
+
const gesturesToAttach = useMemo(() => gestureConfig.toGestureArray(), [gestureConfig]);
|
58
|
+
const shouldUseReanimated = gesturesToAttach.some(g => g.shouldUseReanimated);
|
59
|
+
const webEventHandlersRef = useWebEventHandlers(); // store state in ref to prevent unnecessary renders
|
60
|
+
|
61
|
+
const state = useRef({
|
62
|
+
firstRender: true,
|
63
|
+
viewRef: null,
|
64
|
+
previousViewTag: -1,
|
65
|
+
forceRebuildReanimatedEvent: false
|
66
|
+
}).current;
|
67
|
+
const preparedGesture = React.useRef({
|
68
|
+
attachedGestures: [],
|
69
|
+
animatedEventHandler: null,
|
70
|
+
animatedHandlers: null,
|
71
|
+
shouldUseReanimated: shouldUseReanimated,
|
72
|
+
isMounted: false
|
73
|
+
}).current;
|
74
|
+
const updateAttachedGestures = useDetectorUpdater(state, preparedGesture, gesturesToAttach, gestureConfig, webEventHandlersRef);
|
75
|
+
const refHandler = useViewRefHandler(state, updateAttachedGestures); // Reanimated event should be rebuilt only when gestures are reattached, otherwise
|
76
|
+
// config update will be enough as all necessary items are stored in shared values anyway
|
77
|
+
|
78
|
+
const needsToRebuildReanimatedEvent = state.firstRender || state.forceRebuildReanimatedEvent || needsToReattach(preparedGesture, gesturesToAttach);
|
79
|
+
state.forceRebuildReanimatedEvent = false;
|
80
|
+
useAnimatedGesture(preparedGesture, needsToRebuildReanimatedEvent);
|
81
|
+
useLayoutEffect(() => {
|
82
|
+
const viewTag = findNodeHandle(state.viewRef);
|
83
|
+
preparedGesture.isMounted = true;
|
84
|
+
attachHandlers({
|
85
|
+
preparedGesture,
|
86
|
+
gestureConfig,
|
87
|
+
gesturesToAttach,
|
88
|
+
webEventHandlersRef,
|
89
|
+
viewTag
|
90
|
+
});
|
91
|
+
return () => {
|
92
|
+
preparedGesture.isMounted = false;
|
93
|
+
dropHandlers(preparedGesture);
|
94
|
+
};
|
95
|
+
}, []);
|
96
|
+
useEffect(() => {
|
97
|
+
if (state.firstRender) {
|
98
|
+
state.firstRender = false;
|
99
|
+
} else {
|
100
|
+
updateAttachedGestures();
|
101
|
+
}
|
102
|
+
}, [props]);
|
103
|
+
|
104
|
+
if (shouldUseReanimated) {
|
105
|
+
return /*#__PURE__*/React.createElement(AnimatedWrap, {
|
106
|
+
ref: refHandler,
|
107
|
+
onGestureHandlerEvent: preparedGesture.animatedEventHandler
|
108
|
+
}, props.children);
|
109
|
+
} else {
|
110
|
+
return /*#__PURE__*/React.createElement(Wrap, {
|
111
|
+
ref: refHandler
|
112
|
+
}, props.children);
|
113
|
+
}
|
114
|
+
};
|
115
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["React","useContext","useEffect","useLayoutEffect","useMemo","useRef","Platform","findNodeHandle","isJestEnv","GestureHandlerRootViewContext","useAnimatedGesture","attachHandlers","needsToReattach","dropHandlers","useWebEventHandlers","Wrap","AnimatedWrap","useDetectorUpdater","useViewRefHandler","propagateDetectorConfig","props","gesture","keysToPropagate","key","value","undefined","g","toGestureArray","config","GestureDetector","rootViewContext","__DEV__","OS","Error","gestureConfig","gesturesToAttach","shouldUseReanimated","some","webEventHandlersRef","state","firstRender","viewRef","previousViewTag","forceRebuildReanimatedEvent","current","preparedGesture","attachedGestures","animatedEventHandler","animatedHandlers","isMounted","updateAttachedGestures","refHandler","needsToRebuildReanimatedEvent","viewTag","children"],"mappings":"AAAA;AACA,OAAOA,KAAP,IACEC,UADF,EAEEC,SAFF,EAGEC,eAHF,EAIEC,OAJF,EAKEC,MALF,QAMO,OANP;AAOA,SAASC,QAAT,EAAmBC,cAAnB,QAAyC,cAAzC;AAIA,SAASC,SAAT,QAA0B,gBAA1B;AAEA,OAAOC,6BAAP,MAA0C,wCAA1C;AAEA,SAASC,kBAAT,QAAmC,sBAAnC;AACA,SAASC,cAAT,QAA+B,kBAA/B;AACA,SAASC,eAAT,QAAgC,mBAAhC;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SAASC,mBAAT,QAAoC,SAApC;AACA,SAASC,IAAT,EAAeC,YAAf,QAAmC,QAAnC;AACA,SAASC,kBAAT,Q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ACXR,MAAAA,eAAe,CAACI,SAAhB,GAA4B,KAA5B;AACApC,MAAAA,YAAY,CAACgC,eAAD,CAAZ;AACD,KAHD;AAID,GAhBc,EAgBZ,EAhBY,CAAf;AAkBA3C,EAAAA,SAAS,CAAC,MAAM;AACd,QAAIqC,KAAK,CAACC,WAAV,EAAuB;AACrBD,MAAAA,KAAK,CAACC,WAAN,GAAoB,KAApB;AACD,KAFD,MAEO;AACLU,MAAAA,sBAAsB;AACvB;AACF,GANQ,EAMN,CAAC9B,KAAD,CANM,CAAT;;AAQA,MAAIgB,mBAAJ,EAAyB;AACvB,wBACE,oBAAC,YAAD;AACE,MAAA,GAAG,EAAEe,UADP;AAEE,MAAA,qBAAqB,EAAEN,eAAe,CAACE;AAFzC,OAGG3B,KAAK,CAACkC,QAHT,CADF;AAOD,GARD,MAQO;AACL,wBAAO,oBAAC,IAAD;AAAM,MAAA,GAAG,EAAEH;AAAX,OAAwB/B,KAAK,CAACkC,QAA9B,CAAP;AACD;AACF,CA9FM","sourcesContent":["/* eslint-disable react/no-unused-prop-types */\nimport React, {\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n} from 'react';\nimport { Platform, findNodeHandle } from 'react-native';\nimport { GestureType } from '../gesture';\nimport { UserSelect, TouchAction } from '../../gestureHandlerCommon';\nimport { ComposedGesture } from '../gestureComposition';\nimport { isJestEnv } from '../../../utils';\n\nimport GestureHandlerRootViewContext from '../../../GestureHandlerRootViewContext';\nimport { AttachedGestureState, GestureDetectorState } from './types';\nimport { useAnimatedGesture } from './useAnimatedGesture';\nimport { attachHandlers } from './attachHandlers';\nimport { needsToReattach } from './needsToReattach';\nimport { dropHandlers } from './dropHandlers';\nimport { useWebEventHandlers } from './utils';\nimport { Wrap, AnimatedWrap } from './Wrap';\nimport { useDetectorUpdater } from './useDetectorUpdater';\nimport { useViewRefHandler } from './useViewRefHandler';\n\nfunction propagateDetectorConfig(\n props: GestureDetectorProps,\n gesture: ComposedGesture | GestureType\n) {\n const keysToPropagate: (keyof GestureDetectorProps)[] = [\n 'userSelect',\n 'enableContextMenu',\n 'touchAction',\n ];\n\n for (const key of keysToPropagate) {\n const value = props[key];\n if (value === undefined) {\n continue;\n }\n\n for (const g of gesture.toGestureArray()) {\n const config = g.config as { [key: string]: unknown };\n config[key] = value;\n }\n }\n}\n\ninterface GestureDetectorProps {\n children?: React.ReactNode;\n /**\n * A gesture object containing the configuration and callbacks.\n * Can be any of:\n * - base gestures (`Tap`, `Pan`, ...)\n * - `ComposedGesture` (`Race`, `Simultaneous`, `Exclusive`)\n */\n gesture: ComposedGesture | GestureType;\n /**\n * #### Web only\n * This parameter allows to specify which `userSelect` property should be applied to underlying view.\n * Possible values are `\"none\" | \"auto\" | \"text\"`. Default value is set to `\"none\"`.\n */\n userSelect?: UserSelect;\n /**\n * #### Web only\n * Specifies whether context menu should be enabled after clicking on underlying view with right mouse button.\n * Default value is set to `false`.\n */\n enableContextMenu?: boolean;\n /**\n * #### Web only\n * This parameter allows to specify which `touchAction` property should be applied to underlying view.\n * Supports all CSS touch-action values (e.g. `\"none\"`, `\"pan-y\"`). Default value is set to `\"none\"`.\n */\n touchAction?: TouchAction;\n}\n\n/**\n * `GestureDetector` is responsible for creating and updating native gesture handlers based on the config of provided gesture.\n *\n * ### Props\n * - `gesture`\n * - `userSelect` (**Web only**)\n * - `enableContextMenu` (**Web only**)\n * - `touchAction` (**Web only**)\n *\n * ### Remarks\n * - Gesture Detector will use first native view in its subtree to recognize gestures, however if this view is used only to group its children it may get automatically collapsed.\n * - Using the same instance of a gesture across multiple Gesture Detectors is not possible.\n *\n * @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/gesture-detector\n */\nexport const GestureDetector = (props: GestureDetectorProps) => {\n const rootViewContext = useContext(GestureHandlerRootViewContext);\n if (__DEV__ && !rootViewContext && !isJestEnv() && Platform.OS !== 'web') {\n throw new Error(\n 'GestureDetector must be used as a descendant of GestureHandlerRootView. Otherwise the gestures will not be recognized. See https://docs.swmansion.com/react-native-gesture-handler/docs/installation for more details.'\n );\n }\n\n // Gesture config should be wrapped with useMemo to prevent unnecessary re-renders\n const gestureConfig = props.gesture;\n propagateDetectorConfig(props, gestureConfig);\n\n const gesturesToAttach = useMemo(\n () => gestureConfig.toGestureArray(),\n [gestureConfig]\n );\n const shouldUseReanimated = gesturesToAttach.some(\n (g) => g.shouldUseReanimated\n );\n\n const webEventHandlersRef = useWebEventHandlers();\n // store state in ref to prevent unnecessary renders\n const state = useRef<GestureDetectorState>({\n firstRender: true,\n viewRef: null,\n previousViewTag: -1,\n forceRebuildReanimatedEvent: false,\n }).current;\n\n const preparedGesture = React.useRef<AttachedGestureState>({\n attachedGestures: [],\n animatedEventHandler: null,\n animatedHandlers: null,\n shouldUseReanimated: shouldUseReanimated,\n isMounted: false,\n }).current;\n\n const updateAttachedGestures = useDetectorUpdater(\n state,\n preparedGesture,\n gesturesToAttach,\n gestureConfig,\n webEventHandlersRef\n );\n\n const refHandler = useViewRefHandler(state, updateAttachedGestures);\n\n // Reanimated event should be rebuilt only when gestures are reattached, otherwise\n // config update will be enough as all necessary items are stored in shared values anyway\n const needsToRebuildReanimatedEvent =\n state.firstRender ||\n state.forceRebuildReanimatedEvent ||\n needsToReattach(preparedGesture, gesturesToAttach);\n state.forceRebuildReanimatedEvent = false;\n\n useAnimatedGesture(preparedGesture, needsToRebuildReanimatedEvent);\n\n useLayoutEffect(() => {\n const viewTag = findNodeHandle(state.viewRef) as number;\n preparedGesture.isMounted = true;\n\n attachHandlers({\n preparedGesture,\n gestureConfig,\n gesturesToAttach,\n webEventHandlersRef,\n viewTag,\n });\n\n return () => {\n preparedGesture.isMounted = false;\n dropHandlers(preparedGesture);\n };\n }, []);\n\n useEffect(() => {\n if (state.firstRender) {\n state.firstRender = false;\n } else {\n updateAttachedGestures();\n }\n }, [props]);\n\n if (shouldUseReanimated) {\n return (\n <AnimatedWrap\n ref={refHandler}\n onGestureHandlerEvent={preparedGesture.animatedEventHandler}>\n {props.children}\n </AnimatedWrap>\n );\n } else {\n return <Wrap ref={refHandler}>{props.children}</Wrap>;\n }\n};\n"]}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
// Checks whether the gesture should be reattached to the view, this will happen when:
|
2
|
+
// - The number of gestures in the preparedGesture is different than the number of gestures in the gesture
|
3
|
+
// - The handlerName is different in any of the gestures
|
4
|
+
// - At least one of the gestures changed the thread it runs on
|
5
|
+
export function needsToReattach(preparedGesture, newGestures) {
|
6
|
+
if (newGestures.length !== preparedGesture.attachedGestures.length) {
|
7
|
+
return true;
|
8
|
+
}
|
9
|
+
|
10
|
+
for (let i = 0; i < newGestures.length; i++) {
|
11
|
+
if (newGestures[i].handlerName !== preparedGesture.attachedGestures[i].handlerName || newGestures[i].shouldUseReanimated !== preparedGesture.attachedGestures[i].shouldUseReanimated) {
|
12
|
+
return true;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
return false;
|
17
|
+
}
|
18
|
+
//# sourceMappingURL=needsToReattach.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["needsToReattach.ts"],"names":["needsToReattach","preparedGesture","newGestures","length","attachedGestures","i","handlerName","shouldUseReanimated"],"mappings":"AAGA;AACA;AACA;AACA;AACA,OAAO,SAASA,eAAT,CACLC,eADK,EAELC,WAFK,EAGL;AACA,MAAIA,WAAW,CAACC,MAAZ,KAAuBF,eAAe,CAACG,gBAAhB,CAAiCD,MAA5D,EAAoE;AAClE,WAAO,IAAP;AACD;;AACD,OAAK,IAAIE,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGH,WAAW,CAACC,MAAhC,EAAwCE,CAAC,EAAzC,EAA6C;AAC3C,QACEH,WAAW,CAACG,CAAD,CAAX,CAAeC,WAAf,KACEL,eAAe,CAACG,gBAAhB,CAAiCC,CAAjC,EAAoCC,WADtC,IAEAJ,WAAW,CAACG,CAAD,CAAX,CAAeE,mBAAf,KACEN,eAAe,CAACG,gBAAhB,CAAiCC,CAAjC,EAAoCE,mBAJxC,EAKE;AACA,aAAO,IAAP;AACD;AACF;;AAED,SAAO,KAAP;AACD","sourcesContent":["import { GestureType } from '../gesture';\nimport { AttachedGestureState } from './types';\n\n// Checks whether the gesture should be reattached to the view, this will happen when:\n// - The number of gestures in the preparedGesture is different than the number of gestures in the gesture\n// - The handlerName is different in any of the gestures\n// - At least one of the gestures changed the thread it runs on\nexport function needsToReattach(\n preparedGesture: AttachedGestureState,\n newGestures: GestureType[]\n) {\n if (newGestures.length !== preparedGesture.attachedGestures.length) {\n return true;\n }\n for (let i = 0; i < newGestures.length; i++) {\n if (\n newGestures[i].handlerName !==\n preparedGesture.attachedGestures[i].handlerName ||\n newGestures[i].shouldUseReanimated !==\n preparedGesture.attachedGestures[i].shouldUseReanimated\n ) {\n return true;\n }\n }\n\n return false;\n}\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
import { registerHandler } from '../../handlersRegistry';
|
2
|
+
import RNGestureHandlerModule from '../../../RNGestureHandlerModule';
|
3
|
+
import { filterConfig, scheduleFlushOperations } from '../../gestureHandlerCommon';
|
4
|
+
import { ghQueueMicrotask } from '../../../ghQueueMicrotask';
|
5
|
+
import { extractGestureRelations, checkGestureCallbacksForWorklets, ALLOWED_PROPS } from './utils';
|
6
|
+
export function updateHandlers(preparedGesture, gestureConfig, newGestures) {
|
7
|
+
gestureConfig.prepare();
|
8
|
+
|
9
|
+
for (let i = 0; i < newGestures.length; i++) {
|
10
|
+
const handler = preparedGesture.attachedGestures[i];
|
11
|
+
checkGestureCallbacksForWorklets(handler); // only update handlerTag when it's actually different, it may be the same
|
12
|
+
// if gesture config object is wrapped with useMemo
|
13
|
+
|
14
|
+
if (newGestures[i].handlerTag !== handler.handlerTag) {
|
15
|
+
newGestures[i].handlerTag = handler.handlerTag;
|
16
|
+
newGestures[i].handlers.handlerTag = handler.handlerTag;
|
17
|
+
}
|
18
|
+
} // use queueMicrotask to extract handlerTags, because when it's ran, all refs should be updated
|
19
|
+
// and handlerTags in BaseGesture references should be updated in the loop above (we need to wait
|
20
|
+
// in case of external relations)
|
21
|
+
|
22
|
+
|
23
|
+
ghQueueMicrotask(() => {
|
24
|
+
if (!preparedGesture.isMounted) {
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
|
28
|
+
for (let i = 0; i < newGestures.length; i++) {
|
29
|
+
const handler = preparedGesture.attachedGestures[i];
|
30
|
+
handler.config = newGestures[i].config;
|
31
|
+
handler.handlers = newGestures[i].handlers;
|
32
|
+
RNGestureHandlerModule.updateGestureHandler(handler.handlerTag, filterConfig(handler.config, ALLOWED_PROPS, extractGestureRelations(handler)));
|
33
|
+
registerHandler(handler.handlerTag, handler, handler.config.testId);
|
34
|
+
}
|
35
|
+
|
36
|
+
if (preparedGesture.animatedHandlers) {
|
37
|
+
var _preparedGesture$anim;
|
38
|
+
|
39
|
+
const previousHandlersValue = (_preparedGesture$anim = preparedGesture.animatedHandlers.value) !== null && _preparedGesture$anim !== void 0 ? _preparedGesture$anim : [];
|
40
|
+
const newHandlersValue = preparedGesture.attachedGestures.filter(g => g.shouldUseReanimated) // ignore gestures that shouldn't run on UI
|
41
|
+
.map(g => g.handlers); // if amount of gesture configs changes, we need to update the callbacks in shared value
|
42
|
+
|
43
|
+
let shouldUpdateSharedValue = previousHandlersValue.length !== newHandlersValue.length;
|
44
|
+
|
45
|
+
if (!shouldUpdateSharedValue) {
|
46
|
+
// if the amount is the same, we need to check if any of the configs inside has changed
|
47
|
+
for (let i = 0; i < newHandlersValue.length; i++) {
|
48
|
+
if ( // we can use the `gestureId` prop as it's unique for every config instance
|
49
|
+
newHandlersValue[i].gestureId !== previousHandlersValue[i].gestureId) {
|
50
|
+
shouldUpdateSharedValue = true;
|
51
|
+
break;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
if (shouldUpdateSharedValue) {
|
57
|
+
preparedGesture.animatedHandlers.value = newHandlersValue;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
scheduleFlushOperations();
|
62
|
+
});
|
63
|
+
}
|
64
|
+
//# sourceMappingURL=updateHandlers.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["updateHandlers.ts"],"names":["registerHandler","RNGestureHandlerModule","filterConfig","scheduleFlushOperations","ghQueueMicrotask","extractGestureRelations","checkGestureCallbacksForWorklets","ALLOWED_PROPS","updateHandlers","preparedGesture","gestureConfig","newGestures","prepare","i","length","handler","attachedGestures","handlerTag","handlers","isMounted","config","updateGestureHandler","testId","animatedHandlers","previousHandlersValue","value","newHandlersValue","filter","g","shouldUseReanimated","map","shouldUpdateSharedValue","gestureId"],"mappings":"AACA,SAASA,eAAT,QAAgC,wBAAhC;AACA,OAAOC,sBAAP,MAAmC,iCAAnC;AACA,SACEC,YADF,EAEEC,uBAFF,QAGO,4BAHP;AAKA,SAASC,gBAAT,QAAiC,2BAAjC;AAEA,SACEC,uBADF,EAEEC,gCAFF,EAGEC,aAHF,QAIO,SAJP;AAMA,OAAO,SAASC,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;AACAP,IAAAA,gCAAgC,CAACS,OAAD,CAAhC,CAF2C,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,CAAwB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BA,CAAC,GAAGa,gBAAgB,CAACZ,MAArC,EAA6CD,CAAC,EAA9C,EAAkD;AAChD,eACE;AACAa,UAAAA,gBAAgB,CAACb,CAAD,CAAhB,CAAoBmB,SAApB,KAAkCR,qBAAqB,CAACX,CAAD,CAArB,CAAyBmB,SAF7D,EAGE;AACAD,YAAAA,uBAAuB,GAAG,IAA1B;AACA;AACD;AACF;AACF;;AAED,UAAIA,uBAAJ,EAA6B;AAC3BtB,QAAAA,eAAe,CAACc,gBAAhB,CAAiCE,KAAjC,GAAyCC,gBAAzC;AACD;AACF;;AAEDvB,IAAAA,uBAAuB;AACxB,GAtDe,CAAhB;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,165 @@
|
|
1
|
+
import { CALLBACK_TYPE } from '../gesture';
|
2
|
+
import { Reanimated } from '../reanimatedWrapper';
|
3
|
+
import { GestureStateManager } from '../gestureStateManager';
|
4
|
+
import { State } from '../../../State';
|
5
|
+
import { TouchEventType } from '../../../TouchEventType';
|
6
|
+
import { tagMessage } from '../../../utils';
|
7
|
+
|
8
|
+
function getHandler(type, gesture) {
|
9
|
+
'worklet';
|
10
|
+
|
11
|
+
switch (type) {
|
12
|
+
case CALLBACK_TYPE.BEGAN:
|
13
|
+
return gesture.onBegin;
|
14
|
+
|
15
|
+
case CALLBACK_TYPE.START:
|
16
|
+
return gesture.onStart;
|
17
|
+
|
18
|
+
case CALLBACK_TYPE.UPDATE:
|
19
|
+
return gesture.onUpdate;
|
20
|
+
|
21
|
+
case CALLBACK_TYPE.CHANGE:
|
22
|
+
return gesture.onChange;
|
23
|
+
|
24
|
+
case CALLBACK_TYPE.END:
|
25
|
+
return gesture.onEnd;
|
26
|
+
|
27
|
+
case CALLBACK_TYPE.FINALIZE:
|
28
|
+
return gesture.onFinalize;
|
29
|
+
|
30
|
+
case CALLBACK_TYPE.TOUCHES_DOWN:
|
31
|
+
return gesture.onTouchesDown;
|
32
|
+
|
33
|
+
case CALLBACK_TYPE.TOUCHES_MOVE:
|
34
|
+
return gesture.onTouchesMove;
|
35
|
+
|
36
|
+
case CALLBACK_TYPE.TOUCHES_UP:
|
37
|
+
return gesture.onTouchesUp;
|
38
|
+
|
39
|
+
case CALLBACK_TYPE.TOUCHES_CANCELLED:
|
40
|
+
return gesture.onTouchesCancelled;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
function touchEventTypeToCallbackType(eventType) {
|
45
|
+
'worklet';
|
46
|
+
|
47
|
+
switch (eventType) {
|
48
|
+
case TouchEventType.TOUCHES_DOWN:
|
49
|
+
return CALLBACK_TYPE.TOUCHES_DOWN;
|
50
|
+
|
51
|
+
case TouchEventType.TOUCHES_MOVE:
|
52
|
+
return CALLBACK_TYPE.TOUCHES_MOVE;
|
53
|
+
|
54
|
+
case TouchEventType.TOUCHES_UP:
|
55
|
+
return CALLBACK_TYPE.TOUCHES_UP;
|
56
|
+
|
57
|
+
case TouchEventType.TOUCHES_CANCELLED:
|
58
|
+
return CALLBACK_TYPE.TOUCHES_CANCELLED;
|
59
|
+
}
|
60
|
+
|
61
|
+
return CALLBACK_TYPE.UNDEFINED;
|
62
|
+
}
|
63
|
+
|
64
|
+
function runWorklet(type, gesture, event, ...args) {
|
65
|
+
'worklet';
|
66
|
+
|
67
|
+
const handler = getHandler(type, gesture);
|
68
|
+
|
69
|
+
if (gesture.isWorklet[type]) {
|
70
|
+
// @ts-ignore Logic below makes sure the correct event is send to the
|
71
|
+
// correct handler.
|
72
|
+
handler === null || handler === void 0 ? void 0 : handler(event, ...args);
|
73
|
+
} else if (handler) {
|
74
|
+
console.warn(tagMessage('Animated gesture callback must be a worklet'));
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
function isStateChangeEvent(event) {
|
79
|
+
'worklet'; // @ts-ignore Yes, the oldState prop is missing on GestureTouchEvent, that's the point
|
80
|
+
|
81
|
+
return event.oldState != null;
|
82
|
+
}
|
83
|
+
|
84
|
+
function isTouchEvent(event) {
|
85
|
+
'worklet';
|
86
|
+
|
87
|
+
return event.eventType != null;
|
88
|
+
}
|
89
|
+
|
90
|
+
export function useAnimatedGesture(preparedGesture, needsRebuild) {
|
91
|
+
if (!Reanimated) {
|
92
|
+
return;
|
93
|
+
} // Hooks are called conditionally, but the condition is whether the
|
94
|
+
// react-native-reanimated is installed, which shouldn't change while running
|
95
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
96
|
+
|
97
|
+
|
98
|
+
const sharedHandlersCallbacks = Reanimated.useSharedValue(null); // eslint-disable-next-line react-hooks/rules-of-hooks
|
99
|
+
|
100
|
+
const lastUpdateEvent = Reanimated.useSharedValue([]); // not every gesture needs a state controller, init them lazily
|
101
|
+
|
102
|
+
const stateControllers = [];
|
103
|
+
|
104
|
+
const callback = event => {
|
105
|
+
'worklet';
|
106
|
+
|
107
|
+
const currentCallback = sharedHandlersCallbacks.value;
|
108
|
+
|
109
|
+
if (!currentCallback) {
|
110
|
+
return;
|
111
|
+
}
|
112
|
+
|
113
|
+
for (let i = 0; i < currentCallback.length; i++) {
|
114
|
+
const gesture = currentCallback[i];
|
115
|
+
|
116
|
+
if (event.handlerTag !== gesture.handlerTag) {
|
117
|
+
continue;
|
118
|
+
}
|
119
|
+
|
120
|
+
if (isStateChangeEvent(event)) {
|
121
|
+
if (event.oldState === State.UNDETERMINED && event.state === State.BEGAN) {
|
122
|
+
runWorklet(CALLBACK_TYPE.BEGAN, gesture, event);
|
123
|
+
} else if ((event.oldState === State.BEGAN || event.oldState === State.UNDETERMINED) && event.state === State.ACTIVE) {
|
124
|
+
runWorklet(CALLBACK_TYPE.START, gesture, event);
|
125
|
+
lastUpdateEvent.value[gesture.handlerTag] = undefined;
|
126
|
+
} else if (event.oldState !== event.state && event.state === State.END) {
|
127
|
+
if (event.oldState === State.ACTIVE) {
|
128
|
+
runWorklet(CALLBACK_TYPE.END, gesture, event, true);
|
129
|
+
}
|
130
|
+
|
131
|
+
runWorklet(CALLBACK_TYPE.FINALIZE, gesture, event, true);
|
132
|
+
} else if ((event.state === State.FAILED || event.state === State.CANCELLED) && event.state !== event.oldState) {
|
133
|
+
if (event.oldState === State.ACTIVE) {
|
134
|
+
runWorklet(CALLBACK_TYPE.END, gesture, event, false);
|
135
|
+
}
|
136
|
+
|
137
|
+
runWorklet(CALLBACK_TYPE.FINALIZE, gesture, event, false);
|
138
|
+
}
|
139
|
+
} else if (isTouchEvent(event)) {
|
140
|
+
if (!stateControllers[i]) {
|
141
|
+
stateControllers[i] = GestureStateManager.create(event.handlerTag);
|
142
|
+
}
|
143
|
+
|
144
|
+
if (event.eventType !== TouchEventType.UNDETERMINED) {
|
145
|
+
runWorklet(touchEventTypeToCallbackType(event.eventType), gesture, event, stateControllers[i]);
|
146
|
+
}
|
147
|
+
} else {
|
148
|
+
runWorklet(CALLBACK_TYPE.UPDATE, gesture, event);
|
149
|
+
|
150
|
+
if (gesture.onChange && gesture.changeEventCalculator) {
|
151
|
+
var _gesture$changeEventC;
|
152
|
+
|
153
|
+
runWorklet(CALLBACK_TYPE.CHANGE, gesture, (_gesture$changeEventC = gesture.changeEventCalculator) === null || _gesture$changeEventC === void 0 ? void 0 : _gesture$changeEventC.call(gesture, event, lastUpdateEvent.value[gesture.handlerTag]));
|
154
|
+
lastUpdateEvent.value[gesture.handlerTag] = event;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
}
|
158
|
+
}; // eslint-disable-next-line react-hooks/rules-of-hooks
|
159
|
+
|
160
|
+
|
161
|
+
const event = Reanimated.useEvent(callback, ['onGestureHandlerStateChange', 'onGestureHandlerEvent'], needsRebuild);
|
162
|
+
preparedGesture.animatedEventHandler = event;
|
163
|
+
preparedGesture.animatedHandlers = sharedHandlersCallbacks;
|
164
|
+
}
|
165
|
+
//# sourceMappingURL=useAnimatedGesture.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["useAnimatedGesture.ts"],"names":["CALLBACK_TYPE","Reanimated","GestureStateManager","State","TouchEventType","tagMessage","getHandler","type","gesture","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","UNDEFINED","runWorklet","event","args","handler","isWorklet","console","warn","isStateChangeEvent","oldState","isTouchEvent","useAnimatedGesture","preparedGesture","needsRebuild","sharedHandlersCallbacks","useSharedValue","lastUpdateEvent","stateControllers","callback","currentCallback","value","i","length","handlerTag","UNDETERMINED","state","ACTIVE","undefined","FAILED","CANCELLED","create","changeEventCalculator","useEvent","animatedEventHandler","animatedHandlers"],"mappings":"AAAA,SAA2BA,aAA3B,QAAgD,YAAhD;AACA,SAASC,UAAT,QAA2B,sBAA3B;AAMA,SACEC,mBADF,QAGO,wBAHP;AAIA,SAASC,KAAT,QAAsB,gBAAtB;AACA,SAASC,cAAT,QAA+B,yBAA/B;AACA,SAASC,UAAT,QAA2B,gBAA3B;;AAGA,SAASC,UAAT,CACEC,IADF,EAEEC,OAFF,EAGE;AACA;;AACA,UAAQD,IAAR;AACE,SAAKP,aAAa,CAACS,KAAnB;AACE,aAAOD,OAAO,CAACE,OAAf;;AACF,SAAKV,aAAa,CAACW,KAAnB;AACE,aAAOH,OAAO,CAACI,OAAf;;AACF,SAAKZ,aAAa,CAACa,MAAnB;AAC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esture';\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,41 @@
|
|
1
|
+
import { useCallback } from 'react';
|
2
|
+
import { findNodeHandle } from 'react-native';
|
3
|
+
import { attachHandlers } from './attachHandlers';
|
4
|
+
import { updateHandlers } from './updateHandlers';
|
5
|
+
import { needsToReattach } from './needsToReattach';
|
6
|
+
import { dropHandlers } from './dropHandlers';
|
7
|
+
import { useForceRender, validateDetectorChildren } from './utils'; // Returns a function that's responsible for updating the attached gestures
|
8
|
+
// If the view has changed, it will reattach the handlers to the new view
|
9
|
+
// If the view remains the same, it will update the handlers with the new config
|
10
|
+
|
11
|
+
export function useDetectorUpdater(state, preparedGesture, gesturesToAttach, gestureConfig, webEventHandlersRef) {
|
12
|
+
const forceRender = useForceRender();
|
13
|
+
const updateAttachedGestures = useCallback( // skipConfigUpdate is used to prevent unnecessary updates when only checking if the view has changed
|
14
|
+
skipConfigUpdate => {
|
15
|
+
// if the underlying view has changed we need to reattach handlers to the new view
|
16
|
+
const viewTag = findNodeHandle(state.viewRef);
|
17
|
+
const didUnderlyingViewChange = viewTag !== state.previousViewTag;
|
18
|
+
|
19
|
+
if (didUnderlyingViewChange || needsToReattach(preparedGesture, gesturesToAttach)) {
|
20
|
+
validateDetectorChildren(state.viewRef);
|
21
|
+
dropHandlers(preparedGesture);
|
22
|
+
attachHandlers({
|
23
|
+
preparedGesture,
|
24
|
+
gestureConfig,
|
25
|
+
gesturesToAttach,
|
26
|
+
webEventHandlersRef,
|
27
|
+
viewTag
|
28
|
+
});
|
29
|
+
|
30
|
+
if (didUnderlyingViewChange) {
|
31
|
+
state.previousViewTag = viewTag;
|
32
|
+
state.forceRebuildReanimatedEvent = true;
|
33
|
+
forceRender();
|
34
|
+
}
|
35
|
+
} else if (!skipConfigUpdate) {
|
36
|
+
updateHandlers(preparedGesture, gestureConfig, gesturesToAttach);
|
37
|
+
}
|
38
|
+
}, [forceRender, gestureConfig, gesturesToAttach, preparedGesture, state, webEventHandlersRef]);
|
39
|
+
return updateAttachedGestures;
|
40
|
+
}
|
41
|
+
//# sourceMappingURL=useDetectorUpdater.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["useDetectorUpdater.ts"],"names":["useCallback","findNodeHandle","attachHandlers","updateHandlers","needsToReattach","dropHandlers","useForceRender","validateDetectorChildren","useDetectorUpdater","state","preparedGesture","gesturesToAttach","gestureConfig","webEventHandlersRef","forceRender","updateAttachedGestures","skipConfigUpdate","viewTag","viewRef","didUnderlyingViewChange","previousViewTag","forceRebuildReanimatedEvent"],"mappings":"AAAA,SAAgBA,WAAhB,QAAmC,OAAnC;AACA,SAASC,cAAT,QAA+B,cAA/B;AASA,SAASC,cAAT,QAA+B,kBAA/B;AACA,SAASC,cAAT,QAA+B,kBAA/B;AACA,SAASC,eAAT,QAAgC,mBAAhC;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SAASC,cAAT,EAAyBC,wBAAzB,QAAyD,SAAzD,C,CAEA;AACA;AACA;;AACA,OAAO,SAASC,kBAAT,CACLC,KADK,EAELC,eAFK,EAGLC,gBAHK,EAILC,aAJK,EAKLC,mBALK,EAML;AACA,QAAMC,WAAW,GAAGR,cAAc,EAAlC;AACA,QAAMS,sBAAsB,GAAGf,WAAW,EACxC;AACCgB,EAAAA,gBAAD,IAAgC;AAC9B;AACA,UAAMC,OAAO,GAAGhB,cAAc,CAACQ,KAAK,CAACS,OAAP,CAA9B;AACA,UAAMC,uBAAuB,GAAGF,OAAO,KAAKR,KAAK,CAACW,eAAlD;;AAEA,QACED,uBAAuB,IACvBf,eAAe,CAACM,eAAD,EAAkBC,gBAAlB,CAFjB,EAGE;AACAJ,MAAAA,wBAAwB,CAACE,KAAK,CAACS,OAAP,CAAxB;AACAb,MAAAA,YAAY,CAACK,eAAD,CAAZ;AACAR,MAAAA,cAAc,CAAC;AACbQ,QAAAA,eADa;AAEbE,QAAAA,aAFa;AAGbD,QAAAA,gBAHa;AAIbE,QAAAA,mBAJa;AAKbI,QAAAA;AALa,OAAD,CAAd;;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;AAC5Bb,MAAAA,cAAc,CAACO,eAAD,EAAkBE,aAAlB,EAAiCD,gBAAjC,CAAd;AACD;AACF,GA7BuC,EA8BxC,CACEG,WADF,EAEEF,aAFF,EAGED,gBAHF,EAIED,eAJF,EAKED,KALF,EAMEI,mBANF,CA9BwC,CAA1C;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"]}
|