react-native-gesture-handler 2.17.1 → 2.18.1
Sign up to get free protection for your applications and to get access to all the features.
- package/ReanimatedSwipeable/package.json +6 -0
- package/android/build.gradle +0 -103
- package/android/gradle.properties +0 -7
- package/android/paper/src/main/java/com/swmansion/gesturehandler/NativeRNGestureHandlerModuleSpec.java +22 -10
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +1 -1
- package/android/src/main/java/com/swmansion/gesturehandler/core/NativeViewGestureHandler.kt +16 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/PinchGestureHandler.kt +7 -8
- package/android/src/main/java/com/swmansion/gesturehandler/core/RotationGestureDetector.kt +14 -4
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEvent.kt +3 -1
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerStateChangeEvent.kt +3 -1
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerTouchEvent.kt +2 -1
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNViewConfigurationHelper.kt +8 -7
- package/android/src/main/jni/cpp-adapter.cpp +2 -2
- package/apple/Handlers/RNFlingHandler.m +1 -0
- package/apple/Handlers/RNForceTouchHandler.m +2 -0
- package/apple/Handlers/RNLongPressHandler.m +2 -1
- package/apple/Handlers/RNManualHandler.m +1 -0
- package/apple/Handlers/RNNativeViewHandler.mm +31 -27
- package/apple/Handlers/RNPanHandler.m +1 -0
- package/apple/Handlers/RNPinchHandler.m +1 -0
- package/apple/Handlers/RNRotationHandler.m +1 -0
- package/apple/Handlers/RNTapHandler.m +1 -0
- package/apple/RNGestureHandlerModule.mm +1 -2
- package/apple/RNRootViewGestureRecognizer.m +5 -0
- package/lib/commonjs/Directions.js +2 -2
- package/lib/commonjs/Directions.js.map +1 -1
- package/lib/commonjs/RNGestureHandlerModule.web.js +2 -2
- package/lib/commonjs/RNGestureHandlerModule.web.js.map +1 -1
- package/lib/commonjs/components/DrawerLayout.js +2 -2
- package/lib/commonjs/components/DrawerLayout.js.map +1 -1
- package/lib/commonjs/components/GestureButtons.js +3 -3
- package/lib/commonjs/components/GestureButtons.js.map +1 -1
- package/lib/commonjs/components/GestureButtonsProps.js +6 -0
- package/lib/commonjs/components/GestureButtonsProps.js.map +1 -0
- package/lib/commonjs/components/GestureComponents.js +1 -1
- package/lib/commonjs/components/GestureComponents.js.map +1 -1
- package/lib/commonjs/components/GestureHandlerButton.js.map +1 -1
- package/lib/commonjs/components/GestureHandlerRootView.android.js +1 -1
- package/lib/commonjs/components/GestureHandlerRootView.android.js.map +1 -1
- package/lib/commonjs/components/GestureHandlerRootView.js +1 -1
- package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
- package/lib/commonjs/components/Pressable/Pressable.js +334 -0
- package/lib/commonjs/components/Pressable/Pressable.js.map +1 -0
- package/lib/commonjs/components/Pressable/PressableProps.js +6 -0
- package/lib/commonjs/components/Pressable/PressableProps.js.map +1 -0
- package/lib/commonjs/components/Pressable/index.js +24 -0
- package/lib/commonjs/components/Pressable/index.js.map +1 -0
- package/lib/commonjs/components/Pressable/utils.js +136 -0
- package/lib/commonjs/components/Pressable/utils.js.map +1 -0
- package/lib/commonjs/components/ReanimatedSwipeable.js +317 -0
- package/lib/commonjs/components/ReanimatedSwipeable.js.map +1 -0
- package/lib/commonjs/components/Swipeable.js +8 -3
- package/lib/commonjs/components/Swipeable.js.map +1 -1
- package/lib/commonjs/components/touchables/GenericTouchable.js +4 -4
- package/lib/commonjs/components/touchables/GenericTouchable.js.map +1 -1
- package/lib/commonjs/components/touchables/GenericTouchableProps.js +6 -0
- package/lib/commonjs/components/touchables/GenericTouchableProps.js.map +1 -0
- package/lib/commonjs/components/touchables/TouchableHighlight.js.map +1 -1
- package/lib/commonjs/components/touchables/TouchableNativeFeedback.android.js +1 -1
- package/lib/commonjs/components/touchables/TouchableNativeFeedback.android.js.map +1 -1
- package/lib/commonjs/components/touchables/TouchableNativeFeedbackProps.js +6 -0
- package/lib/commonjs/components/touchables/TouchableNativeFeedbackProps.js.map +1 -0
- package/lib/commonjs/components/touchables/TouchableOpacity.js.map +1 -1
- package/lib/commonjs/components/touchables/TouchableWithoutFeedback.js.map +1 -1
- package/lib/commonjs/getShadowNodeFromRef.js +2 -2
- package/lib/commonjs/getShadowNodeFromRef.js.map +1 -1
- package/lib/commonjs/ghQueueMicrotask.js +3 -4
- package/lib/commonjs/ghQueueMicrotask.js.map +1 -1
- package/lib/commonjs/handlers/FlingGestureHandler.js.map +1 -1
- package/lib/commonjs/handlers/ForceTouchGestureHandler.js.map +1 -1
- package/lib/commonjs/handlers/GestureHandlerEventPayload.js +2 -0
- package/lib/commonjs/handlers/GestureHandlerEventPayload.js.map +1 -0
- package/lib/commonjs/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/commonjs/handlers/NativeViewGestureHandler.js.map +1 -1
- package/lib/commonjs/handlers/PanGestureHandler.js.map +1 -1
- package/lib/commonjs/handlers/PinchGestureHandler.js.map +1 -1
- package/lib/commonjs/handlers/RotationGestureHandler.js.map +1 -1
- package/lib/commonjs/handlers/TapGestureHandler.js.map +1 -1
- package/lib/commonjs/handlers/createHandler.js +21 -19
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/handlers/createNativeWrapper.js +3 -3
- package/lib/commonjs/handlers/createNativeWrapper.js.map +1 -1
- package/lib/commonjs/handlers/gestureHandlerCommon.js +0 -86
- package/lib/commonjs/handlers/gestureHandlerCommon.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/Wrap.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/attachHandlers.js +9 -9
- package/lib/commonjs/handlers/gestures/GestureDetector/attachHandlers.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/dropHandlers.js +2 -2
- package/lib/commonjs/handlers/gestures/GestureDetector/dropHandlers.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/handlers/gestures/GestureDetector/updateHandlers.js +21 -31
- package/lib/commonjs/handlers/gestures/GestureDetector/updateHandlers.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/useDetectorUpdater.js +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/useDetectorUpdater.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/utils.js +5 -5
- package/lib/commonjs/handlers/gestures/GestureDetector/utils.js.map +1 -1
- package/lib/commonjs/handlers/gestures/flingGesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/forceTouchGesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/gesture.js +7 -7
- package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/gestureComposition.js +5 -5
- package/lib/commonjs/handlers/gestures/gestureComposition.js.map +1 -1
- package/lib/commonjs/handlers/gestures/gestureStateManager.js +1 -1
- package/lib/commonjs/handlers/gestures/gestureStateManager.js.map +1 -1
- package/lib/commonjs/handlers/gestures/longPressGesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/nativeGesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/panGesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/pinchGesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/rotationGesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/tapGesture.js.map +1 -1
- package/lib/commonjs/handlers/getNextHandlerTag.js +12 -0
- package/lib/commonjs/handlers/getNextHandlerTag.js.map +1 -0
- package/lib/commonjs/handlers/handlersRegistry.js +0 -6
- package/lib/commonjs/handlers/handlersRegistry.js.map +1 -1
- package/lib/commonjs/handlers/utils.js +91 -0
- package/lib/commonjs/handlers/utils.js.map +1 -0
- package/lib/commonjs/index.js +8 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/init.js +1 -1
- package/lib/commonjs/init.js.map +1 -1
- package/lib/commonjs/jestUtils/jestUtils.js +2 -2
- package/lib/commonjs/jestUtils/jestUtils.js.map +1 -1
- package/lib/commonjs/mocks.js +2 -2
- package/lib/commonjs/mocks.js.map +1 -1
- package/lib/commonjs/utils.js +1 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/Gestures.js +1 -1
- package/lib/commonjs/web/Gestures.js.map +1 -1
- package/lib/commonjs/web/detectors/RotationGestureDetector.js +1 -1
- package/lib/commonjs/web/detectors/RotationGestureDetector.js.map +1 -1
- package/lib/commonjs/web/detectors/ScaleGestureDetector.js +4 -4
- package/lib/commonjs/web/detectors/ScaleGestureDetector.js.map +1 -1
- package/lib/commonjs/web/handlers/FlingGestureHandler.js +1 -1
- package/lib/commonjs/web/handlers/FlingGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/GestureHandler.js +6 -11
- package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/NativeViewGestureHandler.js +1 -1
- package/lib/commonjs/web/handlers/NativeViewGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/PanGestureHandler.js +1 -1
- package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/TapGestureHandler.js +1 -1
- package/lib/commonjs/web/handlers/TapGestureHandler.js.map +1 -1
- package/lib/commonjs/web/tools/EventManager.js +2 -2
- package/lib/commonjs/web/tools/EventManager.js.map +1 -1
- package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js +4 -11
- package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/commonjs/web/tools/LeastSquareSolver.js +18 -18
- package/lib/commonjs/web/tools/LeastSquareSolver.js.map +1 -1
- package/lib/commonjs/web/tools/PointerEventManager.js +2 -2
- package/lib/commonjs/web/tools/PointerEventManager.js.map +1 -1
- package/lib/commonjs/web/tools/PointerTracker.js +1 -1
- package/lib/commonjs/web/tools/PointerTracker.js.map +1 -1
- package/lib/commonjs/web/tools/TouchEventManager.js +4 -4
- package/lib/commonjs/web/tools/TouchEventManager.js.map +1 -1
- package/lib/commonjs/web/tools/VelocityTracker.js +6 -6
- package/lib/commonjs/web/tools/VelocityTracker.js.map +1 -1
- package/lib/commonjs/web_hammer/NodeManager.js +2 -0
- package/lib/commonjs/web_hammer/NodeManager.js.map +1 -1
- package/lib/module/Directions.js +2 -2
- package/lib/module/Directions.js.map +1 -1
- package/lib/module/RNGestureHandlerModule.web.js +2 -2
- package/lib/module/RNGestureHandlerModule.web.js.map +1 -1
- package/lib/module/components/DrawerLayout.js +2 -2
- package/lib/module/components/DrawerLayout.js.map +1 -1
- package/lib/module/components/GestureButtons.js +3 -3
- package/lib/module/components/GestureButtons.js.map +1 -1
- package/lib/module/components/GestureButtonsProps.js +2 -0
- package/lib/module/components/GestureButtonsProps.js.map +1 -0
- package/lib/module/components/GestureComponents.js +1 -1
- package/lib/module/components/GestureComponents.js.map +1 -1
- package/lib/module/components/GestureHandlerButton.js.map +1 -1
- package/lib/module/components/GestureHandlerRootView.android.js +1 -1
- package/lib/module/components/GestureHandlerRootView.android.js.map +1 -1
- package/lib/module/components/GestureHandlerRootView.js +1 -1
- package/lib/module/components/GestureHandlerRootView.js.map +1 -1
- package/lib/module/components/Pressable/Pressable.js +309 -0
- package/lib/module/components/Pressable/Pressable.js.map +1 -0
- package/lib/module/components/Pressable/PressableProps.js +2 -0
- package/lib/module/components/Pressable/PressableProps.js.map +1 -0
- package/lib/module/components/Pressable/index.js +3 -0
- package/lib/module/components/Pressable/index.js.map +1 -0
- package/lib/module/components/Pressable/utils.js +120 -0
- package/lib/module/components/Pressable/utils.js.map +1 -0
- package/lib/module/components/ReanimatedSwipeable.js +293 -0
- package/lib/module/components/ReanimatedSwipeable.js.map +1 -0
- package/lib/module/components/Swipeable.js +9 -3
- package/lib/module/components/Swipeable.js.map +1 -1
- package/lib/module/components/touchables/GenericTouchable.js +4 -4
- package/lib/module/components/touchables/GenericTouchable.js.map +1 -1
- package/lib/module/components/touchables/GenericTouchableProps.js +2 -0
- package/lib/module/components/touchables/GenericTouchableProps.js.map +1 -0
- package/lib/module/components/touchables/TouchableHighlight.js.map +1 -1
- package/lib/module/components/touchables/TouchableNativeFeedback.android.js +1 -1
- package/lib/module/components/touchables/TouchableNativeFeedback.android.js.map +1 -1
- package/lib/module/components/touchables/TouchableNativeFeedbackProps.js +2 -0
- package/lib/module/components/touchables/TouchableNativeFeedbackProps.js.map +1 -0
- package/lib/module/components/touchables/TouchableOpacity.js.map +1 -1
- package/lib/module/components/touchables/TouchableWithoutFeedback.js.map +1 -1
- package/lib/module/getShadowNodeFromRef.js +2 -2
- package/lib/module/getShadowNodeFromRef.js.map +1 -1
- package/lib/module/ghQueueMicrotask.js +3 -4
- package/lib/module/ghQueueMicrotask.js.map +1 -1
- package/lib/module/handlers/FlingGestureHandler.js.map +1 -1
- package/lib/module/handlers/ForceTouchGestureHandler.js.map +1 -1
- package/lib/module/handlers/GestureHandlerEventPayload.js +2 -0
- package/lib/module/handlers/GestureHandlerEventPayload.js.map +1 -0
- package/lib/module/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/module/handlers/NativeViewGestureHandler.js.map +1 -1
- package/lib/module/handlers/PanGestureHandler.js.map +1 -1
- package/lib/module/handlers/PinchGestureHandler.js.map +1 -1
- package/lib/module/handlers/RotationGestureHandler.js.map +1 -1
- package/lib/module/handlers/TapGestureHandler.js.map +1 -1
- package/lib/module/handlers/createHandler.js +6 -5
- package/lib/module/handlers/createHandler.js.map +1 -1
- package/lib/module/handlers/createNativeWrapper.js +3 -3
- package/lib/module/handlers/createNativeWrapper.js.map +1 -1
- package/lib/module/handlers/gestureHandlerCommon.js +0 -72
- package/lib/module/handlers/gestureHandlerCommon.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/Wrap.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/attachHandlers.js +4 -4
- package/lib/module/handlers/gestures/GestureDetector/attachHandlers.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/dropHandlers.js +1 -1
- package/lib/module/handlers/gestures/GestureDetector/dropHandlers.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/handlers/gestures/GestureDetector/updateHandlers.js +18 -28
- package/lib/module/handlers/gestures/GestureDetector/updateHandlers.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/useDetectorUpdater.js +1 -1
- package/lib/module/handlers/gestures/GestureDetector/useDetectorUpdater.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/utils.js +5 -5
- package/lib/module/handlers/gestures/GestureDetector/utils.js.map +1 -1
- package/lib/module/handlers/gestures/flingGesture.js.map +1 -1
- package/lib/module/handlers/gestures/forceTouchGesture.js.map +1 -1
- package/lib/module/handlers/gestures/gesture.js +6 -6
- package/lib/module/handlers/gestures/gesture.js.map +1 -1
- package/lib/module/handlers/gestures/gestureComposition.js +5 -5
- package/lib/module/handlers/gestures/gestureComposition.js.map +1 -1
- package/lib/module/handlers/gestures/gestureStateManager.js +1 -1
- package/lib/module/handlers/gestures/gestureStateManager.js.map +1 -1
- package/lib/module/handlers/gestures/longPressGesture.js.map +1 -1
- package/lib/module/handlers/gestures/nativeGesture.js.map +1 -1
- package/lib/module/handlers/gestures/panGesture.js.map +1 -1
- package/lib/module/handlers/gestures/pinchGesture.js.map +1 -1
- package/lib/module/handlers/gestures/rotationGesture.js.map +1 -1
- package/lib/module/handlers/gestures/tapGesture.js.map +1 -1
- package/lib/module/handlers/getNextHandlerTag.js +5 -0
- package/lib/module/handlers/getNextHandlerTag.js.map +1 -0
- package/lib/module/handlers/handlersRegistry.js +0 -4
- package/lib/module/handlers/handlersRegistry.js.map +1 -1
- package/lib/module/handlers/utils.js +73 -0
- package/lib/module/handlers/utils.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/init.js +1 -1
- package/lib/module/init.js.map +1 -1
- package/lib/module/jestUtils/jestUtils.js +2 -2
- package/lib/module/jestUtils/jestUtils.js.map +1 -1
- package/lib/module/mocks.js +2 -2
- package/lib/module/mocks.js.map +1 -1
- package/lib/module/utils.js +1 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/Gestures.js +1 -1
- package/lib/module/web/Gestures.js.map +1 -1
- package/lib/module/web/detectors/RotationGestureDetector.js +1 -1
- package/lib/module/web/detectors/RotationGestureDetector.js.map +1 -1
- package/lib/module/web/detectors/ScaleGestureDetector.js +4 -4
- package/lib/module/web/detectors/ScaleGestureDetector.js.map +1 -1
- package/lib/module/web/handlers/FlingGestureHandler.js +1 -1
- package/lib/module/web/handlers/FlingGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/GestureHandler.js +6 -11
- package/lib/module/web/handlers/GestureHandler.js.map +1 -1
- package/lib/module/web/handlers/NativeViewGestureHandler.js +1 -1
- package/lib/module/web/handlers/NativeViewGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/PanGestureHandler.js +1 -1
- package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/TapGestureHandler.js +1 -1
- package/lib/module/web/handlers/TapGestureHandler.js.map +1 -1
- package/lib/module/web/tools/EventManager.js +2 -2
- package/lib/module/web/tools/EventManager.js.map +1 -1
- package/lib/module/web/tools/GestureHandlerWebDelegate.js +4 -11
- package/lib/module/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/module/web/tools/LeastSquareSolver.js +18 -18
- package/lib/module/web/tools/LeastSquareSolver.js.map +1 -1
- package/lib/module/web/tools/PointerEventManager.js +2 -2
- package/lib/module/web/tools/PointerEventManager.js.map +1 -1
- package/lib/module/web/tools/PointerTracker.js +1 -1
- package/lib/module/web/tools/PointerTracker.js.map +1 -1
- package/lib/module/web/tools/TouchEventManager.js +4 -4
- package/lib/module/web/tools/TouchEventManager.js.map +1 -1
- package/lib/module/web/tools/VelocityTracker.js +6 -6
- package/lib/module/web/tools/VelocityTracker.js.map +1 -1
- package/lib/module/web_hammer/NodeManager.js +1 -1
- package/lib/module/web_hammer/NodeManager.js.map +1 -1
- package/lib/typescript/RNGestureHandlerModule.web.d.ts +1 -1
- package/lib/typescript/components/GestureButtons.d.ts +2 -85
- package/lib/typescript/components/GestureButtonsProps.d.ts +99 -0
- package/lib/typescript/components/GestureHandlerButton.d.ts +1 -1
- package/lib/typescript/components/Pressable/Pressable.d.ts +3 -0
- package/lib/typescript/components/Pressable/PressableProps.d.ts +116 -0
- package/lib/typescript/components/Pressable/index.d.ts +2 -0
- package/lib/typescript/components/Pressable/utils.d.ts +15 -0
- package/lib/typescript/components/ReanimatedSwipeable.d.ts +125 -0
- package/lib/typescript/components/Swipeable.d.ts +5 -0
- package/lib/typescript/components/touchables/GenericTouchable.d.ts +4 -16
- package/lib/typescript/components/touchables/GenericTouchableProps.d.ts +14 -0
- package/lib/typescript/components/touchables/TouchableHighlight.d.ts +1 -1
- package/lib/typescript/components/touchables/TouchableNativeFeedback.android.d.ts +2 -9
- package/lib/typescript/components/touchables/TouchableNativeFeedbackProps.d.ts +9 -0
- package/lib/typescript/components/touchables/TouchableOpacity.d.ts +1 -1
- package/lib/typescript/components/touchables/TouchableWithoutFeedback.d.ts +2 -1
- package/lib/typescript/handlers/FlingGestureHandler.d.ts +2 -6
- package/lib/typescript/handlers/ForceTouchGestureHandler.d.ts +1 -10
- package/lib/typescript/handlers/GestureHandlerEventPayload.d.ts +159 -0
- package/lib/typescript/handlers/LongPressGestureHandler.d.ts +2 -35
- package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +2 -6
- package/lib/typescript/handlers/PanGestureHandler.d.ts +3 -51
- package/lib/typescript/handlers/PinchGestureHandler.d.ts +2 -23
- package/lib/typescript/handlers/RotationGestureHandler.d.ts +2 -23
- package/lib/typescript/handlers/TapGestureHandler.d.ts +2 -6
- package/lib/typescript/handlers/gestureHandlerCommon.d.ts +0 -5
- package/lib/typescript/handlers/gestureHandlerTypesCompat.d.ts +10 -9
- package/lib/typescript/handlers/gestures/GestureDetector/types.d.ts +1 -0
- package/lib/typescript/handlers/gestures/GestureDetector/utils.d.ts +1 -0
- package/lib/typescript/handlers/gestures/flingGesture.d.ts +2 -1
- package/lib/typescript/handlers/gestures/forceTouchGesture.d.ts +2 -1
- package/lib/typescript/handlers/gestures/gesture.d.ts +2 -8
- package/lib/typescript/handlers/gestures/longPressGesture.d.ts +2 -1
- package/lib/typescript/handlers/gestures/nativeGesture.d.ts +2 -1
- package/lib/typescript/handlers/gestures/panGesture.d.ts +2 -1
- package/lib/typescript/handlers/gestures/pinchGesture.d.ts +1 -1
- package/lib/typescript/handlers/gestures/rotationGesture.d.ts +1 -1
- package/lib/typescript/handlers/gestures/tapGesture.d.ts +2 -1
- package/lib/typescript/handlers/getNextHandlerTag.d.ts +1 -0
- package/lib/typescript/handlers/handlersRegistry.d.ts +1 -2
- package/lib/typescript/handlers/utils.d.ts +6 -0
- package/lib/typescript/index.d.ts +12 -9
- package/lib/typescript/jestUtils/jestUtils.d.ts +9 -7
- 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/HoverGestureHandler.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_hammer/NodeManager.d.ts +4 -5
- package/package.json +14 -16
- package/src/Directions.ts +2 -2
- package/src/RNGestureHandlerModule.web.ts +2 -2
- package/src/components/DrawerLayout.tsx +7 -9
- package/src/components/GestureButtons.tsx +13 -123
- package/src/components/GestureButtonsProps.ts +115 -0
- package/src/components/GestureComponents.tsx +1 -1
- package/src/components/GestureHandlerButton.tsx +1 -1
- package/src/components/GestureHandlerRootView.android.tsx +1 -1
- package/src/components/GestureHandlerRootView.tsx +1 -1
- package/src/components/Pressable/Pressable.tsx +398 -0
- package/src/components/Pressable/PressableProps.tsx +149 -0
- package/src/components/Pressable/index.ts +2 -0
- package/src/components/Pressable/utils.ts +180 -0
- package/src/components/ReanimatedSwipeable.tsx +629 -0
- package/src/components/Swipeable.tsx +12 -6
- package/src/components/touchables/GenericTouchable.tsx +9 -36
- package/src/components/touchables/GenericTouchableProps.ts +26 -0
- package/src/components/touchables/TouchableHighlight.tsx +2 -4
- package/src/components/touchables/TouchableNativeFeedback.android.tsx +7 -17
- package/src/components/touchables/TouchableNativeFeedbackProps.tsx +12 -0
- package/src/components/touchables/TouchableOpacity.tsx +3 -5
- package/src/components/touchables/TouchableWithoutFeedback.tsx +2 -1
- package/src/getShadowNodeFromRef.ts +2 -2
- package/src/ghQueueMicrotask.ts +7 -4
- package/src/handlers/FlingGestureHandler.ts +1 -6
- package/src/handlers/ForceTouchGestureHandler.ts +1 -12
- package/src/handlers/GestureHandlerEventPayload.ts +184 -0
- package/src/handlers/LongPressGestureHandler.ts +1 -40
- package/src/handlers/NativeViewGestureHandler.ts +1 -7
- package/src/handlers/PanGestureHandler.ts +1 -58
- package/src/handlers/PinchGestureHandler.ts +1 -27
- package/src/handlers/RotationGestureHandler.ts +1 -27
- package/src/handlers/TapGestureHandler.ts +1 -6
- package/src/handlers/createHandler.tsx +6 -11
- package/src/handlers/createNativeWrapper.tsx +3 -3
- package/src/handlers/gestureHandlerCommon.ts +3 -79
- package/src/handlers/gestureHandlerTypesCompat.ts +16 -30
- package/src/handlers/gestures/GestureDetector/Wrap.tsx +1 -1
- package/src/handlers/gestures/GestureDetector/attachHandlers.ts +4 -7
- package/src/handlers/gestures/GestureDetector/dropHandlers.ts +1 -1
- package/src/handlers/gestures/GestureDetector/index.tsx +1 -1
- package/src/handlers/gestures/GestureDetector/updateHandlers.ts +20 -30
- package/src/handlers/gestures/GestureDetector/useDetectorUpdater.ts +1 -1
- package/src/handlers/gestures/GestureDetector/utils.ts +5 -5
- package/src/handlers/gestures/flingGesture.ts +2 -4
- package/src/handlers/gestures/forceTouchGesture.ts +2 -4
- package/src/handlers/gestures/gesture.ts +17 -15
- package/src/handlers/gestures/gestureComposition.ts +5 -5
- package/src/handlers/gestures/gestureStateManager.ts +1 -1
- package/src/handlers/gestures/longPressGesture.ts +2 -4
- package/src/handlers/gestures/nativeGesture.ts +2 -4
- package/src/handlers/gestures/panGesture.ts +2 -4
- package/src/handlers/gestures/pinchGesture.ts +1 -1
- package/src/handlers/gestures/rotationGesture.ts +1 -1
- package/src/handlers/gestures/tapGesture.ts +2 -4
- package/src/handlers/getNextHandlerTag.ts +5 -0
- package/src/handlers/handlersRegistry.ts +0 -6
- package/src/handlers/utils.ts +75 -0
- package/src/index.ts +25 -36
- package/src/init.ts +1 -1
- package/src/jestUtils/jestUtils.ts +12 -10
- package/src/mocks.ts +2 -2
- package/src/utils.ts +1 -1
- package/src/web/Gestures.ts +1 -1
- package/src/web/detectors/RotationGestureDetector.ts +1 -1
- package/src/web/detectors/ScaleGestureDetector.ts +4 -4
- package/src/web/handlers/FlingGestureHandler.ts +1 -1
- package/src/web/handlers/GestureHandler.ts +8 -14
- package/src/web/handlers/NativeViewGestureHandler.ts +3 -3
- package/src/web/handlers/PanGestureHandler.ts +1 -1
- package/src/web/handlers/TapGestureHandler.ts +1 -1
- package/src/web/tools/EventManager.ts +2 -2
- package/src/web/tools/GestureHandlerWebDelegate.ts +3 -8
- package/src/web/tools/LeastSquareSolver.ts +18 -18
- package/src/web/tools/PointerEventManager.ts +2 -2
- package/src/web/tools/PointerTracker.ts +2 -1
- package/src/web/tools/TouchEventManager.ts +4 -4
- package/src/web/tools/VelocityTracker.ts +6 -6
- package/src/web_hammer/NodeManager.ts +2 -11
@@ -0,0 +1,629 @@
|
|
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
|
+
useRef,
|
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
|
+
Extrapolation,
|
22
|
+
SharedValue,
|
23
|
+
interpolate,
|
24
|
+
runOnJS,
|
25
|
+
useAnimatedStyle,
|
26
|
+
useSharedValue,
|
27
|
+
withSpring,
|
28
|
+
} from 'react-native-reanimated';
|
29
|
+
import {
|
30
|
+
I18nManager,
|
31
|
+
LayoutChangeEvent,
|
32
|
+
StyleProp,
|
33
|
+
StyleSheet,
|
34
|
+
View,
|
35
|
+
ViewStyle,
|
36
|
+
} from 'react-native';
|
37
|
+
|
38
|
+
const DRAG_TOSS = 0.05;
|
39
|
+
|
40
|
+
type SwipeableExcludes = Exclude<
|
41
|
+
keyof PanGestureHandlerProps,
|
42
|
+
'onGestureEvent' | 'onHandlerStateChange'
|
43
|
+
>;
|
44
|
+
|
45
|
+
export interface SwipeableProps
|
46
|
+
extends Pick<PanGestureHandlerProps, SwipeableExcludes> {
|
47
|
+
/**
|
48
|
+
* Enables two-finger gestures on supported devices, for example iPads with
|
49
|
+
* trackpads. If not enabled the gesture will require click + drag, with
|
50
|
+
* `enableTrackpadTwoFingerGesture` swiping with two fingers will also trigger
|
51
|
+
* the gesture.
|
52
|
+
*/
|
53
|
+
enableTrackpadTwoFingerGesture?: boolean;
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Specifies how much the visual interaction will be delayed compared to the
|
57
|
+
* gesture distance. e.g. value of 1 will indicate that the swipeable panel
|
58
|
+
* should exactly follow the gesture, 2 means it is going to be two times
|
59
|
+
* "slower".
|
60
|
+
*/
|
61
|
+
friction?: number;
|
62
|
+
|
63
|
+
/**
|
64
|
+
* Distance from the left edge at which released panel will animate to the
|
65
|
+
* open state (or the open panel will animate into the closed state). By
|
66
|
+
* default it's a half of the panel's width.
|
67
|
+
*/
|
68
|
+
leftThreshold?: number;
|
69
|
+
|
70
|
+
/**
|
71
|
+
* Distance from the right edge at which released panel will animate to the
|
72
|
+
* open state (or the open panel will animate into the closed state). By
|
73
|
+
* default it's a half of the panel's width.
|
74
|
+
*/
|
75
|
+
rightThreshold?: number;
|
76
|
+
|
77
|
+
/**
|
78
|
+
* Distance that the panel must be dragged from the left edge to be considered
|
79
|
+
* a swipe. The default value is 10.
|
80
|
+
*/
|
81
|
+
dragOffsetFromLeftEdge?: number;
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Distance that the panel must be dragged from the right edge to be considered
|
85
|
+
* a swipe. The default value is 10.
|
86
|
+
*/
|
87
|
+
dragOffsetFromRightEdge?: number;
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Value indicating if the swipeable panel can be pulled further than the left
|
91
|
+
* actions panel's width. It is set to true by default as long as the left
|
92
|
+
* panel render method is present.
|
93
|
+
*/
|
94
|
+
overshootLeft?: boolean;
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Value indicating if the swipeable panel can be pulled further than the
|
98
|
+
* right actions panel's width. It is set to true by default as long as the
|
99
|
+
* right panel render method is present.
|
100
|
+
*/
|
101
|
+
overshootRight?: boolean;
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Specifies how much the visual interaction will be delayed compared to the
|
105
|
+
* gesture distance at overshoot. Default value is 1, it mean no friction, for
|
106
|
+
* a native feel, try 8 or above.
|
107
|
+
*/
|
108
|
+
overshootFriction?: number;
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Called when action panel gets open (either right or left).
|
112
|
+
*/
|
113
|
+
onSwipeableOpen?: (
|
114
|
+
direction: 'left' | 'right',
|
115
|
+
swipeable: SwipeableMethods
|
116
|
+
) => void;
|
117
|
+
|
118
|
+
/**
|
119
|
+
* Called when action panel is closed.
|
120
|
+
*/
|
121
|
+
onSwipeableClose?: (
|
122
|
+
direction: 'left' | 'right',
|
123
|
+
swipeable: SwipeableMethods
|
124
|
+
) => void;
|
125
|
+
|
126
|
+
/**
|
127
|
+
* Called when action panel starts animating on open (either right or left).
|
128
|
+
*/
|
129
|
+
onSwipeableWillOpen?: (direction: 'left' | 'right') => void;
|
130
|
+
|
131
|
+
/**
|
132
|
+
* Called when action panel starts animating on close.
|
133
|
+
*/
|
134
|
+
onSwipeableWillClose?: (direction: 'left' | 'right') => void;
|
135
|
+
|
136
|
+
/**
|
137
|
+
* Called when action panel starts being shown on dragging to open.
|
138
|
+
*/
|
139
|
+
onSwipeableOpenStartDrag?: (direction: 'left' | 'right') => void;
|
140
|
+
|
141
|
+
/**
|
142
|
+
* Called when action panel starts being shown on dragging to close.
|
143
|
+
*/
|
144
|
+
onSwipeableCloseStartDrag?: (direction: 'left' | 'right') => void;
|
145
|
+
|
146
|
+
/**
|
147
|
+
*
|
148
|
+
* This map describes the values to use as inputRange for extra interpolation:
|
149
|
+
* AnimatedValue: [startValue, endValue]
|
150
|
+
*
|
151
|
+
* progressAnimatedValue: [0, 1] dragAnimatedValue: [0, +]
|
152
|
+
*
|
153
|
+
* To support `rtl` flexbox layouts use `flexDirection` styling.
|
154
|
+
* */
|
155
|
+
renderLeftActions?: (
|
156
|
+
progressAnimatedValue: SharedValue<number>,
|
157
|
+
dragAnimatedValue: SharedValue<number>,
|
158
|
+
swipeable: SwipeableMethods
|
159
|
+
) => React.ReactNode;
|
160
|
+
/**
|
161
|
+
*
|
162
|
+
* This map describes the values to use as inputRange for extra interpolation:
|
163
|
+
* AnimatedValue: [startValue, endValue]
|
164
|
+
*
|
165
|
+
* progressAnimatedValue: [0, 1] dragAnimatedValue: [0, -]
|
166
|
+
*
|
167
|
+
* To support `rtl` flexbox layouts use `flexDirection` styling.
|
168
|
+
* */
|
169
|
+
renderRightActions?: (
|
170
|
+
progressAnimatedValue: SharedValue<number>,
|
171
|
+
dragAnimatedValue: SharedValue<number>,
|
172
|
+
swipeable: SwipeableMethods
|
173
|
+
) => React.ReactNode;
|
174
|
+
|
175
|
+
animationOptions?: Record<string, unknown>;
|
176
|
+
|
177
|
+
/**
|
178
|
+
* Style object for the container (`Animated.View`), for example to override
|
179
|
+
* `overflow: 'hidden'`.
|
180
|
+
*/
|
181
|
+
containerStyle?: StyleProp<ViewStyle>;
|
182
|
+
|
183
|
+
/**
|
184
|
+
* Style object for the children container (`Animated.View`), for example to
|
185
|
+
* apply `flex: 1`
|
186
|
+
*/
|
187
|
+
childrenContainerStyle?: StyleProp<ViewStyle>;
|
188
|
+
}
|
189
|
+
|
190
|
+
export interface SwipeableMethods {
|
191
|
+
close: () => void;
|
192
|
+
openLeft: () => void;
|
193
|
+
openRight: () => void;
|
194
|
+
reset: () => void;
|
195
|
+
}
|
196
|
+
|
197
|
+
const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
|
198
|
+
function Swipeable(
|
199
|
+
props: SwipeableProps,
|
200
|
+
ref: ForwardedRef<SwipeableMethods>
|
201
|
+
) {
|
202
|
+
const rowState = useSharedValue<number>(0);
|
203
|
+
|
204
|
+
const userDrag = useSharedValue<number>(0);
|
205
|
+
const appliedTranslation = useSharedValue<number>(0);
|
206
|
+
|
207
|
+
const rowWidth = useSharedValue<number>(0);
|
208
|
+
const leftWidth = useSharedValue<number>(0);
|
209
|
+
const rightWidth = useSharedValue<number>(0);
|
210
|
+
const rightOffset = useSharedValue<number>(0);
|
211
|
+
|
212
|
+
const leftActionTranslate = useSharedValue<number>(0);
|
213
|
+
const rightActionTranslate = useSharedValue<number>(0);
|
214
|
+
|
215
|
+
const showLeftProgress = useSharedValue<number>(0);
|
216
|
+
const showRightProgress = useSharedValue<number>(0);
|
217
|
+
|
218
|
+
const swipeableMethods = useRef<SwipeableMethods>({
|
219
|
+
close: () => {
|
220
|
+
'worklet';
|
221
|
+
},
|
222
|
+
openLeft: () => {
|
223
|
+
'worklet';
|
224
|
+
},
|
225
|
+
openRight: () => {
|
226
|
+
'worklet';
|
227
|
+
},
|
228
|
+
reset: () => {
|
229
|
+
'worklet';
|
230
|
+
},
|
231
|
+
});
|
232
|
+
|
233
|
+
const defaultProps = {
|
234
|
+
friction: 1,
|
235
|
+
overshootFriction: 1,
|
236
|
+
};
|
237
|
+
|
238
|
+
const {
|
239
|
+
friction = defaultProps.friction,
|
240
|
+
overshootFriction = defaultProps.overshootFriction,
|
241
|
+
} = props;
|
242
|
+
|
243
|
+
const overshootLeftProp = props.overshootLeft;
|
244
|
+
const overshootRightProp = props.overshootRight;
|
245
|
+
|
246
|
+
const calculateCurrentOffset = useCallback(() => {
|
247
|
+
'worklet';
|
248
|
+
if (rowState.value === 1) {
|
249
|
+
return leftWidth.value;
|
250
|
+
} else if (rowState.value === -1) {
|
251
|
+
return -rowWidth.value - rightOffset.value;
|
252
|
+
}
|
253
|
+
return 0;
|
254
|
+
}, [leftWidth, rightOffset, rowState, rowWidth]);
|
255
|
+
|
256
|
+
const updateAnimatedEvent = () => {
|
257
|
+
'worklet';
|
258
|
+
rightWidth.value = Math.max(0, rowWidth.value - rightOffset.value);
|
259
|
+
|
260
|
+
const overshootLeft = overshootLeftProp ?? leftWidth.value > 0;
|
261
|
+
const overshootRight = overshootRightProp ?? rightWidth.value > 0;
|
262
|
+
|
263
|
+
const startOffset =
|
264
|
+
rowState.value === 1
|
265
|
+
? leftWidth.value
|
266
|
+
: rowState.value === -1
|
267
|
+
? -rightWidth.value
|
268
|
+
: 0;
|
269
|
+
|
270
|
+
const offsetDrag = userDrag.value / friction + startOffset;
|
271
|
+
|
272
|
+
appliedTranslation.value = interpolate(
|
273
|
+
offsetDrag,
|
274
|
+
[
|
275
|
+
-rightWidth.value - 1,
|
276
|
+
-rightWidth.value,
|
277
|
+
leftWidth.value,
|
278
|
+
leftWidth.value + 1,
|
279
|
+
],
|
280
|
+
[
|
281
|
+
-rightWidth.value - (overshootRight ? 1 / overshootFriction : 0),
|
282
|
+
-rightWidth.value,
|
283
|
+
leftWidth.value,
|
284
|
+
leftWidth.value + (overshootLeft ? 1 / overshootFriction : 0),
|
285
|
+
]
|
286
|
+
);
|
287
|
+
|
288
|
+
showLeftProgress.value =
|
289
|
+
leftWidth.value > 0
|
290
|
+
? interpolate(
|
291
|
+
appliedTranslation.value,
|
292
|
+
[-1, 0, leftWidth.value],
|
293
|
+
[0, 0, 1]
|
294
|
+
)
|
295
|
+
: 0;
|
296
|
+
leftActionTranslate.value = interpolate(
|
297
|
+
showLeftProgress.value,
|
298
|
+
[0, Number.MIN_VALUE],
|
299
|
+
[-10000, 0],
|
300
|
+
Extrapolation.CLAMP
|
301
|
+
);
|
302
|
+
showRightProgress.value =
|
303
|
+
rightWidth.value > 0
|
304
|
+
? interpolate(
|
305
|
+
appliedTranslation.value,
|
306
|
+
[-rightWidth.value, 0, 1],
|
307
|
+
[1, 0, 0]
|
308
|
+
)
|
309
|
+
: 0;
|
310
|
+
rightActionTranslate.value = interpolate(
|
311
|
+
showRightProgress.value,
|
312
|
+
[0, Number.MIN_VALUE],
|
313
|
+
[-10000, 0],
|
314
|
+
Extrapolation.CLAMP
|
315
|
+
);
|
316
|
+
};
|
317
|
+
|
318
|
+
const dispatchImmediateEvents = useCallback(
|
319
|
+
(fromValue: number, toValue: number) => {
|
320
|
+
if (toValue > 0 && props.onSwipeableWillOpen) {
|
321
|
+
props.onSwipeableWillOpen('left');
|
322
|
+
} else if (toValue < 0 && props.onSwipeableWillOpen) {
|
323
|
+
props.onSwipeableWillOpen('right');
|
324
|
+
} else if (props.onSwipeableWillClose) {
|
325
|
+
const closingDirection = fromValue > 0 ? 'left' : 'right';
|
326
|
+
props.onSwipeableWillClose(closingDirection);
|
327
|
+
}
|
328
|
+
},
|
329
|
+
[
|
330
|
+
props,
|
331
|
+
props.onSwipeableWillClose,
|
332
|
+
props.onSwipeableWillOpen,
|
333
|
+
swipeableMethods,
|
334
|
+
]
|
335
|
+
);
|
336
|
+
|
337
|
+
const dispatchEndEvents = useCallback(
|
338
|
+
(fromValue: number, toValue: number) => {
|
339
|
+
if (toValue > 0 && props.onSwipeableOpen) {
|
340
|
+
props.onSwipeableOpen('left', swipeableMethods.current);
|
341
|
+
} else if (toValue < 0 && props.onSwipeableOpen) {
|
342
|
+
props.onSwipeableOpen('right', swipeableMethods.current);
|
343
|
+
} else if (props.onSwipeableClose) {
|
344
|
+
const closingDirection = fromValue > 0 ? 'left' : 'right';
|
345
|
+
props.onSwipeableClose(closingDirection, swipeableMethods.current);
|
346
|
+
}
|
347
|
+
},
|
348
|
+
[props, props.onSwipeableClose, props.onSwipeableOpen, swipeableMethods]
|
349
|
+
);
|
350
|
+
|
351
|
+
const animationOptionsProp = props.animationOptions;
|
352
|
+
|
353
|
+
const animateRow = useCallback(
|
354
|
+
(fromValue: number, toValue: number, velocityX?: number) => {
|
355
|
+
'worklet';
|
356
|
+
rowState.value = Math.sign(toValue);
|
357
|
+
|
358
|
+
const springConfig = {
|
359
|
+
duration: 1000,
|
360
|
+
dampingRatio: 0.9,
|
361
|
+
stiffness: 500,
|
362
|
+
velocity: velocityX,
|
363
|
+
overshootClamping: true,
|
364
|
+
...animationOptionsProp,
|
365
|
+
};
|
366
|
+
|
367
|
+
appliedTranslation.value = withSpring(
|
368
|
+
toValue,
|
369
|
+
springConfig,
|
370
|
+
(isFinished) => {
|
371
|
+
if (isFinished) {
|
372
|
+
runOnJS(dispatchEndEvents)(fromValue, toValue);
|
373
|
+
}
|
374
|
+
}
|
375
|
+
);
|
376
|
+
|
377
|
+
const progressTarget = toValue === 0 ? 0 : 1;
|
378
|
+
|
379
|
+
// Velocity is in px, while progress is in %
|
380
|
+
springConfig.velocity = 0;
|
381
|
+
|
382
|
+
showLeftProgress.value =
|
383
|
+
leftWidth.value > 0 ? withSpring(progressTarget, springConfig) : 0;
|
384
|
+
showRightProgress.value =
|
385
|
+
rightWidth.value > 0 ? withSpring(progressTarget, springConfig) : 0;
|
386
|
+
|
387
|
+
runOnJS(dispatchImmediateEvents)(fromValue, toValue);
|
388
|
+
},
|
389
|
+
[
|
390
|
+
showLeftProgress,
|
391
|
+
appliedTranslation,
|
392
|
+
dispatchEndEvents,
|
393
|
+
dispatchImmediateEvents,
|
394
|
+
animationOptionsProp,
|
395
|
+
rowState,
|
396
|
+
]
|
397
|
+
);
|
398
|
+
|
399
|
+
const onRowLayout = ({ nativeEvent }: LayoutChangeEvent) => {
|
400
|
+
rowWidth.value = nativeEvent.layout.width;
|
401
|
+
};
|
402
|
+
|
403
|
+
const {
|
404
|
+
children,
|
405
|
+
renderLeftActions,
|
406
|
+
renderRightActions,
|
407
|
+
dragOffsetFromLeftEdge = 10,
|
408
|
+
dragOffsetFromRightEdge = 10,
|
409
|
+
} = props;
|
410
|
+
|
411
|
+
swipeableMethods.current = {
|
412
|
+
close() {
|
413
|
+
'worklet';
|
414
|
+
animateRow(calculateCurrentOffset(), 0);
|
415
|
+
},
|
416
|
+
openLeft() {
|
417
|
+
'worklet';
|
418
|
+
animateRow(calculateCurrentOffset(), leftWidth.value);
|
419
|
+
},
|
420
|
+
openRight() {
|
421
|
+
'worklet';
|
422
|
+
rightWidth.value = rowWidth.value - rightOffset.value;
|
423
|
+
animateRow(calculateCurrentOffset(), -rightWidth.value);
|
424
|
+
},
|
425
|
+
reset() {
|
426
|
+
'worklet';
|
427
|
+
userDrag.value = 0;
|
428
|
+
showLeftProgress.value = 0;
|
429
|
+
appliedTranslation.value = 0;
|
430
|
+
rowState.value = 0;
|
431
|
+
},
|
432
|
+
};
|
433
|
+
|
434
|
+
const leftAnimatedStyle = useAnimatedStyle(
|
435
|
+
() => ({
|
436
|
+
transform: [
|
437
|
+
{
|
438
|
+
translateX: leftActionTranslate.value,
|
439
|
+
},
|
440
|
+
],
|
441
|
+
}),
|
442
|
+
[leftActionTranslate]
|
443
|
+
);
|
444
|
+
|
445
|
+
const leftElement = renderLeftActions && (
|
446
|
+
<Animated.View style={[styles.leftActions, leftAnimatedStyle]}>
|
447
|
+
{renderLeftActions(
|
448
|
+
showLeftProgress,
|
449
|
+
appliedTranslation,
|
450
|
+
swipeableMethods.current
|
451
|
+
)}
|
452
|
+
<View
|
453
|
+
onLayout={({ nativeEvent }) =>
|
454
|
+
(leftWidth.value = nativeEvent.layout.x)
|
455
|
+
}
|
456
|
+
/>
|
457
|
+
</Animated.View>
|
458
|
+
);
|
459
|
+
|
460
|
+
const rightAnimatedStyle = useAnimatedStyle(
|
461
|
+
() => ({
|
462
|
+
transform: [
|
463
|
+
{
|
464
|
+
translateX: rightActionTranslate.value,
|
465
|
+
},
|
466
|
+
],
|
467
|
+
}),
|
468
|
+
[rightActionTranslate]
|
469
|
+
);
|
470
|
+
|
471
|
+
const rightElement = renderRightActions && (
|
472
|
+
<Animated.View style={[styles.rightActions, rightAnimatedStyle]}>
|
473
|
+
{renderRightActions(
|
474
|
+
showRightProgress,
|
475
|
+
appliedTranslation,
|
476
|
+
swipeableMethods.current
|
477
|
+
)}
|
478
|
+
<View
|
479
|
+
onLayout={({ nativeEvent }) =>
|
480
|
+
(rightOffset.value = nativeEvent.layout.x)
|
481
|
+
}
|
482
|
+
/>
|
483
|
+
</Animated.View>
|
484
|
+
);
|
485
|
+
|
486
|
+
const leftThresholdProp = props.leftThreshold;
|
487
|
+
const rightThresholdProp = props.rightThreshold;
|
488
|
+
|
489
|
+
const handleRelease = (
|
490
|
+
event: GestureStateChangeEvent<PanGestureHandlerEventPayload>
|
491
|
+
) => {
|
492
|
+
'worklet';
|
493
|
+
const { velocityX } = event;
|
494
|
+
userDrag.value = event.translationX;
|
495
|
+
|
496
|
+
rightWidth.value = rowWidth.value - rightOffset.value;
|
497
|
+
|
498
|
+
const leftThreshold = leftThresholdProp ?? leftWidth.value / 2;
|
499
|
+
const rightThreshold = rightThresholdProp ?? rightWidth.value / 2;
|
500
|
+
|
501
|
+
const startOffsetX = calculateCurrentOffset() + userDrag.value / friction;
|
502
|
+
const translationX = (userDrag.value + DRAG_TOSS * velocityX) / friction;
|
503
|
+
|
504
|
+
let toValue = 0;
|
505
|
+
|
506
|
+
if (rowState.value === 0) {
|
507
|
+
if (translationX > leftThreshold) {
|
508
|
+
toValue = leftWidth.value;
|
509
|
+
} else if (translationX < -rightThreshold) {
|
510
|
+
toValue = -rightWidth.value;
|
511
|
+
}
|
512
|
+
} else if (rowState.value === 1) {
|
513
|
+
// Swiped to left
|
514
|
+
if (translationX > -leftThreshold) {
|
515
|
+
toValue = leftWidth.value;
|
516
|
+
}
|
517
|
+
} else {
|
518
|
+
// Swiped to right
|
519
|
+
if (translationX < rightThreshold) {
|
520
|
+
toValue = -rightWidth.value;
|
521
|
+
}
|
522
|
+
}
|
523
|
+
|
524
|
+
animateRow(startOffsetX, toValue, velocityX / friction);
|
525
|
+
};
|
526
|
+
|
527
|
+
const close = () => {
|
528
|
+
'worklet';
|
529
|
+
animateRow(calculateCurrentOffset(), 0);
|
530
|
+
};
|
531
|
+
|
532
|
+
const tapGesture = Gesture.Tap().onStart(() => {
|
533
|
+
if (rowState.value !== 0) {
|
534
|
+
close();
|
535
|
+
}
|
536
|
+
});
|
537
|
+
|
538
|
+
const onSwipeableOpenStartDrag = props.onSwipeableOpenStartDrag;
|
539
|
+
const onSwipeableCloseStartDrag = props.onSwipeableCloseStartDrag;
|
540
|
+
|
541
|
+
const panGesture = Gesture.Pan()
|
542
|
+
.onUpdate((event: GestureUpdateEvent<PanGestureHandlerEventPayload>) => {
|
543
|
+
userDrag.value = event.translationX;
|
544
|
+
|
545
|
+
const direction =
|
546
|
+
rowState.value === -1
|
547
|
+
? 'right'
|
548
|
+
: rowState.value === 1
|
549
|
+
? 'left'
|
550
|
+
: event.translationX > 0
|
551
|
+
? 'left'
|
552
|
+
: 'right';
|
553
|
+
|
554
|
+
if (rowState.value === 0 && onSwipeableOpenStartDrag) {
|
555
|
+
runOnJS(onSwipeableOpenStartDrag)(direction);
|
556
|
+
} else if (rowState.value !== 0 && onSwipeableCloseStartDrag) {
|
557
|
+
runOnJS(onSwipeableCloseStartDrag)(direction);
|
558
|
+
}
|
559
|
+
updateAnimatedEvent();
|
560
|
+
})
|
561
|
+
.onEnd(
|
562
|
+
(event: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
|
563
|
+
handleRelease(event);
|
564
|
+
}
|
565
|
+
);
|
566
|
+
|
567
|
+
if (props.enableTrackpadTwoFingerGesture) {
|
568
|
+
panGesture.enableTrackpadTwoFingerGesture(
|
569
|
+
props.enableTrackpadTwoFingerGesture
|
570
|
+
);
|
571
|
+
}
|
572
|
+
|
573
|
+
panGesture.activeOffsetX([
|
574
|
+
-dragOffsetFromRightEdge,
|
575
|
+
dragOffsetFromLeftEdge,
|
576
|
+
]);
|
577
|
+
tapGesture.shouldCancelWhenOutside(true);
|
578
|
+
|
579
|
+
useImperativeHandle(ref, () => swipeableMethods.current, [
|
580
|
+
swipeableMethods,
|
581
|
+
]);
|
582
|
+
|
583
|
+
panGesture.enabled(props.enabled !== false);
|
584
|
+
|
585
|
+
const animatedStyle = useAnimatedStyle(
|
586
|
+
() => ({
|
587
|
+
transform: [{ translateX: appliedTranslation.value }],
|
588
|
+
pointerEvents: rowState.value === 0 ? 'auto' : 'box-only',
|
589
|
+
}),
|
590
|
+
[appliedTranslation, rowState]
|
591
|
+
);
|
592
|
+
|
593
|
+
const containerStyle = props.containerStyle;
|
594
|
+
const childrenContainerStyle = props.childrenContainerStyle;
|
595
|
+
|
596
|
+
return (
|
597
|
+
<GestureDetector gesture={panGesture} touchAction="pan-y">
|
598
|
+
<Animated.View
|
599
|
+
onLayout={onRowLayout}
|
600
|
+
style={[styles.container, containerStyle]}>
|
601
|
+
{leftElement}
|
602
|
+
{rightElement}
|
603
|
+
<GestureDetector gesture={tapGesture} touchAction="pan-y">
|
604
|
+
<Animated.View style={[animatedStyle, childrenContainerStyle]}>
|
605
|
+
{children}
|
606
|
+
</Animated.View>
|
607
|
+
</GestureDetector>
|
608
|
+
</Animated.View>
|
609
|
+
</GestureDetector>
|
610
|
+
);
|
611
|
+
}
|
612
|
+
);
|
613
|
+
|
614
|
+
export default Swipeable;
|
615
|
+
export type SwipeableRef = ForwardedRef<SwipeableMethods>;
|
616
|
+
|
617
|
+
const styles = StyleSheet.create({
|
618
|
+
container: {
|
619
|
+
overflow: 'hidden',
|
620
|
+
},
|
621
|
+
leftActions: {
|
622
|
+
...StyleSheet.absoluteFillObject,
|
623
|
+
flexDirection: I18nManager.isRTL ? 'row-reverse' : 'row',
|
624
|
+
},
|
625
|
+
rightActions: {
|
626
|
+
...StyleSheet.absoluteFillObject,
|
627
|
+
flexDirection: I18nManager.isRTL ? 'row' : 'row-reverse',
|
628
|
+
},
|
629
|
+
});
|
@@ -20,13 +20,13 @@ import {
|
|
20
20
|
} from '../handlers/gestureHandlerCommon';
|
21
21
|
import {
|
22
22
|
PanGestureHandler,
|
23
|
-
PanGestureHandlerEventPayload,
|
24
23
|
PanGestureHandlerProps,
|
25
24
|
} from '../handlers/PanGestureHandler';
|
26
25
|
import {
|
27
|
-
|
26
|
+
PanGestureHandlerEventPayload,
|
28
27
|
TapGestureHandlerEventPayload,
|
29
|
-
} from '../handlers/
|
28
|
+
} from '../handlers/GestureHandlerEventPayload';
|
29
|
+
import { TapGestureHandler } from '../handlers/TapGestureHandler';
|
30
30
|
import { State } from '../State';
|
31
31
|
|
32
32
|
const DRAG_TOSS = 0.05;
|
@@ -222,6 +222,12 @@ type SwipeableState = {
|
|
222
222
|
rowWidth?: number;
|
223
223
|
};
|
224
224
|
|
225
|
+
/**
|
226
|
+
* @deprecated use Reanimated version of Swipeable instead
|
227
|
+
*
|
228
|
+
* This component allows for implementing swipeable rows or similar interaction.
|
229
|
+
*/
|
230
|
+
|
225
231
|
export default class Swipeable extends Component<
|
226
232
|
SwipeableProps,
|
227
233
|
SwipeableState
|
@@ -393,12 +399,12 @@ export default class Swipeable extends Component<
|
|
393
399
|
toValue = -rightWidth;
|
394
400
|
}
|
395
401
|
} else if (rowState === 1) {
|
396
|
-
//
|
402
|
+
// Swiped to left
|
397
403
|
if (translationX > -leftThreshold) {
|
398
404
|
toValue = leftWidth;
|
399
405
|
}
|
400
406
|
} else {
|
401
|
-
//
|
407
|
+
// Swiped to right
|
402
408
|
if (translationX < rightThreshold) {
|
403
409
|
toValue = -rightWidth;
|
404
410
|
}
|
@@ -509,7 +515,7 @@ export default class Swipeable extends Component<
|
|
509
515
|
<Animated.View
|
510
516
|
style={[
|
511
517
|
styles.leftActions,
|
512
|
-
//
|
518
|
+
// All those and below parameters can have ! since they are all
|
513
519
|
// asigned in constructor in `updateAnimatedEvent` but TS cannot spot
|
514
520
|
// it for some reason
|
515
521
|
{ transform: [{ translateX: this.leftActionTranslate! }] },
|