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,143 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.GestureDetector = void 0;
|
7
|
+
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
9
|
+
|
10
|
+
var _reactNative = require("react-native");
|
11
|
+
|
12
|
+
var _utils = require("../../../utils");
|
13
|
+
|
14
|
+
var _GestureHandlerRootViewContext = _interopRequireDefault(require("../../../GestureHandlerRootViewContext"));
|
15
|
+
|
16
|
+
var _useAnimatedGesture = require("./useAnimatedGesture");
|
17
|
+
|
18
|
+
var _attachHandlers = require("./attachHandlers");
|
19
|
+
|
20
|
+
var _needsToReattach = require("./needsToReattach");
|
21
|
+
|
22
|
+
var _dropHandlers = require("./dropHandlers");
|
23
|
+
|
24
|
+
var _utils2 = require("./utils");
|
25
|
+
|
26
|
+
var _Wrap = require("./Wrap");
|
27
|
+
|
28
|
+
var _useDetectorUpdater = require("./useDetectorUpdater");
|
29
|
+
|
30
|
+
var _useViewRefHandler = require("./useViewRefHandler");
|
31
|
+
|
32
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
33
|
+
|
34
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
35
|
+
|
36
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
37
|
+
|
38
|
+
/* eslint-disable react/no-unused-prop-types */
|
39
|
+
function propagateDetectorConfig(props, gesture) {
|
40
|
+
const keysToPropagate = ['userSelect', 'enableContextMenu', 'touchAction'];
|
41
|
+
|
42
|
+
for (const key of keysToPropagate) {
|
43
|
+
const value = props[key];
|
44
|
+
|
45
|
+
if (value === undefined) {
|
46
|
+
continue;
|
47
|
+
}
|
48
|
+
|
49
|
+
for (const g of gesture.toGestureArray()) {
|
50
|
+
const config = g.config;
|
51
|
+
config[key] = value;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* `GestureDetector` is responsible for creating and updating native gesture handlers based on the config of provided gesture.
|
58
|
+
*
|
59
|
+
* ### Props
|
60
|
+
* - `gesture`
|
61
|
+
* - `userSelect` (**Web only**)
|
62
|
+
* - `enableContextMenu` (**Web only**)
|
63
|
+
* - `touchAction` (**Web only**)
|
64
|
+
*
|
65
|
+
* ### Remarks
|
66
|
+
* - 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.
|
67
|
+
* - Using the same instance of a gesture across multiple Gesture Detectors is not possible.
|
68
|
+
*
|
69
|
+
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/gesture-detector
|
70
|
+
*/
|
71
|
+
const GestureDetector = props => {
|
72
|
+
const rootViewContext = (0, _react.useContext)(_GestureHandlerRootViewContext.default);
|
73
|
+
|
74
|
+
if (__DEV__ && !rootViewContext && !(0, _utils.isJestEnv)() && _reactNative.Platform.OS !== 'web') {
|
75
|
+
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.');
|
76
|
+
} // Gesture config should be wrapped with useMemo to prevent unnecessary re-renders
|
77
|
+
|
78
|
+
|
79
|
+
const gestureConfig = props.gesture;
|
80
|
+
propagateDetectorConfig(props, gestureConfig);
|
81
|
+
const gesturesToAttach = (0, _react.useMemo)(() => gestureConfig.toGestureArray(), [gestureConfig]);
|
82
|
+
const shouldUseReanimated = gesturesToAttach.some(g => g.shouldUseReanimated);
|
83
|
+
const webEventHandlersRef = (0, _utils2.useWebEventHandlers)(); // store state in ref to prevent unnecessary renders
|
84
|
+
|
85
|
+
const state = (0, _react.useRef)({
|
86
|
+
firstRender: true,
|
87
|
+
viewRef: null,
|
88
|
+
previousViewTag: -1,
|
89
|
+
forceRebuildReanimatedEvent: false
|
90
|
+
}).current;
|
91
|
+
|
92
|
+
const preparedGesture = _react.default.useRef({
|
93
|
+
attachedGestures: [],
|
94
|
+
animatedEventHandler: null,
|
95
|
+
animatedHandlers: null,
|
96
|
+
shouldUseReanimated: shouldUseReanimated,
|
97
|
+
isMounted: false
|
98
|
+
}).current;
|
99
|
+
|
100
|
+
const updateAttachedGestures = (0, _useDetectorUpdater.useDetectorUpdater)(state, preparedGesture, gesturesToAttach, gestureConfig, webEventHandlersRef);
|
101
|
+
const refHandler = (0, _useViewRefHandler.useViewRefHandler)(state, updateAttachedGestures); // Reanimated event should be rebuilt only when gestures are reattached, otherwise
|
102
|
+
// config update will be enough as all necessary items are stored in shared values anyway
|
103
|
+
|
104
|
+
const needsToRebuildReanimatedEvent = state.firstRender || state.forceRebuildReanimatedEvent || (0, _needsToReattach.needsToReattach)(preparedGesture, gesturesToAttach);
|
105
|
+
state.forceRebuildReanimatedEvent = false;
|
106
|
+
(0, _useAnimatedGesture.useAnimatedGesture)(preparedGesture, needsToRebuildReanimatedEvent);
|
107
|
+
(0, _react.useLayoutEffect)(() => {
|
108
|
+
const viewTag = (0, _reactNative.findNodeHandle)(state.viewRef);
|
109
|
+
preparedGesture.isMounted = true;
|
110
|
+
(0, _attachHandlers.attachHandlers)({
|
111
|
+
preparedGesture,
|
112
|
+
gestureConfig,
|
113
|
+
gesturesToAttach,
|
114
|
+
webEventHandlersRef,
|
115
|
+
viewTag
|
116
|
+
});
|
117
|
+
return () => {
|
118
|
+
preparedGesture.isMounted = false;
|
119
|
+
(0, _dropHandlers.dropHandlers)(preparedGesture);
|
120
|
+
};
|
121
|
+
}, []);
|
122
|
+
(0, _react.useEffect)(() => {
|
123
|
+
if (state.firstRender) {
|
124
|
+
state.firstRender = false;
|
125
|
+
} else {
|
126
|
+
updateAttachedGestures();
|
127
|
+
}
|
128
|
+
}, [props]);
|
129
|
+
|
130
|
+
if (shouldUseReanimated) {
|
131
|
+
return /*#__PURE__*/_react.default.createElement(_Wrap.AnimatedWrap, {
|
132
|
+
ref: refHandler,
|
133
|
+
onGestureHandlerEvent: preparedGesture.animatedEventHandler
|
134
|
+
}, props.children);
|
135
|
+
} else {
|
136
|
+
return /*#__PURE__*/_react.default.createElement(_Wrap.Wrap, {
|
137
|
+
ref: refHandler
|
138
|
+
}, props.children);
|
139
|
+
}
|
140
|
+
};
|
141
|
+
|
142
|
+
exports.GestureDetector = GestureDetector;
|
143
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["propagateDetectorConfig","props","gesture","keysToPropagate","key","value","undefined","g","toGestureArray","config","GestureDetector","rootViewContext","GestureHandlerRootViewContext","__DEV__","Platform","OS","Error","gestureConfig","gesturesToAttach","shouldUseReanimated","some","webEventHandlersRef","state","firstRender","viewRef","previousViewTag","forceRebuildReanimatedEvent","current","preparedGesture","React","useRef","attachedGestures","animatedEventHandler","animatedHandlers","isMounted","updateAttachedGestures","refHandler","needsToRebuildReanimatedEvent","viewTag","children"],"mappings":";;;;;;;AACA;;AAOA;;AAIA;;AAEA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAvBA;AAyBA,SAASA,uBAAT,CACEC,KADF,EAEEC,OAFF,EAGE;AACA,QAAMC,eAA+C,GAAG,CACtD,YADsD,EAEtD,mBAFsD,EAGtD,aAHsD,CAAxD;;AAMA,OAAK,MAAMC,GAAX,IAAkBD,eAAlB,EAAmC;AACjC,UAAME,KAAK,GAAGJ,KAAK,CAACG,GAAD,CAAnB;;AACA,QAAIC,KAAK,KAAKC,SAAd,EAAyB;AACvB;AACD;;AAED,SAAK,MAAMC,CAAX,IAAgBL,OAAO,CAACM,cAAR,EAAhB,EAA0C;AACxC,YAAMC,MAAM,GAAGF,CAAC,CAACE,MAAjB;AACAA,MAAAA,MAAM,CAACL,GAAD,CAAN,GAAcC,KAAd;AACD;AACF;AACF;;AA+BD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMK,eAAe,GAAIT,KAAD,IAAiC;AAC9D,QAAMU,eAAe,GAAG,uBAAWC,sCAAX,CAAxB;;AACA,MAAIC,OAAO,IAAI,CAACF,eAAZ,IAA+B,CAAC,uBAAh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CAHF;AAIAI,EAAAA,KAAK,CAACI,2BAAN,GAAoC,KAApC;AAEA,8CAAmBE,eAAnB,EAAoCS,6BAApC;AAEA,8BAAgB,MAAM;AACpB,UAAMC,OAAO,GAAG,iCAAehB,KAAK,CAACE,OAArB,CAAhB;AACAI,IAAAA,eAAe,CAACM,SAAhB,GAA4B,IAA5B;AAEA,wCAAe;AACbN,MAAAA,eADa;AAEbX,MAAAA,aAFa;AAGbC,MAAAA,gBAHa;AAIbG,MAAAA,mBAJa;AAKbiB,MAAAA;AALa,KAAf;AAQA,WAAO,MAAM;AACXV,MAAAA,eAAe,CAACM,SAAhB,GAA4B,KAA5B;AACA,sCAAaN,eAAb;AACD,KAHD;AAID,GAhBD,EAgBG,EAhBH;AAkBA,wBAAU,MAAM;AACd,QAAIN,KAAK,CAACC,WAAV,EAAuB;AACrBD,MAAAA,KAAK,CAACC,WAAN,GAAoB,KAApB;AACD,KAFD,MAEO;AACLY,MAAAA,sBAAsB;AACvB;AACF,GAND,EAMG,CAAClC,KAAD,CANH;;AAQA,MAAIkB,mBAAJ,EAAyB;AACvB,wBACE,6BAAC,kBAAD;AACE,MAAA,GAAG,EAAEiB,UADP;AAEE,MAAA,qBAAqB,EAAER,eAAe,CAACI;AAFzC,OAGG/B,KAAK,CAACsC,QAHT,CADF;AAOD,GARD,MAQO;AACL,wBAAO,6BAAC,UAAD;AAAM,MAAA,GAAG,EAAEH;AAAX,OAAwBnC,KAAK,CAACsC,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,25 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.needsToReattach = needsToReattach;
|
7
|
+
|
8
|
+
// Checks whether the gesture should be reattached to the view, this will happen when:
|
9
|
+
// - The number of gestures in the preparedGesture is different than the number of gestures in the gesture
|
10
|
+
// - The handlerName is different in any of the gestures
|
11
|
+
// - At least one of the gestures changed the thread it runs on
|
12
|
+
function needsToReattach(preparedGesture, newGestures) {
|
13
|
+
if (newGestures.length !== preparedGesture.attachedGestures.length) {
|
14
|
+
return true;
|
15
|
+
}
|
16
|
+
|
17
|
+
for (let i = 0; i < newGestures.length; i++) {
|
18
|
+
if (newGestures[i].handlerName !== preparedGesture.attachedGestures[i].handlerName || newGestures[i].shouldUseReanimated !== preparedGesture.attachedGestures[i].shouldUseReanimated) {
|
19
|
+
return true;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
return false;
|
24
|
+
}
|
25
|
+
//# 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;AACO,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,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,CAC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e,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,aAAOhB,OAAO,CAACiB,aAAf;;AACF,SAAKhB,uBAAciB,UAAnB;AACE,aAAOlB,OAAO,CAACmB,WAAf;;AACF,SAAKlB,uBAAcmB,iBAAnB;AACE,aAAOpB,OAAO,CAACqB,kBAAf;AApBJ;AAsBD;;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ADN,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"]}
|