react-native-gesture-handler 2.27.1 → 2.27.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReanimatedSwipeable/package.json +4 -4
- package/android/build.gradle +8 -1
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +14 -8
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +10 -5
- package/apple/RNGestureHandler.h +4 -0
- package/apple/RNGestureHandler.mm +41 -6
- package/jestSetup.js +22 -3
- package/lib/commonjs/components/Pressable/Pressable.js +12 -21
- package/lib/commonjs/components/Pressable/Pressable.js.map +1 -1
- package/lib/commonjs/components/Pressable/StateMachine.js +8 -2
- package/lib/commonjs/components/Pressable/StateMachine.js.map +1 -1
- package/lib/commonjs/components/Pressable/stateDefinitions.js +22 -23
- package/lib/commonjs/components/Pressable/stateDefinitions.js.map +1 -1
- package/lib/commonjs/components/{ReanimatedSwipeable.js → ReanimatedSwipeable/ReanimatedSwipeable.js} +30 -39
- package/lib/commonjs/components/ReanimatedSwipeable/ReanimatedSwipeable.js.map +1 -0
- package/lib/commonjs/components/ReanimatedSwipeable/ReanimatedSwipeableProps.js +12 -0
- package/lib/commonjs/components/ReanimatedSwipeable/ReanimatedSwipeableProps.js.map +1 -0
- package/lib/commonjs/components/ReanimatedSwipeable/index.js +21 -0
- package/lib/commonjs/components/ReanimatedSwipeable/index.js.map +1 -0
- package/lib/commonjs/mocks/Pressable.js +13 -0
- package/lib/commonjs/mocks/Pressable.js.map +1 -0
- package/lib/commonjs/{mocks.js → mocks/mocks.js} +8 -11
- package/lib/commonjs/mocks/mocks.js.map +1 -0
- package/lib/commonjs/web/handlers/GestureHandler.js +1 -0
- package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
- package/lib/module/components/Pressable/Pressable.js +14 -23
- package/lib/module/components/Pressable/Pressable.js.map +1 -1
- package/lib/module/components/Pressable/StateMachine.js +8 -2
- package/lib/module/components/Pressable/StateMachine.js.map +1 -1
- package/lib/module/components/Pressable/stateDefinitions.js +21 -22
- package/lib/module/components/Pressable/stateDefinitions.js.map +1 -1
- package/lib/module/components/{ReanimatedSwipeable.js → ReanimatedSwipeable/ReanimatedSwipeable.js} +24 -33
- package/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeable.js.map +1 -0
- package/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeableProps.js +8 -0
- package/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeableProps.js.map +1 -0
- package/lib/module/components/ReanimatedSwipeable/index.js +5 -0
- package/lib/module/components/ReanimatedSwipeable/index.js.map +1 -0
- package/lib/module/mocks/Pressable.js +4 -0
- package/lib/module/mocks/Pressable.js.map +1 -0
- package/lib/module/{mocks.js → mocks/mocks.js} +7 -11
- package/lib/module/mocks/mocks.js.map +1 -0
- package/lib/module/web/handlers/GestureHandler.js +1 -0
- package/lib/module/web/handlers/GestureHandler.js.map +1 -1
- package/lib/typescript/ActionType.d.ts +1 -0
- package/lib/typescript/Directions.d.ts +1 -0
- package/lib/typescript/EnableNewWebImplementation.d.ts +1 -0
- package/lib/typescript/GestureHandlerRootViewContext.d.ts +1 -0
- package/lib/typescript/PlatformConstants.d.ts +1 -0
- package/lib/typescript/PlatformConstants.web.d.ts +1 -0
- package/lib/typescript/PointerType.d.ts +1 -0
- package/lib/typescript/RNGestureHandlerModule.d.ts +1 -0
- package/lib/typescript/RNGestureHandlerModule.web.d.ts +1 -0
- package/lib/typescript/RNGestureHandlerModule.windows.d.ts +1 -0
- package/lib/typescript/RNRenderer.d.ts +1 -0
- package/lib/typescript/RNRenderer.web.d.ts +1 -0
- package/lib/typescript/State.d.ts +1 -0
- package/lib/typescript/TouchEventType.d.ts +1 -0
- package/lib/typescript/components/DrawerLayout.d.ts +1 -0
- package/lib/typescript/components/GestureButtons.d.ts +1 -0
- package/lib/typescript/components/GestureButtonsProps.d.ts +10 -1
- package/lib/typescript/components/GestureButtonsProps.d.ts.map +1 -1
- package/lib/typescript/components/GestureComponents.d.ts +1 -0
- package/lib/typescript/components/GestureComponents.web.d.ts +1 -0
- package/lib/typescript/components/GestureHandlerButton.d.ts +1 -0
- package/lib/typescript/components/GestureHandlerButton.web.d.ts +1 -0
- package/lib/typescript/components/GestureHandlerRootView.android.d.ts +1 -0
- package/lib/typescript/components/GestureHandlerRootView.d.ts +1 -0
- package/lib/typescript/components/GestureHandlerRootView.web.d.ts +1 -0
- package/lib/typescript/components/Pressable/Pressable.d.ts +1 -0
- package/lib/typescript/components/Pressable/Pressable.d.ts.map +1 -1
- package/lib/typescript/components/Pressable/PressableProps.d.ts +3 -4
- package/lib/typescript/components/Pressable/PressableProps.d.ts.map +1 -1
- package/lib/typescript/components/Pressable/StateMachine.d.ts +4 -2
- package/lib/typescript/components/Pressable/StateMachine.d.ts.map +1 -1
- package/lib/typescript/components/Pressable/index.d.ts +1 -0
- package/lib/typescript/components/Pressable/stateDefinitions.d.ts +3 -2
- package/lib/typescript/components/Pressable/stateDefinitions.d.ts.map +1 -1
- package/lib/typescript/components/Pressable/utils.d.ts +1 -0
- package/lib/typescript/components/ReanimatedDrawerLayout.d.ts +1 -0
- package/lib/typescript/components/ReanimatedSwipeable/ReanimatedSwipeable.d.ts +6 -0
- package/lib/typescript/components/ReanimatedSwipeable/ReanimatedSwipeable.d.ts.map +1 -0
- package/lib/typescript/components/{ReanimatedSwipeable.d.ts → ReanimatedSwipeable/ReanimatedSwipeableProps.d.ts} +10 -7
- package/lib/typescript/components/ReanimatedSwipeable/ReanimatedSwipeableProps.d.ts.map +1 -0
- package/lib/typescript/components/ReanimatedSwipeable/index.d.ts +3 -0
- package/lib/typescript/components/ReanimatedSwipeable/index.d.ts.map +1 -0
- package/lib/typescript/components/Swipeable.d.ts +1 -0
- package/lib/typescript/components/Text.d.ts +1 -0
- package/lib/typescript/components/gestureHandlerRootHOC.d.ts +1 -0
- package/lib/typescript/components/touchables/ExtraButtonProps.d.ts +1 -0
- package/lib/typescript/components/touchables/GenericTouchable.d.ts +1 -0
- package/lib/typescript/components/touchables/GenericTouchableProps.d.ts +1 -0
- package/lib/typescript/components/touchables/TouchableHighlight.d.ts +1 -0
- package/lib/typescript/components/touchables/TouchableNativeFeedback.android.d.ts +1 -0
- package/lib/typescript/components/touchables/TouchableNativeFeedback.d.ts +1 -0
- package/lib/typescript/components/touchables/TouchableNativeFeedbackProps.d.ts +1 -0
- package/lib/typescript/components/touchables/TouchableOpacity.d.ts +1 -0
- package/lib/typescript/components/touchables/TouchableWithoutFeedback.d.ts +1 -0
- package/lib/typescript/components/touchables/index.d.ts +1 -0
- package/lib/typescript/components/utils.d.ts +1 -0
- package/lib/typescript/findNodeHandle.d.ts +1 -0
- package/lib/typescript/findNodeHandle.web.d.ts +1 -0
- package/lib/typescript/getShadowNodeFromRef.d.ts +1 -0
- package/lib/typescript/getShadowNodeFromRef.web.d.ts +1 -0
- package/lib/typescript/ghQueueMicrotask.d.ts +1 -0
- package/lib/typescript/handlers/FlingGestureHandler.d.ts +1 -0
- package/lib/typescript/handlers/ForceTouchGestureHandler.d.ts +1 -0
- package/lib/typescript/handlers/GestureHandlerEventPayload.d.ts +1 -0
- package/lib/typescript/handlers/LongPressGestureHandler.d.ts +1 -0
- package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +1 -0
- package/lib/typescript/handlers/PanGestureHandler.d.ts +1 -0
- package/lib/typescript/handlers/PinchGestureHandler.d.ts +1 -0
- package/lib/typescript/handlers/PressabilityDebugView.d.ts +1 -0
- package/lib/typescript/handlers/PressabilityDebugView.web.d.ts +1 -0
- package/lib/typescript/handlers/RotationGestureHandler.d.ts +1 -0
- package/lib/typescript/handlers/TapGestureHandler.d.ts +1 -0
- package/lib/typescript/handlers/createHandler.d.ts +1 -0
- package/lib/typescript/handlers/createNativeWrapper.d.ts +1 -0
- package/lib/typescript/handlers/customDirectEventTypes.d.ts +1 -0
- package/lib/typescript/handlers/customDirectEventTypes.web.d.ts +1 -0
- package/lib/typescript/handlers/gestureHandlerCommon.d.ts +1 -0
- package/lib/typescript/handlers/gestureHandlerTypesCompat.d.ts +1 -0
- package/lib/typescript/handlers/gestures/GestureDetector/Wrap.d.ts +1 -0
- package/lib/typescript/handlers/gestures/GestureDetector/Wrap.web.d.ts +1 -0
- package/lib/typescript/handlers/gestures/GestureDetector/attachHandlers.d.ts +1 -0
- package/lib/typescript/handlers/gestures/GestureDetector/dropHandlers.d.ts +1 -0
- package/lib/typescript/handlers/gestures/GestureDetector/index.d.ts +1 -0
- package/lib/typescript/handlers/gestures/GestureDetector/needsToReattach.d.ts +1 -0
- package/lib/typescript/handlers/gestures/GestureDetector/types.d.ts +1 -0
- package/lib/typescript/handlers/gestures/GestureDetector/updateHandlers.d.ts +1 -0
- package/lib/typescript/handlers/gestures/GestureDetector/useAnimatedGesture.d.ts +1 -0
- package/lib/typescript/handlers/gestures/GestureDetector/useDetectorUpdater.d.ts +1 -0
- package/lib/typescript/handlers/gestures/GestureDetector/useMountReactions.d.ts +1 -0
- package/lib/typescript/handlers/gestures/GestureDetector/useViewRefHandler.d.ts +1 -0
- package/lib/typescript/handlers/gestures/GestureDetector/utils.d.ts +1 -0
- package/lib/typescript/handlers/gestures/eventReceiver.d.ts +1 -0
- package/lib/typescript/handlers/gestures/flingGesture.d.ts +1 -0
- package/lib/typescript/handlers/gestures/forceTouchGesture.d.ts +1 -0
- package/lib/typescript/handlers/gestures/gesture.d.ts +1 -0
- package/lib/typescript/handlers/gestures/gestureComposition.d.ts +1 -0
- package/lib/typescript/handlers/gestures/gestureObjects.d.ts +1 -0
- package/lib/typescript/handlers/gestures/gestureStateManager.d.ts +1 -0
- package/lib/typescript/handlers/gestures/gestureStateManager.web.d.ts +1 -0
- package/lib/typescript/handlers/gestures/hoverGesture.d.ts +1 -0
- package/lib/typescript/handlers/gestures/longPressGesture.d.ts +1 -0
- package/lib/typescript/handlers/gestures/manualGesture.d.ts +1 -0
- package/lib/typescript/handlers/gestures/nativeGesture.d.ts +1 -0
- package/lib/typescript/handlers/gestures/panGesture.d.ts +1 -0
- package/lib/typescript/handlers/gestures/pinchGesture.d.ts +1 -0
- package/lib/typescript/handlers/gestures/reanimatedWrapper.d.ts +1 -0
- package/lib/typescript/handlers/gestures/rotationGesture.d.ts +1 -0
- package/lib/typescript/handlers/gestures/tapGesture.d.ts +1 -0
- package/lib/typescript/handlers/getNextHandlerTag.d.ts +1 -0
- package/lib/typescript/handlers/handlersRegistry.d.ts +1 -0
- package/lib/typescript/handlers/utils.d.ts +1 -0
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/init.d.ts +1 -0
- package/lib/typescript/jestUtils/index.d.ts +1 -0
- package/lib/typescript/jestUtils/jestUtils.d.ts +1 -0
- package/lib/typescript/mocks/Pressable.d.ts +2 -0
- package/lib/typescript/mocks/Pressable.d.ts.map +1 -0
- package/lib/typescript/{mocks.d.ts → mocks/mocks.d.ts} +5 -4
- package/lib/typescript/mocks/mocks.d.ts.map +1 -0
- package/lib/typescript/mountRegistry.d.ts +1 -0
- package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +1 -0
- package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +1 -0
- package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +1 -0
- package/lib/typescript/typeUtils.d.ts +1 -0
- package/lib/typescript/utils.d.ts +1 -0
- package/lib/typescript/web/Gestures.d.ts +1 -0
- package/lib/typescript/web/constants.d.ts +1 -0
- package/lib/typescript/web/detectors/RotationGestureDetector.d.ts +1 -0
- package/lib/typescript/web/detectors/ScaleGestureDetector.d.ts +1 -0
- package/lib/typescript/web/handlers/FlingGestureHandler.d.ts +1 -0
- package/lib/typescript/web/handlers/GestureHandler.d.ts +1 -0
- package/lib/typescript/web/handlers/GestureHandler.d.ts.map +1 -1
- package/lib/typescript/web/handlers/HoverGestureHandler.d.ts +1 -0
- package/lib/typescript/web/handlers/IGestureHandler.d.ts +1 -0
- package/lib/typescript/web/handlers/LongPressGestureHandler.d.ts +1 -0
- package/lib/typescript/web/handlers/ManualGestureHandler.d.ts +1 -0
- package/lib/typescript/web/handlers/NativeViewGestureHandler.d.ts +1 -0
- package/lib/typescript/web/handlers/PanGestureHandler.d.ts +1 -0
- package/lib/typescript/web/handlers/PinchGestureHandler.d.ts +1 -0
- package/lib/typescript/web/handlers/RotationGestureHandler.d.ts +1 -0
- package/lib/typescript/web/handlers/TapGestureHandler.d.ts +1 -0
- package/lib/typescript/web/interfaces.d.ts +1 -0
- package/lib/typescript/web/tools/CircularBuffer.d.ts +1 -0
- package/lib/typescript/web/tools/EventManager.d.ts +1 -0
- package/lib/typescript/web/tools/GestureHandlerDelegate.d.ts +1 -0
- package/lib/typescript/web/tools/GestureHandlerOrchestrator.d.ts +1 -0
- package/lib/typescript/web/tools/GestureHandlerWebDelegate.d.ts +1 -0
- package/lib/typescript/web/tools/InteractionManager.d.ts +1 -0
- package/lib/typescript/web/tools/KeyboardEventManager.d.ts +1 -0
- package/lib/typescript/web/tools/LeastSquareSolver.d.ts +1 -0
- package/lib/typescript/web/tools/NodeManager.d.ts +1 -0
- package/lib/typescript/web/tools/PointerEventManager.d.ts +1 -0
- package/lib/typescript/web/tools/PointerTracker.d.ts +1 -0
- package/lib/typescript/web/tools/Vector.d.ts +1 -0
- package/lib/typescript/web/tools/VelocityTracker.d.ts +1 -0
- package/lib/typescript/web/tools/WheelEventManager.d.ts +1 -0
- package/lib/typescript/web/utils.d.ts +1 -0
- package/lib/typescript/web_hammer/DiscreteGestureHandler.d.ts +1 -0
- package/lib/typescript/web_hammer/DraggingGestureHandler.d.ts +1 -0
- package/lib/typescript/web_hammer/Errors.d.ts +1 -0
- package/lib/typescript/web_hammer/FlingGestureHandler.d.ts +1 -0
- package/lib/typescript/web_hammer/GestureHandler.d.ts +1 -0
- package/lib/typescript/web_hammer/IndiscreteGestureHandler.d.ts +1 -0
- package/lib/typescript/web_hammer/LongPressGestureHandler.d.ts +1 -0
- package/lib/typescript/web_hammer/NativeViewGestureHandler.d.ts +1 -0
- package/lib/typescript/web_hammer/NodeManager.d.ts +1 -0
- package/lib/typescript/web_hammer/PanGestureHandler.d.ts +1 -0
- package/lib/typescript/web_hammer/PinchGestureHandler.d.ts +1 -0
- package/lib/typescript/web_hammer/PressGestureHandler.d.ts +1 -0
- package/lib/typescript/web_hammer/RotationGestureHandler.d.ts +1 -0
- package/lib/typescript/web_hammer/TapGestureHandler.d.ts +1 -0
- package/lib/typescript/web_hammer/constants.d.ts +1 -0
- package/lib/typescript/web_hammer/utils.d.ts +1 -0
- package/package.json +1 -1
- package/src/components/GestureButtonsProps.ts +10 -0
- package/src/components/Pressable/Pressable.tsx +20 -31
- package/src/components/Pressable/PressableProps.tsx +2 -4
- package/src/components/Pressable/StateMachine.tsx +12 -4
- package/src/components/Pressable/stateDefinitions.ts +23 -23
- package/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx +603 -0
- package/src/components/ReanimatedSwipeable/ReanimatedSwipeableProps.ts +199 -0
- package/src/components/ReanimatedSwipeable/index.ts +6 -0
- package/src/mocks/Pressable.tsx +1 -0
- package/src/{mocks.tsx → mocks/mocks.tsx} +7 -11
- package/src/web/handlers/GestureHandler.ts +1 -0
- package/lib/commonjs/components/ReanimatedSwipeable.js.map +0 -1
- package/lib/commonjs/mocks.js.map +0 -1
- package/lib/module/components/ReanimatedSwipeable.js.map +0 -1
- package/lib/module/mocks.js.map +0 -1
- package/lib/typescript/ActionType.js +0 -6
- package/lib/typescript/Directions.js +0 -18
- package/lib/typescript/EnableNewWebImplementation.js +0 -30
- package/lib/typescript/GestureHandlerRootViewContext.js +0 -2
- package/lib/typescript/PlatformConstants.js +0 -3
- package/lib/typescript/PlatformConstants.web.js +0 -5
- package/lib/typescript/PointerType.js +0 -8
- package/lib/typescript/RNGestureHandlerModule.js +0 -4
- package/lib/typescript/RNGestureHandlerModule.web.js +0 -92
- package/lib/typescript/RNGestureHandlerModule.windows.js +0 -47
- package/lib/typescript/RNRenderer.js +0 -3
- package/lib/typescript/RNRenderer.web.js +0 -3
- package/lib/typescript/State.js +0 -9
- package/lib/typescript/TouchEventType.js +0 -7
- package/lib/typescript/components/DrawerLayout.js +0 -417
- package/lib/typescript/components/GestureButtons.js +0 -165
- package/lib/typescript/components/GestureButtonsProps.js +0 -1
- package/lib/typescript/components/GestureComponents.js +0 -67
- package/lib/typescript/components/GestureComponents.web.js +0 -21
- package/lib/typescript/components/GestureHandlerButton.js +0 -2
- package/lib/typescript/components/GestureHandlerButton.web.js +0 -3
- package/lib/typescript/components/GestureHandlerRootView.android.js +0 -17
- package/lib/typescript/components/GestureHandlerRootView.js +0 -16
- package/lib/typescript/components/GestureHandlerRootView.web.js +0 -11
- package/lib/typescript/components/Pressable/Pressable.js +0 -231
- package/lib/typescript/components/Pressable/PressableProps.js +0 -1
- package/lib/typescript/components/Pressable/StateMachine.js +0 -34
- package/lib/typescript/components/Pressable/index.js +0 -1
- package/lib/typescript/components/Pressable/stateDefinitions.js +0 -104
- package/lib/typescript/components/Pressable/utils.js +0 -80
- package/lib/typescript/components/ReanimatedDrawerLayout.js +0 -364
- package/lib/typescript/components/ReanimatedSwipeable.d.ts.map +0 -1
- package/lib/typescript/components/ReanimatedSwipeable.js +0 -400
- package/lib/typescript/components/Swipeable.js +0 -287
- package/lib/typescript/components/Text.js +0 -38
- package/lib/typescript/components/gestureHandlerRootHOC.js +0 -18
- package/lib/typescript/components/touchables/ExtraButtonProps.js +0 -1
- package/lib/typescript/components/touchables/GenericTouchable.js +0 -221
- package/lib/typescript/components/touchables/GenericTouchableProps.js +0 -1
- package/lib/typescript/components/touchables/TouchableHighlight.js +0 -75
- package/lib/typescript/components/touchables/TouchableNativeFeedback.android.js +0 -65
- package/lib/typescript/components/touchables/TouchableNativeFeedback.js +0 -6
- package/lib/typescript/components/touchables/TouchableNativeFeedbackProps.js +0 -1
- package/lib/typescript/components/touchables/TouchableOpacity.js +0 -51
- package/lib/typescript/components/touchables/TouchableWithoutFeedback.js +0 -10
- package/lib/typescript/components/touchables/index.js +0 -4
- package/lib/typescript/components/utils.js +0 -11
- package/lib/typescript/findNodeHandle.js +0 -2
- package/lib/typescript/findNodeHandle.web.js +0 -31
- package/lib/typescript/getShadowNodeFromRef.js +0 -45
- package/lib/typescript/getShadowNodeFromRef.web.js +0 -7
- package/lib/typescript/ghQueueMicrotask.js +0 -7
- package/lib/typescript/handlers/FlingGestureHandler.js +0 -19
- package/lib/typescript/handlers/ForceTouchGestureHandler.js +0 -37
- package/lib/typescript/handlers/GestureHandlerEventPayload.js +0 -1
- package/lib/typescript/handlers/LongPressGestureHandler.js +0 -22
- package/lib/typescript/handlers/NativeViewGestureHandler.js +0 -20
- package/lib/typescript/handlers/PanGestureHandler.js +0 -128
- package/lib/typescript/handlers/PinchGestureHandler.js +0 -12
- package/lib/typescript/handlers/PressabilityDebugView.js +0 -2
- package/lib/typescript/handlers/PressabilityDebugView.web.js +0 -4
- package/lib/typescript/handlers/RotationGestureHandler.js +0 -12
- package/lib/typescript/handlers/TapGestureHandler.js +0 -26
- package/lib/typescript/handlers/createHandler.js +0 -375
- package/lib/typescript/handlers/createNativeWrapper.js +0 -67
- package/lib/typescript/handlers/customDirectEventTypes.js +0 -2
- package/lib/typescript/handlers/customDirectEventTypes.web.js +0 -4
- package/lib/typescript/handlers/gestureHandlerCommon.js +0 -42
- package/lib/typescript/handlers/gestureHandlerTypesCompat.js +0 -1
- package/lib/typescript/handlers/gestures/GestureDetector/Wrap.js +0 -22
- package/lib/typescript/handlers/gestures/GestureDetector/Wrap.web.js +0 -24
- package/lib/typescript/handlers/gestures/GestureDetector/attachHandlers.js +0 -55
- package/lib/typescript/handlers/gestures/GestureDetector/dropHandlers.js +0 -12
- package/lib/typescript/handlers/gestures/GestureDetector/index.js +0 -114
- package/lib/typescript/handlers/gestures/GestureDetector/needsToReattach.js +0 -18
- package/lib/typescript/handlers/gestures/GestureDetector/types.js +0 -1
- package/lib/typescript/handlers/gestures/GestureDetector/updateHandlers.js +0 -54
- package/lib/typescript/handlers/gestures/GestureDetector/useAnimatedGesture.js +0 -137
- package/lib/typescript/handlers/gestures/GestureDetector/useDetectorUpdater.js +0 -48
- package/lib/typescript/handlers/gestures/GestureDetector/useMountReactions.js +0 -35
- package/lib/typescript/handlers/gestures/GestureDetector/useViewRefHandler.js +0 -32
- package/lib/typescript/handlers/gestures/GestureDetector/utils.js +0 -140
- package/lib/typescript/handlers/gestures/eventReceiver.js +0 -105
- package/lib/typescript/handlers/gestures/flingGesture.js +0 -27
- package/lib/typescript/handlers/gestures/forceTouchGesture.js +0 -57
- package/lib/typescript/handlers/gestures/gesture.js +0 -303
- package/lib/typescript/handlers/gestures/gestureComposition.js +0 -78
- package/lib/typescript/handlers/gestures/gestureObjects.js +0 -125
- package/lib/typescript/handlers/gestures/gestureStateManager.js +0 -60
- package/lib/typescript/handlers/gestures/gestureStateManager.web.js +0 -19
- package/lib/typescript/handlers/gestures/hoverGesture.js +0 -45
- package/lib/typescript/handlers/gestures/longPressGesture.js +0 -35
- package/lib/typescript/handlers/gestures/manualGesture.js +0 -16
- package/lib/typescript/handlers/gestures/nativeGesture.js +0 -24
- package/lib/typescript/handlers/gestures/panGesture.js +0 -181
- package/lib/typescript/handlers/gestures/pinchGesture.js +0 -27
- package/lib/typescript/handlers/gestures/reanimatedWrapper.js +0 -23
- package/lib/typescript/handlers/gestures/rotationGesture.js +0 -27
- package/lib/typescript/handlers/gestures/tapGesture.js +0 -72
- package/lib/typescript/handlers/getNextHandlerTag.js +0 -4
- package/lib/typescript/handlers/handlersRegistry.js +0 -36
- package/lib/typescript/handlers/utils.js +0 -58
- package/lib/typescript/index.js +0 -28
- package/lib/typescript/init.js +0 -15
- package/lib/typescript/jestUtils/index.js +0 -1
- package/lib/typescript/jestUtils/jestUtils.js +0 -290
- package/lib/typescript/mocks.d.ts.map +0 -1
- package/lib/typescript/mocks.js +0 -59
- package/lib/typescript/mountRegistry.js +0 -29
- package/lib/typescript/specs/NativeRNGestureHandlerModule.js +0 -2
- package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.js +0 -2
- package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.js +0 -2
- package/lib/typescript/typeUtils.js +0 -1
- package/lib/typescript/utils.js +0 -80
- package/lib/typescript/web/Gestures.js +0 -38
- package/lib/typescript/web/constants.js +0 -2
- package/lib/typescript/web/detectors/RotationGestureDetector.js +0 -122
- package/lib/typescript/web/detectors/ScaleGestureDetector.js +0 -117
- package/lib/typescript/web/handlers/FlingGestureHandler.js +0 -133
- package/lib/typescript/web/handlers/GestureHandler.js +0 -656
- package/lib/typescript/web/handlers/HoverGestureHandler.js +0 -37
- package/lib/typescript/web/handlers/IGestureHandler.js +0 -1
- package/lib/typescript/web/handlers/LongPressGestureHandler.js +0 -136
- package/lib/typescript/web/handlers/ManualGestureHandler.js +0 -29
- package/lib/typescript/web/handlers/NativeViewGestureHandler.js +0 -133
- package/lib/typescript/web/handlers/PanGestureHandler.js +0 -420
- package/lib/typescript/web/handlers/PinchGestureHandler.js +0 -117
- package/lib/typescript/web/handlers/RotationGestureHandler.js +0 -122
- package/lib/typescript/web/handlers/TapGestureHandler.js +0 -202
- package/lib/typescript/web/interfaces.js +0 -25
- package/lib/typescript/web/tools/CircularBuffer.js +0 -37
- package/lib/typescript/web/tools/EventManager.js +0 -85
- package/lib/typescript/web/tools/GestureHandlerDelegate.js +0 -1
- package/lib/typescript/web/tools/GestureHandlerOrchestrator.js +0 -273
- package/lib/typescript/web/tools/GestureHandlerWebDelegate.js +0 -169
- package/lib/typescript/web/tools/InteractionManager.js +0 -91
- package/lib/typescript/web/tools/KeyboardEventManager.js +0 -73
- package/lib/typescript/web/tools/LeastSquareSolver.js +0 -147
- package/lib/typescript/web/tools/NodeManager.js +0 -28
- package/lib/typescript/web/tools/PointerEventManager.js +0 -179
- package/lib/typescript/web/tools/PointerTracker.js +0 -161
- package/lib/typescript/web/tools/Vector.js +0 -43
- package/lib/typescript/web/tools/VelocityTracker.js +0 -76
- package/lib/typescript/web/tools/WheelEventManager.js +0 -40
- package/lib/typescript/web/utils.js +0 -233
- package/lib/typescript/web_hammer/DiscreteGestureHandler.js +0 -48
- package/lib/typescript/web_hammer/DraggingGestureHandler.js +0 -25
- package/lib/typescript/web_hammer/Errors.js +0 -5
- package/lib/typescript/web_hammer/FlingGestureHandler.js +0 -119
- package/lib/typescript/web_hammer/GestureHandler.js +0 -469
- package/lib/typescript/web_hammer/IndiscreteGestureHandler.js +0 -26
- package/lib/typescript/web_hammer/LongPressGestureHandler.js +0 -46
- package/lib/typescript/web_hammer/NativeViewGestureHandler.js +0 -40
- package/lib/typescript/web_hammer/NodeManager.js +0 -28
- package/lib/typescript/web_hammer/PanGestureHandler.js +0 -151
- package/lib/typescript/web_hammer/PinchGestureHandler.js +0 -19
- package/lib/typescript/web_hammer/PressGestureHandler.js +0 -133
- package/lib/typescript/web_hammer/RotationGestureHandler.js +0 -20
- package/lib/typescript/web_hammer/TapGestureHandler.js +0 -142
- package/lib/typescript/web_hammer/constants.js +0 -42
- package/lib/typescript/web_hammer/utils.js +0 -15
- package/src/components/ReanimatedSwipeable.tsx +0 -811
@@ -0,0 +1,603 @@
|
|
1
|
+
import { useMemo, useCallback, useImperativeHandle, ForwardedRef } from 'react';
|
2
|
+
import { LayoutChangeEvent, View, I18nManager, StyleSheet } from 'react-native';
|
3
|
+
import Animated, {
|
4
|
+
useSharedValue,
|
5
|
+
interpolate,
|
6
|
+
runOnJS,
|
7
|
+
ReduceMotion,
|
8
|
+
withSpring,
|
9
|
+
useAnimatedRef,
|
10
|
+
measure,
|
11
|
+
runOnUI,
|
12
|
+
useAnimatedStyle,
|
13
|
+
} from 'react-native-reanimated';
|
14
|
+
import { SwipeableProps, SwipeableMethods, SwipeDirection } from '.';
|
15
|
+
import { Gesture } from '../..';
|
16
|
+
import {
|
17
|
+
GestureStateChangeEvent,
|
18
|
+
GestureUpdateEvent,
|
19
|
+
} from '../../handlers/gestureHandlerCommon';
|
20
|
+
import { PanGestureHandlerEventPayload } from '../../handlers/GestureHandlerEventPayload';
|
21
|
+
import { GestureDetector } from '../../handlers/gestures/GestureDetector';
|
22
|
+
import {
|
23
|
+
applyRelationProp,
|
24
|
+
RelationPropName,
|
25
|
+
RelationPropType,
|
26
|
+
} from '../utils';
|
27
|
+
|
28
|
+
const DRAG_TOSS = 0.05;
|
29
|
+
|
30
|
+
const DEFAULT_FRICTION = 1;
|
31
|
+
const DEFAULT_OVERSHOOT_FRICTION = 1;
|
32
|
+
const DEFAULT_DRAG_OFFSET = 10;
|
33
|
+
const DEFAULT_ENABLE_TRACKING_TWO_FINGER_GESTURE = false;
|
34
|
+
|
35
|
+
const Swipeable = (props: SwipeableProps) => {
|
36
|
+
const {
|
37
|
+
ref,
|
38
|
+
leftThreshold,
|
39
|
+
rightThreshold,
|
40
|
+
enabled,
|
41
|
+
containerStyle,
|
42
|
+
childrenContainerStyle,
|
43
|
+
animationOptions,
|
44
|
+
overshootLeft,
|
45
|
+
overshootRight,
|
46
|
+
testID,
|
47
|
+
children,
|
48
|
+
enableTrackpadTwoFingerGesture = DEFAULT_ENABLE_TRACKING_TWO_FINGER_GESTURE,
|
49
|
+
dragOffsetFromLeftEdge = DEFAULT_DRAG_OFFSET,
|
50
|
+
dragOffsetFromRightEdge = DEFAULT_DRAG_OFFSET,
|
51
|
+
friction = DEFAULT_FRICTION,
|
52
|
+
overshootFriction = DEFAULT_OVERSHOOT_FRICTION,
|
53
|
+
onSwipeableOpenStartDrag,
|
54
|
+
onSwipeableCloseStartDrag,
|
55
|
+
onSwipeableWillOpen,
|
56
|
+
onSwipeableWillClose,
|
57
|
+
onSwipeableOpen,
|
58
|
+
onSwipeableClose,
|
59
|
+
renderLeftActions,
|
60
|
+
renderRightActions,
|
61
|
+
simultaneousWithExternalGesture,
|
62
|
+
requireExternalGestureToFail,
|
63
|
+
blocksExternalGesture,
|
64
|
+
hitSlop,
|
65
|
+
...remainingProps
|
66
|
+
} = props;
|
67
|
+
|
68
|
+
const relationProps = useMemo(
|
69
|
+
() => ({
|
70
|
+
simultaneousWithExternalGesture,
|
71
|
+
requireExternalGestureToFail,
|
72
|
+
blocksExternalGesture,
|
73
|
+
}),
|
74
|
+
[
|
75
|
+
blocksExternalGesture,
|
76
|
+
requireExternalGestureToFail,
|
77
|
+
simultaneousWithExternalGesture,
|
78
|
+
]
|
79
|
+
);
|
80
|
+
|
81
|
+
const rowState = useSharedValue<number>(0);
|
82
|
+
|
83
|
+
const userDrag = useSharedValue<number>(0);
|
84
|
+
|
85
|
+
const appliedTranslation = useSharedValue<number>(0);
|
86
|
+
|
87
|
+
const rowWidth = useSharedValue<number>(0);
|
88
|
+
const leftWidth = useSharedValue<number>(0);
|
89
|
+
const rightWidth = useSharedValue<number>(0);
|
90
|
+
|
91
|
+
const showLeftProgress = useSharedValue<number>(0);
|
92
|
+
const showRightProgress = useSharedValue<number>(0);
|
93
|
+
|
94
|
+
const updateAnimatedEvent = useCallback(() => {
|
95
|
+
'worklet';
|
96
|
+
|
97
|
+
const shouldOvershootLeft = overshootLeft ?? leftWidth.value > 0;
|
98
|
+
const shouldOvershootRight = overshootRight ?? rightWidth.value > 0;
|
99
|
+
|
100
|
+
const startOffset =
|
101
|
+
rowState.value === 1
|
102
|
+
? leftWidth.value
|
103
|
+
: rowState.value === -1
|
104
|
+
? -rightWidth.value
|
105
|
+
: 0;
|
106
|
+
|
107
|
+
const offsetDrag = userDrag.value / friction + startOffset;
|
108
|
+
|
109
|
+
appliedTranslation.value = interpolate(
|
110
|
+
offsetDrag,
|
111
|
+
[
|
112
|
+
-rightWidth.value - 1,
|
113
|
+
-rightWidth.value,
|
114
|
+
leftWidth.value,
|
115
|
+
leftWidth.value + 1,
|
116
|
+
],
|
117
|
+
[
|
118
|
+
-rightWidth.value - (shouldOvershootRight ? 1 / overshootFriction : 0),
|
119
|
+
-rightWidth.value,
|
120
|
+
leftWidth.value,
|
121
|
+
leftWidth.value + (shouldOvershootLeft ? 1 / overshootFriction : 0),
|
122
|
+
]
|
123
|
+
);
|
124
|
+
|
125
|
+
showLeftProgress.value =
|
126
|
+
leftWidth.value > 0
|
127
|
+
? interpolate(
|
128
|
+
appliedTranslation.value,
|
129
|
+
[-1, 0, leftWidth.value],
|
130
|
+
[0, 0, 1]
|
131
|
+
)
|
132
|
+
: 0;
|
133
|
+
|
134
|
+
showRightProgress.value =
|
135
|
+
rightWidth.value > 0
|
136
|
+
? interpolate(
|
137
|
+
appliedTranslation.value,
|
138
|
+
[-rightWidth.value, 0, 1],
|
139
|
+
[1, 0, 0]
|
140
|
+
)
|
141
|
+
: 0;
|
142
|
+
}, [
|
143
|
+
appliedTranslation,
|
144
|
+
friction,
|
145
|
+
leftWidth,
|
146
|
+
overshootFriction,
|
147
|
+
rightWidth,
|
148
|
+
rowState,
|
149
|
+
showLeftProgress,
|
150
|
+
showRightProgress,
|
151
|
+
userDrag,
|
152
|
+
overshootLeft,
|
153
|
+
overshootRight,
|
154
|
+
]);
|
155
|
+
|
156
|
+
const dispatchImmediateEvents = useCallback(
|
157
|
+
(fromValue: number, toValue: number) => {
|
158
|
+
'worklet';
|
159
|
+
|
160
|
+
if (onSwipeableWillOpen && toValue !== 0) {
|
161
|
+
runOnJS(onSwipeableWillOpen)(
|
162
|
+
toValue > 0 ? SwipeDirection.RIGHT : SwipeDirection.LEFT
|
163
|
+
);
|
164
|
+
}
|
165
|
+
|
166
|
+
if (onSwipeableWillClose && toValue === 0) {
|
167
|
+
runOnJS(onSwipeableWillClose)(
|
168
|
+
fromValue > 0 ? SwipeDirection.LEFT : SwipeDirection.RIGHT
|
169
|
+
);
|
170
|
+
}
|
171
|
+
},
|
172
|
+
[onSwipeableWillClose, onSwipeableWillOpen]
|
173
|
+
);
|
174
|
+
|
175
|
+
const dispatchEndEvents = useCallback(
|
176
|
+
(fromValue: number, toValue: number) => {
|
177
|
+
'worklet';
|
178
|
+
|
179
|
+
if (onSwipeableOpen && toValue !== 0) {
|
180
|
+
runOnJS(onSwipeableOpen)(
|
181
|
+
toValue > 0 ? SwipeDirection.RIGHT : SwipeDirection.LEFT
|
182
|
+
);
|
183
|
+
}
|
184
|
+
|
185
|
+
if (onSwipeableClose && toValue === 0) {
|
186
|
+
runOnJS(onSwipeableClose)(
|
187
|
+
fromValue > 0 ? SwipeDirection.LEFT : SwipeDirection.RIGHT
|
188
|
+
);
|
189
|
+
}
|
190
|
+
},
|
191
|
+
[onSwipeableClose, onSwipeableOpen]
|
192
|
+
);
|
193
|
+
|
194
|
+
const animateRow: (toValue: number, velocityX?: number) => void = useCallback(
|
195
|
+
(toValue: number, velocityX?: number) => {
|
196
|
+
'worklet';
|
197
|
+
|
198
|
+
const translationSpringConfig = {
|
199
|
+
mass: 2,
|
200
|
+
damping: 1000,
|
201
|
+
stiffness: 700,
|
202
|
+
velocity: velocityX,
|
203
|
+
overshootClamping: true,
|
204
|
+
reduceMotion: ReduceMotion.System,
|
205
|
+
...animationOptions,
|
206
|
+
};
|
207
|
+
|
208
|
+
const isClosing = toValue === 0;
|
209
|
+
const moveToRight = isClosing ? rowState.value < 0 : toValue > 0;
|
210
|
+
|
211
|
+
const usedWidth = isClosing
|
212
|
+
? moveToRight
|
213
|
+
? rightWidth.value
|
214
|
+
: leftWidth.value
|
215
|
+
: moveToRight
|
216
|
+
? leftWidth.value
|
217
|
+
: rightWidth.value;
|
218
|
+
|
219
|
+
const progressSpringConfig = {
|
220
|
+
...translationSpringConfig,
|
221
|
+
restDisplacementThreshold: 0.01,
|
222
|
+
restSpeedThreshold: 0.01,
|
223
|
+
velocity:
|
224
|
+
velocityX && interpolate(velocityX, [-usedWidth, usedWidth], [-1, 1]),
|
225
|
+
};
|
226
|
+
|
227
|
+
const frozenRowState = rowState.value;
|
228
|
+
|
229
|
+
appliedTranslation.value = withSpring(
|
230
|
+
toValue,
|
231
|
+
translationSpringConfig,
|
232
|
+
(isFinished) => {
|
233
|
+
if (isFinished) {
|
234
|
+
dispatchEndEvents(frozenRowState, toValue);
|
235
|
+
}
|
236
|
+
}
|
237
|
+
);
|
238
|
+
|
239
|
+
const progressTarget = toValue === 0 ? 0 : 1 * Math.sign(toValue);
|
240
|
+
|
241
|
+
showLeftProgress.value = withSpring(
|
242
|
+
Math.max(progressTarget, 0),
|
243
|
+
progressSpringConfig
|
244
|
+
);
|
245
|
+
|
246
|
+
showRightProgress.value = withSpring(
|
247
|
+
Math.max(-progressTarget, 0),
|
248
|
+
progressSpringConfig
|
249
|
+
);
|
250
|
+
|
251
|
+
dispatchImmediateEvents(frozenRowState, toValue);
|
252
|
+
|
253
|
+
rowState.value = Math.sign(toValue);
|
254
|
+
},
|
255
|
+
[
|
256
|
+
rowState,
|
257
|
+
animationOptions,
|
258
|
+
appliedTranslation,
|
259
|
+
showLeftProgress,
|
260
|
+
leftWidth,
|
261
|
+
showRightProgress,
|
262
|
+
rightWidth,
|
263
|
+
dispatchImmediateEvents,
|
264
|
+
dispatchEndEvents,
|
265
|
+
]
|
266
|
+
);
|
267
|
+
|
268
|
+
const leftLayoutRef = useAnimatedRef();
|
269
|
+
const leftWrapperLayoutRef = useAnimatedRef();
|
270
|
+
const rightLayoutRef = useAnimatedRef();
|
271
|
+
|
272
|
+
const updateElementWidths = useCallback(() => {
|
273
|
+
'worklet';
|
274
|
+
const leftLayout = measure(leftLayoutRef);
|
275
|
+
const leftWrapperLayout = measure(leftWrapperLayoutRef);
|
276
|
+
const rightLayout = measure(rightLayoutRef);
|
277
|
+
leftWidth.value =
|
278
|
+
(leftLayout?.pageX ?? 0) - (leftWrapperLayout?.pageX ?? 0);
|
279
|
+
|
280
|
+
rightWidth.value =
|
281
|
+
rowWidth.value -
|
282
|
+
(rightLayout?.pageX ?? rowWidth.value) +
|
283
|
+
(leftWrapperLayout?.pageX ?? 0);
|
284
|
+
}, [
|
285
|
+
leftLayoutRef,
|
286
|
+
leftWrapperLayoutRef,
|
287
|
+
rightLayoutRef,
|
288
|
+
leftWidth,
|
289
|
+
rightWidth,
|
290
|
+
rowWidth,
|
291
|
+
]);
|
292
|
+
|
293
|
+
const swipeableMethods = useMemo<SwipeableMethods>(
|
294
|
+
() => ({
|
295
|
+
close() {
|
296
|
+
'worklet';
|
297
|
+
if (_WORKLET) {
|
298
|
+
animateRow(0);
|
299
|
+
return;
|
300
|
+
}
|
301
|
+
runOnUI(() => {
|
302
|
+
animateRow(0);
|
303
|
+
})();
|
304
|
+
},
|
305
|
+
openLeft() {
|
306
|
+
'worklet';
|
307
|
+
if (_WORKLET) {
|
308
|
+
updateElementWidths();
|
309
|
+
animateRow(leftWidth.value);
|
310
|
+
return;
|
311
|
+
}
|
312
|
+
runOnUI(() => {
|
313
|
+
updateElementWidths();
|
314
|
+
animateRow(leftWidth.value);
|
315
|
+
})();
|
316
|
+
},
|
317
|
+
openRight() {
|
318
|
+
'worklet';
|
319
|
+
if (_WORKLET) {
|
320
|
+
updateElementWidths();
|
321
|
+
animateRow(-rightWidth.value);
|
322
|
+
return;
|
323
|
+
}
|
324
|
+
runOnUI(() => {
|
325
|
+
updateElementWidths();
|
326
|
+
animateRow(-rightWidth.value);
|
327
|
+
})();
|
328
|
+
},
|
329
|
+
reset() {
|
330
|
+
'worklet';
|
331
|
+
userDrag.value = 0;
|
332
|
+
showLeftProgress.value = 0;
|
333
|
+
appliedTranslation.value = 0;
|
334
|
+
rowState.value = 0;
|
335
|
+
},
|
336
|
+
}),
|
337
|
+
[
|
338
|
+
animateRow,
|
339
|
+
updateElementWidths,
|
340
|
+
leftWidth,
|
341
|
+
rightWidth,
|
342
|
+
userDrag,
|
343
|
+
showLeftProgress,
|
344
|
+
appliedTranslation,
|
345
|
+
rowState,
|
346
|
+
]
|
347
|
+
);
|
348
|
+
|
349
|
+
const onRowLayout = useCallback(
|
350
|
+
({ nativeEvent }: LayoutChangeEvent) => {
|
351
|
+
rowWidth.value = nativeEvent.layout.width;
|
352
|
+
},
|
353
|
+
[rowWidth]
|
354
|
+
);
|
355
|
+
|
356
|
+
// As stated in `Dimensions.get` docstring, this function should be called on every render
|
357
|
+
// since dimensions may change (e.g. orientation change)
|
358
|
+
|
359
|
+
const leftActionAnimation = useAnimatedStyle(() => {
|
360
|
+
return {
|
361
|
+
opacity: showLeftProgress.value === 0 ? 0 : 1,
|
362
|
+
};
|
363
|
+
});
|
364
|
+
|
365
|
+
const leftElement = useCallback(
|
366
|
+
() => (
|
367
|
+
<Animated.View
|
368
|
+
ref={leftWrapperLayoutRef}
|
369
|
+
style={[styles.leftActions, leftActionAnimation]}>
|
370
|
+
{renderLeftActions?.(
|
371
|
+
showLeftProgress,
|
372
|
+
appliedTranslation,
|
373
|
+
swipeableMethods
|
374
|
+
)}
|
375
|
+
<Animated.View ref={leftLayoutRef} />
|
376
|
+
</Animated.View>
|
377
|
+
),
|
378
|
+
[
|
379
|
+
appliedTranslation,
|
380
|
+
leftActionAnimation,
|
381
|
+
leftLayoutRef,
|
382
|
+
leftWrapperLayoutRef,
|
383
|
+
renderLeftActions,
|
384
|
+
showLeftProgress,
|
385
|
+
swipeableMethods,
|
386
|
+
]
|
387
|
+
);
|
388
|
+
|
389
|
+
const rightActionAnimation = useAnimatedStyle(() => {
|
390
|
+
return {
|
391
|
+
opacity: showRightProgress.value === 0 ? 0 : 1,
|
392
|
+
};
|
393
|
+
});
|
394
|
+
|
395
|
+
const rightElement = useCallback(
|
396
|
+
() => (
|
397
|
+
<Animated.View style={[styles.rightActions, rightActionAnimation]}>
|
398
|
+
{renderRightActions?.(
|
399
|
+
showRightProgress,
|
400
|
+
appliedTranslation,
|
401
|
+
swipeableMethods
|
402
|
+
)}
|
403
|
+
<Animated.View ref={rightLayoutRef} />
|
404
|
+
</Animated.View>
|
405
|
+
),
|
406
|
+
[
|
407
|
+
appliedTranslation,
|
408
|
+
renderRightActions,
|
409
|
+
rightActionAnimation,
|
410
|
+
rightLayoutRef,
|
411
|
+
showRightProgress,
|
412
|
+
swipeableMethods,
|
413
|
+
]
|
414
|
+
);
|
415
|
+
|
416
|
+
const handleRelease = useCallback(
|
417
|
+
(event: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
|
418
|
+
'worklet';
|
419
|
+
const { velocityX } = event;
|
420
|
+
userDrag.value = event.translationX;
|
421
|
+
|
422
|
+
const leftThresholdProp = leftThreshold ?? leftWidth.value / 2;
|
423
|
+
const rightThresholdProp = rightThreshold ?? rightWidth.value / 2;
|
424
|
+
|
425
|
+
const translationX = (userDrag.value + DRAG_TOSS * velocityX) / friction;
|
426
|
+
|
427
|
+
let toValue = 0;
|
428
|
+
|
429
|
+
if (rowState.value === 0) {
|
430
|
+
if (translationX > leftThresholdProp) {
|
431
|
+
toValue = leftWidth.value;
|
432
|
+
} else if (translationX < -rightThresholdProp) {
|
433
|
+
toValue = -rightWidth.value;
|
434
|
+
}
|
435
|
+
} else if (rowState.value === 1) {
|
436
|
+
// Swiped to left
|
437
|
+
if (translationX > -leftThresholdProp) {
|
438
|
+
toValue = leftWidth.value;
|
439
|
+
}
|
440
|
+
} else {
|
441
|
+
// Swiped to right
|
442
|
+
if (translationX < rightThresholdProp) {
|
443
|
+
toValue = -rightWidth.value;
|
444
|
+
}
|
445
|
+
}
|
446
|
+
|
447
|
+
animateRow(toValue, velocityX / friction);
|
448
|
+
},
|
449
|
+
[
|
450
|
+
animateRow,
|
451
|
+
friction,
|
452
|
+
leftThreshold,
|
453
|
+
leftWidth,
|
454
|
+
rightThreshold,
|
455
|
+
rightWidth,
|
456
|
+
rowState,
|
457
|
+
userDrag,
|
458
|
+
]
|
459
|
+
);
|
460
|
+
|
461
|
+
const close = useCallback(() => {
|
462
|
+
'worklet';
|
463
|
+
animateRow(0);
|
464
|
+
}, [animateRow]);
|
465
|
+
|
466
|
+
const dragStarted = useSharedValue<boolean>(false);
|
467
|
+
|
468
|
+
const tapGesture = useMemo(() => {
|
469
|
+
const tap = Gesture.Tap()
|
470
|
+
.shouldCancelWhenOutside(true)
|
471
|
+
.onStart(() => {
|
472
|
+
if (rowState.value !== 0) {
|
473
|
+
close();
|
474
|
+
}
|
475
|
+
});
|
476
|
+
|
477
|
+
Object.entries(relationProps).forEach(([relationName, relation]) => {
|
478
|
+
applyRelationProp(
|
479
|
+
tap,
|
480
|
+
relationName as RelationPropName,
|
481
|
+
relation as RelationPropType
|
482
|
+
);
|
483
|
+
});
|
484
|
+
|
485
|
+
return tap;
|
486
|
+
}, [close, relationProps, rowState]);
|
487
|
+
|
488
|
+
const panGesture = useMemo(() => {
|
489
|
+
const pan = Gesture.Pan()
|
490
|
+
.enabled(enabled !== false)
|
491
|
+
.enableTrackpadTwoFingerGesture(enableTrackpadTwoFingerGesture)
|
492
|
+
.activeOffsetX([-dragOffsetFromRightEdge, dragOffsetFromLeftEdge])
|
493
|
+
.onStart(updateElementWidths)
|
494
|
+
.onUpdate((event: GestureUpdateEvent<PanGestureHandlerEventPayload>) => {
|
495
|
+
userDrag.value = event.translationX;
|
496
|
+
|
497
|
+
const direction =
|
498
|
+
rowState.value === -1
|
499
|
+
? SwipeDirection.RIGHT
|
500
|
+
: rowState.value === 1
|
501
|
+
? SwipeDirection.LEFT
|
502
|
+
: event.translationX > 0
|
503
|
+
? SwipeDirection.RIGHT
|
504
|
+
: SwipeDirection.LEFT;
|
505
|
+
|
506
|
+
if (!dragStarted.value) {
|
507
|
+
dragStarted.value = true;
|
508
|
+
if (rowState.value === 0 && onSwipeableOpenStartDrag) {
|
509
|
+
runOnJS(onSwipeableOpenStartDrag)(direction);
|
510
|
+
} else if (onSwipeableCloseStartDrag) {
|
511
|
+
runOnJS(onSwipeableCloseStartDrag)(direction);
|
512
|
+
}
|
513
|
+
}
|
514
|
+
|
515
|
+
updateAnimatedEvent();
|
516
|
+
})
|
517
|
+
.onEnd(
|
518
|
+
(event: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
|
519
|
+
handleRelease(event);
|
520
|
+
}
|
521
|
+
)
|
522
|
+
.onFinalize(() => {
|
523
|
+
dragStarted.value = false;
|
524
|
+
});
|
525
|
+
|
526
|
+
Object.entries(relationProps).forEach(([relationName, relation]) => {
|
527
|
+
applyRelationProp(
|
528
|
+
pan,
|
529
|
+
relationName as RelationPropName,
|
530
|
+
relation as RelationPropType
|
531
|
+
);
|
532
|
+
});
|
533
|
+
|
534
|
+
return pan;
|
535
|
+
}, [
|
536
|
+
enabled,
|
537
|
+
enableTrackpadTwoFingerGesture,
|
538
|
+
dragOffsetFromRightEdge,
|
539
|
+
dragOffsetFromLeftEdge,
|
540
|
+
updateElementWidths,
|
541
|
+
relationProps,
|
542
|
+
userDrag,
|
543
|
+
rowState,
|
544
|
+
dragStarted,
|
545
|
+
updateAnimatedEvent,
|
546
|
+
onSwipeableOpenStartDrag,
|
547
|
+
onSwipeableCloseStartDrag,
|
548
|
+
handleRelease,
|
549
|
+
]);
|
550
|
+
|
551
|
+
useImperativeHandle(ref, () => swipeableMethods, [swipeableMethods]);
|
552
|
+
|
553
|
+
const animatedStyle = useAnimatedStyle(
|
554
|
+
() => ({
|
555
|
+
transform: [{ translateX: appliedTranslation.value }],
|
556
|
+
pointerEvents: rowState.value === 0 ? 'auto' : 'box-only',
|
557
|
+
}),
|
558
|
+
[appliedTranslation, rowState]
|
559
|
+
);
|
560
|
+
|
561
|
+
const swipeableComponent = (
|
562
|
+
<GestureDetector gesture={panGesture} touchAction="pan-y">
|
563
|
+
<Animated.View
|
564
|
+
{...remainingProps}
|
565
|
+
onLayout={onRowLayout}
|
566
|
+
hitSlop={hitSlop ?? undefined}
|
567
|
+
style={[styles.container, containerStyle]}>
|
568
|
+
{leftElement()}
|
569
|
+
{rightElement()}
|
570
|
+
<GestureDetector gesture={tapGesture} touchAction="pan-y">
|
571
|
+
<Animated.View style={[animatedStyle, childrenContainerStyle]}>
|
572
|
+
{children}
|
573
|
+
</Animated.View>
|
574
|
+
</GestureDetector>
|
575
|
+
</Animated.View>
|
576
|
+
</GestureDetector>
|
577
|
+
);
|
578
|
+
|
579
|
+
return testID ? (
|
580
|
+
<View testID={testID}>{swipeableComponent}</View>
|
581
|
+
) : (
|
582
|
+
swipeableComponent
|
583
|
+
);
|
584
|
+
};
|
585
|
+
|
586
|
+
export default Swipeable;
|
587
|
+
export type SwipeableRef = ForwardedRef<SwipeableMethods>;
|
588
|
+
|
589
|
+
const styles = StyleSheet.create({
|
590
|
+
container: {
|
591
|
+
overflow: 'hidden',
|
592
|
+
},
|
593
|
+
leftActions: {
|
594
|
+
...StyleSheet.absoluteFillObject,
|
595
|
+
flexDirection: I18nManager.isRTL ? 'row-reverse' : 'row',
|
596
|
+
overflow: 'hidden',
|
597
|
+
},
|
598
|
+
rightActions: {
|
599
|
+
...StyleSheet.absoluteFillObject,
|
600
|
+
flexDirection: I18nManager.isRTL ? 'row' : 'row-reverse',
|
601
|
+
overflow: 'hidden',
|
602
|
+
},
|
603
|
+
});
|