react-native-gesture-handler 2.27.1 → 2.28.0
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/RNGestureHandler.podspec +3 -2
- package/ReanimatedSwipeable/package.json +4 -4
- 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/android/src/main/jni/CMakeLists.txt +5 -0
- package/android/src/main/jni/cpp-adapter.cpp +6 -0
- package/apple/RNGestureHandler.h +4 -0
- package/apple/RNGestureHandler.mm +41 -6
- package/apple/RNGestureHandlerModule.mm +5 -0
- 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/components/gestureHandlerRootHOC.js +4 -1
- package/lib/commonjs/components/gestureHandlerRootHOC.js.map +1 -1
- package/lib/commonjs/handlers/createHandler.js +1 -1
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/index.js +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/index.js.map +1 -1
- 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 +5 -2
- package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
- package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js +0 -5
- package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/commonjs/web/tools/KeyboardEventManager.js +34 -8
- package/lib/commonjs/web/tools/KeyboardEventManager.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/components/gestureHandlerRootHOC.js +5 -0
- package/lib/module/components/gestureHandlerRootHOC.js.map +1 -1
- package/lib/module/handlers/createHandler.js +1 -1
- package/lib/module/handlers/createHandler.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/index.js +1 -1
- package/lib/module/handlers/gestures/GestureDetector/index.js.map +1 -1
- 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 +5 -2
- package/lib/module/web/handlers/GestureHandler.js.map +1 -1
- package/lib/module/web/tools/GestureHandlerWebDelegate.js +0 -5
- package/lib/module/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/module/web/tools/KeyboardEventManager.js +34 -8
- package/lib/module/web/tools/KeyboardEventManager.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 +5 -0
- package/lib/typescript/components/gestureHandlerRootHOC.d.ts.map +1 -1
- 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/GestureHandlerWebDelegate.d.ts.map +1 -1
- package/lib/typescript/web/tools/InteractionManager.d.ts +1 -0
- package/lib/typescript/web/tools/KeyboardEventManager.d.ts +7 -3
- package/lib/typescript/web/tools/KeyboardEventManager.d.ts.map +1 -1
- 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 +4 -3
- package/scripts/gesture_handler_utils.rb +25 -0
- 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/components/gestureHandlerRootHOC.tsx +4 -0
- package/src/handlers/createHandler.tsx +1 -1
- package/src/handlers/gestures/GestureDetector/index.tsx +1 -1
- package/src/mocks/Pressable.tsx +1 -0
- package/src/{mocks.tsx → mocks/mocks.tsx} +7 -11
- package/src/web/handlers/GestureHandler.ts +8 -3
- package/src/web/tools/GestureHandlerWebDelegate.ts +0 -5
- package/src/web/tools/KeyboardEventManager.ts +50 -8
- 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
@@ -1,811 +0,0 @@
|
|
1
|
-
// Similarily to the DrawerLayout component this deserves to be put in a
|
2
|
-
// separate repo. Although, keeping it here for the time being will allow us to
|
3
|
-
// move faster and fix possible issues quicker
|
4
|
-
|
5
|
-
import React, {
|
6
|
-
ForwardedRef,
|
7
|
-
forwardRef,
|
8
|
-
useCallback,
|
9
|
-
useImperativeHandle,
|
10
|
-
useMemo,
|
11
|
-
} from 'react';
|
12
|
-
import { GestureObjects as Gesture } from '../handlers/gestures/gestureObjects';
|
13
|
-
import { GestureDetector } from '../handlers/gestures/GestureDetector';
|
14
|
-
import {
|
15
|
-
GestureStateChangeEvent,
|
16
|
-
GestureUpdateEvent,
|
17
|
-
} from '../handlers/gestureHandlerCommon';
|
18
|
-
import type { PanGestureHandlerProps } from '../handlers/PanGestureHandler';
|
19
|
-
import type { PanGestureHandlerEventPayload } from '../handlers/GestureHandlerEventPayload';
|
20
|
-
import Animated, {
|
21
|
-
ReduceMotion,
|
22
|
-
SharedValue,
|
23
|
-
interpolate,
|
24
|
-
measure,
|
25
|
-
runOnJS,
|
26
|
-
runOnUI,
|
27
|
-
useAnimatedRef,
|
28
|
-
useAnimatedStyle,
|
29
|
-
useSharedValue,
|
30
|
-
withSpring,
|
31
|
-
} from 'react-native-reanimated';
|
32
|
-
import {
|
33
|
-
I18nManager,
|
34
|
-
LayoutChangeEvent,
|
35
|
-
StyleProp,
|
36
|
-
StyleSheet,
|
37
|
-
View,
|
38
|
-
ViewStyle,
|
39
|
-
} from 'react-native';
|
40
|
-
import { applyRelationProp, RelationPropName, RelationPropType } from './utils';
|
41
|
-
|
42
|
-
const DRAG_TOSS = 0.05;
|
43
|
-
|
44
|
-
type SwipeableExcludes = Exclude<
|
45
|
-
keyof PanGestureHandlerProps,
|
46
|
-
'onGestureEvent' | 'onHandlerStateChange'
|
47
|
-
>;
|
48
|
-
|
49
|
-
enum SwipeDirection {
|
50
|
-
LEFT = 'left',
|
51
|
-
RIGHT = 'right',
|
52
|
-
}
|
53
|
-
|
54
|
-
export interface SwipeableProps
|
55
|
-
extends Pick<PanGestureHandlerProps, SwipeableExcludes> {
|
56
|
-
/**
|
57
|
-
* Enables two-finger gestures on supported devices, for example iPads with
|
58
|
-
* trackpads. If not enabled the gesture will require click + drag, with
|
59
|
-
* `enableTrackpadTwoFingerGesture` swiping with two fingers will also trigger
|
60
|
-
* the gesture.
|
61
|
-
*/
|
62
|
-
enableTrackpadTwoFingerGesture?: boolean;
|
63
|
-
|
64
|
-
/**
|
65
|
-
* Specifies how much the visual interaction will be delayed compared to the
|
66
|
-
* gesture distance. e.g. value of 1 will indicate that the swipeable panel
|
67
|
-
* should exactly follow the gesture, 2 means it is going to be two times
|
68
|
-
* "slower".
|
69
|
-
*/
|
70
|
-
friction?: number;
|
71
|
-
|
72
|
-
/**
|
73
|
-
* Distance from the left edge at which released panel will animate to the
|
74
|
-
* open state (or the open panel will animate into the closed state). By
|
75
|
-
* default it's a half of the panel's width.
|
76
|
-
*/
|
77
|
-
leftThreshold?: number;
|
78
|
-
|
79
|
-
/**
|
80
|
-
* Distance from the right edge at which released panel will animate to the
|
81
|
-
* open state (or the open panel will animate into the closed state). By
|
82
|
-
* default it's a half of the panel's width.
|
83
|
-
*/
|
84
|
-
rightThreshold?: number;
|
85
|
-
|
86
|
-
/**
|
87
|
-
* Distance that the panel must be dragged from the left edge to be considered
|
88
|
-
* a swipe. The default value is 10.
|
89
|
-
*/
|
90
|
-
dragOffsetFromLeftEdge?: number;
|
91
|
-
|
92
|
-
/**
|
93
|
-
* Distance that the panel must be dragged from the right edge to be considered
|
94
|
-
* a swipe. The default value is 10.
|
95
|
-
*/
|
96
|
-
dragOffsetFromRightEdge?: number;
|
97
|
-
|
98
|
-
/**
|
99
|
-
* Value indicating if the swipeable panel can be pulled further than the left
|
100
|
-
* actions panel's width. It is set to true by default as long as the left
|
101
|
-
* panel render method is present.
|
102
|
-
*/
|
103
|
-
overshootLeft?: boolean;
|
104
|
-
|
105
|
-
/**
|
106
|
-
* Value indicating if the swipeable panel can be pulled further than the
|
107
|
-
* right actions panel's width. It is set to true by default as long as the
|
108
|
-
* right panel render method is present.
|
109
|
-
*/
|
110
|
-
overshootRight?: boolean;
|
111
|
-
|
112
|
-
/**
|
113
|
-
* Specifies how much the visual interaction will be delayed compared to the
|
114
|
-
* gesture distance at overshoot. Default value is 1, it mean no friction, for
|
115
|
-
* a native feel, try 8 or above.
|
116
|
-
*/
|
117
|
-
overshootFriction?: number;
|
118
|
-
|
119
|
-
/**
|
120
|
-
* Called when action panel gets open (either right or left).
|
121
|
-
*/
|
122
|
-
onSwipeableOpen?: (
|
123
|
-
direction: SwipeDirection.LEFT | SwipeDirection.RIGHT
|
124
|
-
) => void;
|
125
|
-
|
126
|
-
/**
|
127
|
-
* Called when action panel is closed.
|
128
|
-
*/
|
129
|
-
onSwipeableClose?: (
|
130
|
-
direction: SwipeDirection.LEFT | SwipeDirection.RIGHT
|
131
|
-
) => void;
|
132
|
-
|
133
|
-
/**
|
134
|
-
* Called when action panel starts animating on open (either right or left).
|
135
|
-
*/
|
136
|
-
onSwipeableWillOpen?: (
|
137
|
-
direction: SwipeDirection.LEFT | SwipeDirection.RIGHT
|
138
|
-
) => void;
|
139
|
-
|
140
|
-
/**
|
141
|
-
* Called when action panel starts animating on close.
|
142
|
-
*/
|
143
|
-
onSwipeableWillClose?: (
|
144
|
-
direction: SwipeDirection.LEFT | SwipeDirection.RIGHT
|
145
|
-
) => void;
|
146
|
-
|
147
|
-
/**
|
148
|
-
* Called when action panel starts being shown on dragging to open.
|
149
|
-
*/
|
150
|
-
onSwipeableOpenStartDrag?: (
|
151
|
-
direction: SwipeDirection.LEFT | SwipeDirection.RIGHT
|
152
|
-
) => void;
|
153
|
-
|
154
|
-
/**
|
155
|
-
* Called when action panel starts being shown on dragging to close.
|
156
|
-
*/
|
157
|
-
onSwipeableCloseStartDrag?: (
|
158
|
-
direction: SwipeDirection.LEFT | SwipeDirection.RIGHT
|
159
|
-
) => void;
|
160
|
-
|
161
|
-
/**
|
162
|
-
* `progress`: Equals `0` when `swipeable` is closed, `1` when `swipeable` is opened.
|
163
|
-
* - When the element overshoots it's opened position the value tends towards `Infinity`.
|
164
|
-
* - Goes back to `1` when `swipeable` is released.
|
165
|
-
*
|
166
|
-
* `translation`: a horizontal offset of the `swipeable` relative to its closed position.\
|
167
|
-
* `swipeableMethods`: provides an object exposing methods for controlling the `swipeable`.
|
168
|
-
*
|
169
|
-
* To support `rtl` flexbox layouts use `flexDirection` styling.
|
170
|
-
* */
|
171
|
-
renderLeftActions?: (
|
172
|
-
progress: SharedValue<number>,
|
173
|
-
translation: SharedValue<number>,
|
174
|
-
swipeableMethods: SwipeableMethods
|
175
|
-
) => React.ReactNode;
|
176
|
-
|
177
|
-
/**
|
178
|
-
* `progress`: Equals `0` when `swipeable` is closed, `1` when `swipeable` is opened.
|
179
|
-
* - When the element overshoots it's opened position the value tends towards `Infinity`.
|
180
|
-
* - Goes back to `1` when `swipeable` is released.
|
181
|
-
*
|
182
|
-
* `translation`: a horizontal offset of the `swipeable` relative to its closed position.\
|
183
|
-
* `swipeableMethods`: provides an object exposing methods for controlling the `swipeable`.
|
184
|
-
*
|
185
|
-
* To support `rtl` flexbox layouts use `flexDirection` styling.
|
186
|
-
* */
|
187
|
-
renderRightActions?: (
|
188
|
-
progress: SharedValue<number>,
|
189
|
-
translation: SharedValue<number>,
|
190
|
-
swipeableMethods: SwipeableMethods
|
191
|
-
) => React.ReactNode;
|
192
|
-
|
193
|
-
animationOptions?: Record<string, unknown>;
|
194
|
-
|
195
|
-
/**
|
196
|
-
* Style object for the container (`Animated.View`), for example to override
|
197
|
-
* `overflow: 'hidden'`.
|
198
|
-
*/
|
199
|
-
containerStyle?: StyleProp<ViewStyle>;
|
200
|
-
|
201
|
-
/**
|
202
|
-
* Style object for the children container (`Animated.View`), for example to
|
203
|
-
* apply `flex: 1`
|
204
|
-
*/
|
205
|
-
childrenContainerStyle?: StyleProp<ViewStyle>;
|
206
|
-
|
207
|
-
/**
|
208
|
-
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
|
209
|
-
* used with the swipeable's gesture handler.
|
210
|
-
*/
|
211
|
-
simultaneousWithExternalGesture?: RelationPropType;
|
212
|
-
|
213
|
-
/**
|
214
|
-
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
|
215
|
-
* used with the swipeable's gesture handler.
|
216
|
-
*/
|
217
|
-
requireExternalGestureToFail?: RelationPropType;
|
218
|
-
|
219
|
-
/**
|
220
|
-
* A gesture object or an array of gesture objects containing the configuration and callbacks to be
|
221
|
-
* used with the swipeable's gesture handler.
|
222
|
-
*/
|
223
|
-
blocksExternalGesture?: RelationPropType;
|
224
|
-
}
|
225
|
-
|
226
|
-
export interface SwipeableMethods {
|
227
|
-
close: () => void;
|
228
|
-
openLeft: () => void;
|
229
|
-
openRight: () => void;
|
230
|
-
reset: () => void;
|
231
|
-
}
|
232
|
-
|
233
|
-
const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
|
234
|
-
function Swipeable(
|
235
|
-
props: SwipeableProps,
|
236
|
-
ref: ForwardedRef<SwipeableMethods>
|
237
|
-
) {
|
238
|
-
const defaultProps = {
|
239
|
-
friction: 1,
|
240
|
-
overshootFriction: 1,
|
241
|
-
dragOffset: 10,
|
242
|
-
enableTrackpadTwoFingerGesture: false,
|
243
|
-
};
|
244
|
-
|
245
|
-
const {
|
246
|
-
leftThreshold,
|
247
|
-
rightThreshold,
|
248
|
-
enabled,
|
249
|
-
containerStyle,
|
250
|
-
childrenContainerStyle,
|
251
|
-
animationOptions,
|
252
|
-
overshootLeft,
|
253
|
-
overshootRight,
|
254
|
-
testID,
|
255
|
-
children,
|
256
|
-
enableTrackpadTwoFingerGesture = defaultProps.enableTrackpadTwoFingerGesture,
|
257
|
-
dragOffsetFromLeftEdge = defaultProps.dragOffset,
|
258
|
-
dragOffsetFromRightEdge = defaultProps.dragOffset,
|
259
|
-
friction = defaultProps.friction,
|
260
|
-
overshootFriction = defaultProps.overshootFriction,
|
261
|
-
onSwipeableOpenStartDrag,
|
262
|
-
onSwipeableCloseStartDrag,
|
263
|
-
onSwipeableWillOpen,
|
264
|
-
onSwipeableWillClose,
|
265
|
-
onSwipeableOpen,
|
266
|
-
onSwipeableClose,
|
267
|
-
renderLeftActions,
|
268
|
-
renderRightActions,
|
269
|
-
simultaneousWithExternalGesture,
|
270
|
-
requireExternalGestureToFail,
|
271
|
-
blocksExternalGesture,
|
272
|
-
hitSlop,
|
273
|
-
...remainingProps
|
274
|
-
} = props;
|
275
|
-
|
276
|
-
const relationProps = {
|
277
|
-
simultaneousWithExternalGesture,
|
278
|
-
requireExternalGestureToFail,
|
279
|
-
blocksExternalGesture,
|
280
|
-
};
|
281
|
-
|
282
|
-
const rowState = useSharedValue<number>(0);
|
283
|
-
|
284
|
-
const userDrag = useSharedValue<number>(0);
|
285
|
-
|
286
|
-
const appliedTranslation = useSharedValue<number>(0);
|
287
|
-
|
288
|
-
const rowWidth = useSharedValue<number>(0);
|
289
|
-
const leftWidth = useSharedValue<number>(0);
|
290
|
-
const rightWidth = useSharedValue<number>(0);
|
291
|
-
|
292
|
-
const showLeftProgress = useSharedValue<number>(0);
|
293
|
-
const showRightProgress = useSharedValue<number>(0);
|
294
|
-
|
295
|
-
const updateAnimatedEvent = useCallback(() => {
|
296
|
-
'worklet';
|
297
|
-
|
298
|
-
const shouldOvershootLeft = overshootLeft ?? leftWidth.value > 0;
|
299
|
-
const shouldOvershootRight = overshootRight ?? rightWidth.value > 0;
|
300
|
-
|
301
|
-
const startOffset =
|
302
|
-
rowState.value === 1
|
303
|
-
? leftWidth.value
|
304
|
-
: rowState.value === -1
|
305
|
-
? -rightWidth.value
|
306
|
-
: 0;
|
307
|
-
|
308
|
-
const offsetDrag = userDrag.value / friction + startOffset;
|
309
|
-
|
310
|
-
appliedTranslation.value = interpolate(
|
311
|
-
offsetDrag,
|
312
|
-
[
|
313
|
-
-rightWidth.value - 1,
|
314
|
-
-rightWidth.value,
|
315
|
-
leftWidth.value,
|
316
|
-
leftWidth.value + 1,
|
317
|
-
],
|
318
|
-
[
|
319
|
-
-rightWidth.value -
|
320
|
-
(shouldOvershootRight ? 1 / overshootFriction : 0),
|
321
|
-
-rightWidth.value,
|
322
|
-
leftWidth.value,
|
323
|
-
leftWidth.value + (shouldOvershootLeft ? 1 / overshootFriction : 0),
|
324
|
-
]
|
325
|
-
);
|
326
|
-
|
327
|
-
showLeftProgress.value =
|
328
|
-
leftWidth.value > 0
|
329
|
-
? interpolate(
|
330
|
-
appliedTranslation.value,
|
331
|
-
[-1, 0, leftWidth.value],
|
332
|
-
[0, 0, 1]
|
333
|
-
)
|
334
|
-
: 0;
|
335
|
-
|
336
|
-
showRightProgress.value =
|
337
|
-
rightWidth.value > 0
|
338
|
-
? interpolate(
|
339
|
-
appliedTranslation.value,
|
340
|
-
[-rightWidth.value, 0, 1],
|
341
|
-
[1, 0, 0]
|
342
|
-
)
|
343
|
-
: 0;
|
344
|
-
}, [
|
345
|
-
appliedTranslation,
|
346
|
-
friction,
|
347
|
-
leftWidth,
|
348
|
-
overshootFriction,
|
349
|
-
rightWidth,
|
350
|
-
rowState,
|
351
|
-
showLeftProgress,
|
352
|
-
showRightProgress,
|
353
|
-
userDrag,
|
354
|
-
overshootLeft,
|
355
|
-
overshootRight,
|
356
|
-
]);
|
357
|
-
|
358
|
-
const dispatchImmediateEvents = useCallback(
|
359
|
-
(fromValue: number, toValue: number) => {
|
360
|
-
'worklet';
|
361
|
-
|
362
|
-
if (onSwipeableWillOpen && toValue !== 0) {
|
363
|
-
runOnJS(onSwipeableWillOpen)(
|
364
|
-
toValue > 0 ? SwipeDirection.RIGHT : SwipeDirection.LEFT
|
365
|
-
);
|
366
|
-
}
|
367
|
-
|
368
|
-
if (onSwipeableWillClose && toValue === 0) {
|
369
|
-
runOnJS(onSwipeableWillClose)(
|
370
|
-
fromValue > 0 ? SwipeDirection.LEFT : SwipeDirection.RIGHT
|
371
|
-
);
|
372
|
-
}
|
373
|
-
},
|
374
|
-
[onSwipeableWillClose, onSwipeableWillOpen, rowState]
|
375
|
-
);
|
376
|
-
|
377
|
-
const dispatchEndEvents = useCallback(
|
378
|
-
(fromValue: number, toValue: number) => {
|
379
|
-
'worklet';
|
380
|
-
|
381
|
-
if (onSwipeableOpen && toValue !== 0) {
|
382
|
-
runOnJS(onSwipeableOpen)(
|
383
|
-
toValue > 0 ? SwipeDirection.RIGHT : SwipeDirection.LEFT
|
384
|
-
);
|
385
|
-
}
|
386
|
-
|
387
|
-
if (onSwipeableClose && toValue === 0) {
|
388
|
-
runOnJS(onSwipeableClose)(
|
389
|
-
fromValue > 0 ? SwipeDirection.LEFT : SwipeDirection.RIGHT
|
390
|
-
);
|
391
|
-
}
|
392
|
-
},
|
393
|
-
[onSwipeableClose, onSwipeableOpen]
|
394
|
-
);
|
395
|
-
|
396
|
-
const animateRow: (toValue: number, velocityX?: number) => void =
|
397
|
-
useCallback(
|
398
|
-
(toValue: number, velocityX?: number) => {
|
399
|
-
'worklet';
|
400
|
-
|
401
|
-
const translationSpringConfig = {
|
402
|
-
mass: 2,
|
403
|
-
damping: 1000,
|
404
|
-
stiffness: 700,
|
405
|
-
velocity: velocityX,
|
406
|
-
overshootClamping: true,
|
407
|
-
reduceMotion: ReduceMotion.System,
|
408
|
-
...animationOptions,
|
409
|
-
};
|
410
|
-
|
411
|
-
const isClosing = toValue === 0;
|
412
|
-
const moveToRight = isClosing ? rowState.value < 0 : toValue > 0;
|
413
|
-
|
414
|
-
const usedWidth = isClosing
|
415
|
-
? moveToRight
|
416
|
-
? rightWidth.value
|
417
|
-
: leftWidth.value
|
418
|
-
: moveToRight
|
419
|
-
? leftWidth.value
|
420
|
-
: rightWidth.value;
|
421
|
-
|
422
|
-
const progressSpringConfig = {
|
423
|
-
...translationSpringConfig,
|
424
|
-
restDisplacementThreshold: 0.01,
|
425
|
-
restSpeedThreshold: 0.01,
|
426
|
-
velocity:
|
427
|
-
velocityX &&
|
428
|
-
interpolate(velocityX, [-usedWidth, usedWidth], [-1, 1]),
|
429
|
-
};
|
430
|
-
|
431
|
-
const frozenRowState = rowState.value;
|
432
|
-
|
433
|
-
appliedTranslation.value = withSpring(
|
434
|
-
toValue,
|
435
|
-
translationSpringConfig,
|
436
|
-
(isFinished) => {
|
437
|
-
if (isFinished) {
|
438
|
-
dispatchEndEvents(frozenRowState, toValue);
|
439
|
-
}
|
440
|
-
}
|
441
|
-
);
|
442
|
-
|
443
|
-
const progressTarget = toValue === 0 ? 0 : 1 * Math.sign(toValue);
|
444
|
-
|
445
|
-
showLeftProgress.value = withSpring(
|
446
|
-
Math.max(progressTarget, 0),
|
447
|
-
progressSpringConfig
|
448
|
-
);
|
449
|
-
|
450
|
-
showRightProgress.value = withSpring(
|
451
|
-
Math.max(-progressTarget, 0),
|
452
|
-
progressSpringConfig
|
453
|
-
);
|
454
|
-
|
455
|
-
dispatchImmediateEvents(frozenRowState, toValue);
|
456
|
-
|
457
|
-
rowState.value = Math.sign(toValue);
|
458
|
-
},
|
459
|
-
[
|
460
|
-
rowState,
|
461
|
-
animationOptions,
|
462
|
-
appliedTranslation,
|
463
|
-
showLeftProgress,
|
464
|
-
leftWidth,
|
465
|
-
showRightProgress,
|
466
|
-
rightWidth,
|
467
|
-
dispatchImmediateEvents,
|
468
|
-
dispatchEndEvents,
|
469
|
-
]
|
470
|
-
);
|
471
|
-
|
472
|
-
const leftLayoutRef = useAnimatedRef();
|
473
|
-
const leftWrapperLayoutRef = useAnimatedRef();
|
474
|
-
const rightLayoutRef = useAnimatedRef();
|
475
|
-
|
476
|
-
const updateElementWidths = useCallback(() => {
|
477
|
-
'worklet';
|
478
|
-
const leftLayout = measure(leftLayoutRef);
|
479
|
-
const leftWrapperLayout = measure(leftWrapperLayoutRef);
|
480
|
-
const rightLayout = measure(rightLayoutRef);
|
481
|
-
leftWidth.value =
|
482
|
-
(leftLayout?.pageX ?? 0) - (leftWrapperLayout?.pageX ?? 0);
|
483
|
-
|
484
|
-
rightWidth.value =
|
485
|
-
rowWidth.value -
|
486
|
-
(rightLayout?.pageX ?? rowWidth.value) +
|
487
|
-
(leftWrapperLayout?.pageX ?? 0);
|
488
|
-
}, [
|
489
|
-
leftLayoutRef,
|
490
|
-
leftWrapperLayoutRef,
|
491
|
-
rightLayoutRef,
|
492
|
-
leftWidth,
|
493
|
-
rightWidth,
|
494
|
-
rowWidth,
|
495
|
-
]);
|
496
|
-
|
497
|
-
const swipeableMethods = useMemo<SwipeableMethods>(
|
498
|
-
() => ({
|
499
|
-
close() {
|
500
|
-
'worklet';
|
501
|
-
if (_WORKLET) {
|
502
|
-
animateRow(0);
|
503
|
-
return;
|
504
|
-
}
|
505
|
-
runOnUI(() => {
|
506
|
-
animateRow(0);
|
507
|
-
})();
|
508
|
-
},
|
509
|
-
openLeft() {
|
510
|
-
'worklet';
|
511
|
-
if (_WORKLET) {
|
512
|
-
updateElementWidths();
|
513
|
-
animateRow(leftWidth.value);
|
514
|
-
return;
|
515
|
-
}
|
516
|
-
runOnUI(() => {
|
517
|
-
updateElementWidths();
|
518
|
-
animateRow(leftWidth.value);
|
519
|
-
})();
|
520
|
-
},
|
521
|
-
openRight() {
|
522
|
-
'worklet';
|
523
|
-
if (_WORKLET) {
|
524
|
-
updateElementWidths();
|
525
|
-
animateRow(-rightWidth.value);
|
526
|
-
return;
|
527
|
-
}
|
528
|
-
runOnUI(() => {
|
529
|
-
updateElementWidths();
|
530
|
-
animateRow(-rightWidth.value);
|
531
|
-
})();
|
532
|
-
},
|
533
|
-
reset() {
|
534
|
-
'worklet';
|
535
|
-
userDrag.value = 0;
|
536
|
-
showLeftProgress.value = 0;
|
537
|
-
appliedTranslation.value = 0;
|
538
|
-
rowState.value = 0;
|
539
|
-
},
|
540
|
-
}),
|
541
|
-
[
|
542
|
-
animateRow,
|
543
|
-
updateElementWidths,
|
544
|
-
leftWidth,
|
545
|
-
rightWidth,
|
546
|
-
userDrag,
|
547
|
-
showLeftProgress,
|
548
|
-
appliedTranslation,
|
549
|
-
rowState,
|
550
|
-
]
|
551
|
-
);
|
552
|
-
|
553
|
-
const onRowLayout = useCallback(
|
554
|
-
({ nativeEvent }: LayoutChangeEvent) => {
|
555
|
-
rowWidth.value = nativeEvent.layout.width;
|
556
|
-
},
|
557
|
-
[rowWidth]
|
558
|
-
);
|
559
|
-
|
560
|
-
// As stated in `Dimensions.get` docstring, this function should be called on every render
|
561
|
-
// since dimensions may change (e.g. orientation change)
|
562
|
-
|
563
|
-
const leftActionAnimation = useAnimatedStyle(() => {
|
564
|
-
return {
|
565
|
-
opacity: showLeftProgress.value === 0 ? 0 : 1,
|
566
|
-
};
|
567
|
-
});
|
568
|
-
|
569
|
-
const leftElement = useCallback(
|
570
|
-
() => (
|
571
|
-
<Animated.View
|
572
|
-
ref={leftWrapperLayoutRef}
|
573
|
-
style={[styles.leftActions, leftActionAnimation]}>
|
574
|
-
{renderLeftActions?.(
|
575
|
-
showLeftProgress,
|
576
|
-
appliedTranslation,
|
577
|
-
swipeableMethods
|
578
|
-
)}
|
579
|
-
<Animated.View ref={leftLayoutRef} />
|
580
|
-
</Animated.View>
|
581
|
-
),
|
582
|
-
[
|
583
|
-
appliedTranslation,
|
584
|
-
leftActionAnimation,
|
585
|
-
leftLayoutRef,
|
586
|
-
leftWrapperLayoutRef,
|
587
|
-
renderLeftActions,
|
588
|
-
showLeftProgress,
|
589
|
-
swipeableMethods,
|
590
|
-
]
|
591
|
-
);
|
592
|
-
|
593
|
-
const rightActionAnimation = useAnimatedStyle(() => {
|
594
|
-
return {
|
595
|
-
opacity: showRightProgress.value === 0 ? 0 : 1,
|
596
|
-
};
|
597
|
-
});
|
598
|
-
|
599
|
-
const rightElement = useCallback(
|
600
|
-
() => (
|
601
|
-
<Animated.View style={[styles.rightActions, rightActionAnimation]}>
|
602
|
-
{renderRightActions?.(
|
603
|
-
showRightProgress,
|
604
|
-
appliedTranslation,
|
605
|
-
swipeableMethods
|
606
|
-
)}
|
607
|
-
<Animated.View ref={rightLayoutRef} />
|
608
|
-
</Animated.View>
|
609
|
-
),
|
610
|
-
[
|
611
|
-
appliedTranslation,
|
612
|
-
renderRightActions,
|
613
|
-
rightActionAnimation,
|
614
|
-
rightLayoutRef,
|
615
|
-
showRightProgress,
|
616
|
-
swipeableMethods,
|
617
|
-
]
|
618
|
-
);
|
619
|
-
|
620
|
-
const handleRelease = useCallback(
|
621
|
-
(event: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
|
622
|
-
'worklet';
|
623
|
-
const { velocityX } = event;
|
624
|
-
userDrag.value = event.translationX;
|
625
|
-
|
626
|
-
const leftThresholdProp = leftThreshold ?? leftWidth.value / 2;
|
627
|
-
const rightThresholdProp = rightThreshold ?? rightWidth.value / 2;
|
628
|
-
|
629
|
-
const translationX =
|
630
|
-
(userDrag.value + DRAG_TOSS * velocityX) / friction;
|
631
|
-
|
632
|
-
let toValue = 0;
|
633
|
-
|
634
|
-
if (rowState.value === 0) {
|
635
|
-
if (translationX > leftThresholdProp) {
|
636
|
-
toValue = leftWidth.value;
|
637
|
-
} else if (translationX < -rightThresholdProp) {
|
638
|
-
toValue = -rightWidth.value;
|
639
|
-
}
|
640
|
-
} else if (rowState.value === 1) {
|
641
|
-
// Swiped to left
|
642
|
-
if (translationX > -leftThresholdProp) {
|
643
|
-
toValue = leftWidth.value;
|
644
|
-
}
|
645
|
-
} else {
|
646
|
-
// Swiped to right
|
647
|
-
if (translationX < rightThresholdProp) {
|
648
|
-
toValue = -rightWidth.value;
|
649
|
-
}
|
650
|
-
}
|
651
|
-
|
652
|
-
animateRow(toValue, velocityX / friction);
|
653
|
-
},
|
654
|
-
[
|
655
|
-
animateRow,
|
656
|
-
friction,
|
657
|
-
leftThreshold,
|
658
|
-
leftWidth,
|
659
|
-
rightThreshold,
|
660
|
-
rightWidth,
|
661
|
-
rowState,
|
662
|
-
userDrag,
|
663
|
-
]
|
664
|
-
);
|
665
|
-
|
666
|
-
const close = useCallback(() => {
|
667
|
-
'worklet';
|
668
|
-
animateRow(0);
|
669
|
-
}, [animateRow]);
|
670
|
-
|
671
|
-
const dragStarted = useSharedValue<boolean>(false);
|
672
|
-
|
673
|
-
const tapGesture = useMemo(() => {
|
674
|
-
const tap = Gesture.Tap()
|
675
|
-
.shouldCancelWhenOutside(true)
|
676
|
-
.onStart(() => {
|
677
|
-
if (rowState.value !== 0) {
|
678
|
-
close();
|
679
|
-
}
|
680
|
-
});
|
681
|
-
|
682
|
-
Object.entries(relationProps).forEach(([relationName, relation]) => {
|
683
|
-
applyRelationProp(
|
684
|
-
tap,
|
685
|
-
relationName as RelationPropName,
|
686
|
-
relation as RelationPropType
|
687
|
-
);
|
688
|
-
});
|
689
|
-
|
690
|
-
return tap;
|
691
|
-
}, [close, rowState, simultaneousWithExternalGesture]);
|
692
|
-
|
693
|
-
const panGesture = useMemo(() => {
|
694
|
-
const pan = Gesture.Pan()
|
695
|
-
.enabled(enabled !== false)
|
696
|
-
.enableTrackpadTwoFingerGesture(enableTrackpadTwoFingerGesture)
|
697
|
-
.activeOffsetX([-dragOffsetFromRightEdge, dragOffsetFromLeftEdge])
|
698
|
-
.onStart(updateElementWidths)
|
699
|
-
.onUpdate(
|
700
|
-
(event: GestureUpdateEvent<PanGestureHandlerEventPayload>) => {
|
701
|
-
userDrag.value = event.translationX;
|
702
|
-
|
703
|
-
const direction =
|
704
|
-
rowState.value === -1
|
705
|
-
? SwipeDirection.RIGHT
|
706
|
-
: rowState.value === 1
|
707
|
-
? SwipeDirection.LEFT
|
708
|
-
: event.translationX > 0
|
709
|
-
? SwipeDirection.RIGHT
|
710
|
-
: SwipeDirection.LEFT;
|
711
|
-
|
712
|
-
if (!dragStarted.value) {
|
713
|
-
dragStarted.value = true;
|
714
|
-
if (rowState.value === 0 && onSwipeableOpenStartDrag) {
|
715
|
-
runOnJS(onSwipeableOpenStartDrag)(direction);
|
716
|
-
} else if (onSwipeableCloseStartDrag) {
|
717
|
-
runOnJS(onSwipeableCloseStartDrag)(direction);
|
718
|
-
}
|
719
|
-
}
|
720
|
-
|
721
|
-
updateAnimatedEvent();
|
722
|
-
}
|
723
|
-
)
|
724
|
-
.onEnd(
|
725
|
-
(event: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
|
726
|
-
handleRelease(event);
|
727
|
-
}
|
728
|
-
)
|
729
|
-
.onFinalize(() => {
|
730
|
-
dragStarted.value = false;
|
731
|
-
});
|
732
|
-
|
733
|
-
Object.entries(relationProps).forEach(([relationName, relation]) => {
|
734
|
-
applyRelationProp(
|
735
|
-
pan,
|
736
|
-
relationName as RelationPropName,
|
737
|
-
relation as RelationPropType
|
738
|
-
);
|
739
|
-
});
|
740
|
-
|
741
|
-
return pan;
|
742
|
-
}, [
|
743
|
-
dragOffsetFromLeftEdge,
|
744
|
-
dragOffsetFromRightEdge,
|
745
|
-
dragStarted,
|
746
|
-
enableTrackpadTwoFingerGesture,
|
747
|
-
enabled,
|
748
|
-
handleRelease,
|
749
|
-
onSwipeableCloseStartDrag,
|
750
|
-
onSwipeableOpenStartDrag,
|
751
|
-
rowState,
|
752
|
-
updateAnimatedEvent,
|
753
|
-
updateElementWidths,
|
754
|
-
userDrag,
|
755
|
-
simultaneousWithExternalGesture,
|
756
|
-
]);
|
757
|
-
|
758
|
-
useImperativeHandle(ref, () => swipeableMethods, [swipeableMethods]);
|
759
|
-
|
760
|
-
const animatedStyle = useAnimatedStyle(
|
761
|
-
() => ({
|
762
|
-
transform: [{ translateX: appliedTranslation.value }],
|
763
|
-
pointerEvents: rowState.value === 0 ? 'auto' : 'box-only',
|
764
|
-
}),
|
765
|
-
[appliedTranslation, rowState]
|
766
|
-
);
|
767
|
-
|
768
|
-
const swipeableComponent = (
|
769
|
-
<GestureDetector gesture={panGesture} touchAction="pan-y">
|
770
|
-
<Animated.View
|
771
|
-
{...remainingProps}
|
772
|
-
onLayout={onRowLayout}
|
773
|
-
hitSlop={hitSlop ?? undefined}
|
774
|
-
style={[styles.container, containerStyle]}>
|
775
|
-
{leftElement()}
|
776
|
-
{rightElement()}
|
777
|
-
<GestureDetector gesture={tapGesture} touchAction="pan-y">
|
778
|
-
<Animated.View style={[animatedStyle, childrenContainerStyle]}>
|
779
|
-
{children}
|
780
|
-
</Animated.View>
|
781
|
-
</GestureDetector>
|
782
|
-
</Animated.View>
|
783
|
-
</GestureDetector>
|
784
|
-
);
|
785
|
-
|
786
|
-
return testID ? (
|
787
|
-
<View testID={testID}>{swipeableComponent}</View>
|
788
|
-
) : (
|
789
|
-
swipeableComponent
|
790
|
-
);
|
791
|
-
}
|
792
|
-
);
|
793
|
-
|
794
|
-
export default Swipeable;
|
795
|
-
export type SwipeableRef = ForwardedRef<SwipeableMethods>;
|
796
|
-
|
797
|
-
const styles = StyleSheet.create({
|
798
|
-
container: {
|
799
|
-
overflow: 'hidden',
|
800
|
-
},
|
801
|
-
leftActions: {
|
802
|
-
...StyleSheet.absoluteFillObject,
|
803
|
-
flexDirection: I18nManager.isRTL ? 'row-reverse' : 'row',
|
804
|
-
overflow: 'hidden',
|
805
|
-
},
|
806
|
-
rightActions: {
|
807
|
-
...StyleSheet.absoluteFillObject,
|
808
|
-
flexDirection: I18nManager.isRTL ? 'row' : 'row-reverse',
|
809
|
-
overflow: 'hidden',
|
810
|
-
},
|
811
|
-
});
|