react-native-gesture-handler 2.32.0 → 2.33.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/android/build.gradle +27 -11
- package/android/gradle.properties +1 -1
- package/android/src/main/java/com/swmansion/gesturehandler/core/FlingGestureHandler.kt +1 -1
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +32 -33
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +144 -15
- package/android/src/main/java/com/swmansion/gesturehandler/core/LongPressGestureHandler.kt +6 -3
- package/android/src/main/java/com/swmansion/gesturehandler/core/NativeViewGestureHandler.kt +23 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/PanGestureHandler.kt +4 -7
- package/android/src/main/java/com/swmansion/gesturehandler/core/TapGestureHandler.kt +1 -1
- package/android/src/main/java/com/swmansion/gesturehandler/react/Extensions.kt +3 -0
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +2 -0
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt +9 -0
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootView.kt +8 -6
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerTouchEvent.kt +2 -7
- package/apple/Handlers/RNFlingHandler.m +44 -4
- package/apple/Handlers/RNHoverHandler.m +24 -26
- package/apple/Handlers/RNLongPressHandler.m +4 -0
- package/apple/Handlers/RNPanHandler.m +44 -7
- package/apple/Handlers/RNTapHandler.m +35 -4
- package/apple/RNGHUIKit.h +10 -10
- package/apple/RNGestureHandler.h +2 -0
- package/apple/RNGestureHandler.mm +47 -6
- package/apple/RNGestureHandlerButton.mm +5 -3
- package/apple/RNGestureHandlerManager.mm +63 -6
- package/apple/RNGestureHandlerModule.mm +20 -0
- package/apple/RNGestureHandlerPointerTracker.m +64 -10
- package/apple/RNGestureHandlerPointerType.h +1 -0
- package/apple/RNManualActivationRecognizer.m +25 -6
- package/lib/commonjs/components/GestureComponents.js +21 -1
- package/lib/commonjs/components/GestureComponents.js.map +1 -1
- package/lib/commonjs/components/GestureHandlerButton.web.js +2 -1
- package/lib/commonjs/components/GestureHandlerButton.web.js.map +1 -1
- package/lib/commonjs/components/Pressable/Pressable.js +28 -3
- package/lib/commonjs/components/Pressable/Pressable.js.map +1 -1
- package/lib/commonjs/components/Pressable/index.js.map +1 -1
- package/lib/commonjs/components/ReanimatedDrawerLayout.js +4 -2
- package/lib/commonjs/components/ReanimatedDrawerLayout.js.map +1 -1
- package/lib/commonjs/components/ReanimatedSwipeable/ReanimatedSwipeable.js +32 -9
- package/lib/commonjs/components/ReanimatedSwipeable/ReanimatedSwipeable.js.map +1 -1
- package/lib/commonjs/components/Swipeable.js.map +1 -1
- package/lib/commonjs/components/Text.js.map +1 -1
- package/lib/commonjs/components/touchables/TouchableHighlight.js +1 -1
- package/lib/commonjs/components/touchables/TouchableHighlight.js.map +1 -1
- package/lib/commonjs/components/touchables/TouchableNativeFeedback.android.js.map +1 -1
- package/lib/commonjs/components/touchables/TouchableOpacity.js +1 -0
- package/lib/commonjs/components/touchables/TouchableOpacity.js.map +1 -1
- package/lib/commonjs/getShadowNodeFromRef.js +6 -2
- package/lib/commonjs/getShadowNodeFromRef.js.map +1 -1
- package/lib/commonjs/handlers/PanGestureHandler.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/Wrap.js +56 -11
- package/lib/commonjs/handlers/gestures/GestureDetector/Wrap.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/index.js +2 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/index.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/useDetectorUpdater.js +2 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/useDetectorUpdater.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/useMountReactions.js +6 -0
- package/lib/commonjs/handlers/gestures/GestureDetector/useMountReactions.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/useViewRefHandler.js +3 -2
- package/lib/commonjs/handlers/gestures/GestureDetector/useViewRefHandler.js.map +1 -1
- package/lib/commonjs/handlers/gestures/gestureStateManager.web.js.map +1 -1
- package/lib/commonjs/handlers/gestures/panGesture.js +6 -3
- package/lib/commonjs/handlers/gestures/panGesture.js.map +1 -1
- package/lib/commonjs/hostInstance.js +39 -0
- package/lib/commonjs/hostInstance.js.map +1 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mocks/mocks.js +1 -0
- package/lib/commonjs/mocks/mocks.js.map +1 -1
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.ts +16 -14
- package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.ts +3 -3
- package/lib/commonjs/web/detectors/RotationGestureDetector.js +1 -1
- package/lib/commonjs/web/handlers/LongPressGestureHandler.js +3 -1
- package/lib/commonjs/web/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/NativeViewGestureHandler.js +9 -1
- package/lib/commonjs/web/handlers/NativeViewGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/PanGestureHandler.js +8 -9
- package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/TapGestureHandler.js +1 -1
- package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js +14 -0
- package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js.map +1 -1
- package/lib/commonjs/web/tools/WheelEventManager.js +4 -0
- package/lib/commonjs/web/tools/WheelEventManager.js.map +1 -1
- package/lib/module/components/GestureComponents.js +23 -2
- package/lib/module/components/GestureComponents.js.map +1 -1
- package/lib/module/components/GestureHandlerButton.web.js +2 -1
- package/lib/module/components/GestureHandlerButton.web.js.map +1 -1
- package/lib/module/components/Pressable/Pressable.js +28 -3
- package/lib/module/components/Pressable/Pressable.js.map +1 -1
- package/lib/module/components/Pressable/index.js.map +1 -1
- package/lib/module/components/ReanimatedDrawerLayout.js +4 -2
- package/lib/module/components/ReanimatedDrawerLayout.js.map +1 -1
- package/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeable.js +34 -11
- package/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeable.js.map +1 -1
- package/lib/module/components/Swipeable.js.map +1 -1
- package/lib/module/components/Text.js.map +1 -1
- package/lib/module/components/touchables/TouchableHighlight.js +2 -2
- package/lib/module/components/touchables/TouchableHighlight.js.map +1 -1
- package/lib/module/components/touchables/TouchableNativeFeedback.android.js.map +1 -1
- package/lib/module/components/touchables/TouchableOpacity.js +1 -0
- package/lib/module/components/touchables/TouchableOpacity.js.map +1 -1
- package/lib/module/getShadowNodeFromRef.js +7 -2
- package/lib/module/getShadowNodeFromRef.js.map +1 -1
- package/lib/module/handlers/PanGestureHandler.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/Wrap.js +56 -11
- package/lib/module/handlers/gestures/GestureDetector/Wrap.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/index.js +2 -1
- package/lib/module/handlers/gestures/GestureDetector/index.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/useDetectorUpdater.js +2 -1
- package/lib/module/handlers/gestures/GestureDetector/useDetectorUpdater.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/useMountReactions.js +6 -0
- package/lib/module/handlers/gestures/GestureDetector/useMountReactions.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/useViewRefHandler.js +3 -2
- package/lib/module/handlers/gestures/GestureDetector/useViewRefHandler.js.map +1 -1
- package/lib/module/handlers/gestures/gestureStateManager.web.js.map +1 -1
- package/lib/module/handlers/gestures/panGesture.js +6 -3
- package/lib/module/handlers/gestures/panGesture.js.map +1 -1
- package/lib/module/hostInstance.js +32 -0
- package/lib/module/hostInstance.js.map +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/mocks/mocks.js +3 -2
- package/lib/module/mocks/mocks.js.map +1 -1
- package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -1
- package/lib/module/specs/RNGestureHandlerButtonNativeComponent.ts +16 -14
- package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.ts +3 -3
- package/lib/module/web/detectors/RotationGestureDetector.js +1 -1
- package/lib/module/web/handlers/LongPressGestureHandler.js +3 -1
- package/lib/module/web/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/NativeViewGestureHandler.js +9 -1
- package/lib/module/web/handlers/NativeViewGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/PanGestureHandler.js +8 -9
- package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/TapGestureHandler.js +1 -1
- package/lib/module/web/tools/GestureHandlerOrchestrator.js +14 -0
- package/lib/module/web/tools/GestureHandlerOrchestrator.js.map +1 -1
- package/lib/module/web/tools/WheelEventManager.js +4 -0
- package/lib/module/web/tools/WheelEventManager.js.map +1 -1
- package/lib/typescript/components/GestureButtons.d.ts +3 -1
- package/lib/typescript/components/GestureButtons.d.ts.map +1 -1
- package/lib/typescript/components/GestureButtonsProps.d.ts +10 -0
- package/lib/typescript/components/GestureButtonsProps.d.ts.map +1 -1
- package/lib/typescript/components/GestureComponents.d.ts +8 -7
- package/lib/typescript/components/GestureComponents.d.ts.map +1 -1
- package/lib/typescript/components/GestureComponents.web.d.ts +12 -4
- package/lib/typescript/components/GestureComponents.web.d.ts.map +1 -1
- package/lib/typescript/components/GestureHandlerButton.web.d.ts +2 -2
- package/lib/typescript/components/GestureHandlerButton.web.d.ts.map +1 -1
- package/lib/typescript/components/Pressable/Pressable.d.ts.map +1 -1
- package/lib/typescript/components/Pressable/PressableProps.d.ts +1 -1
- package/lib/typescript/components/Pressable/PressableProps.d.ts.map +1 -1
- package/lib/typescript/components/Pressable/index.d.ts +1 -1
- package/lib/typescript/components/Pressable/index.d.ts.map +1 -1
- package/lib/typescript/components/ReanimatedDrawerLayout.d.ts.map +1 -1
- package/lib/typescript/components/ReanimatedSwipeable/ReanimatedSwipeable.d.ts.map +1 -1
- package/lib/typescript/components/Swipeable.d.ts.map +1 -1
- package/lib/typescript/components/touchables/TouchableHighlight.d.ts +1 -1
- package/lib/typescript/components/touchables/TouchableHighlight.d.ts.map +1 -1
- package/lib/typescript/components/touchables/TouchableNativeFeedback.android.d.ts +1 -1
- package/lib/typescript/components/touchables/TouchableNativeFeedback.android.d.ts.map +1 -1
- package/lib/typescript/components/touchables/TouchableOpacity.d.ts.map +1 -1
- package/lib/typescript/getShadowNodeFromRef.d.ts.map +1 -1
- package/lib/typescript/handlers/PanGestureHandler.d.ts +12 -0
- package/lib/typescript/handlers/PanGestureHandler.d.ts.map +1 -1
- package/lib/typescript/handlers/gestures/GestureDetector/Wrap.d.ts +11 -0
- package/lib/typescript/handlers/gestures/GestureDetector/Wrap.d.ts.map +1 -1
- package/lib/typescript/handlers/gestures/GestureDetector/index.d.ts.map +1 -1
- package/lib/typescript/handlers/gestures/GestureDetector/useDetectorUpdater.d.ts.map +1 -1
- package/lib/typescript/handlers/gestures/GestureDetector/useMountReactions.d.ts.map +1 -1
- package/lib/typescript/handlers/gestures/GestureDetector/useViewRefHandler.d.ts.map +1 -1
- package/lib/typescript/handlers/gestures/gestureStateManager.web.d.ts +8 -1
- package/lib/typescript/handlers/gestures/gestureStateManager.web.d.ts.map +1 -1
- package/lib/typescript/handlers/gestures/panGesture.d.ts +6 -3
- package/lib/typescript/handlers/gestures/panGesture.d.ts.map +1 -1
- package/lib/typescript/hostInstance.d.ts +10 -0
- package/lib/typescript/hostInstance.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/mocks/mocks.d.ts +67 -15
- package/lib/typescript/mocks/mocks.d.ts.map +1 -1
- package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +6 -7
- package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts.map +1 -1
- package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +9 -10
- package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts.map +1 -1
- package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +2 -2
- package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/web/handlers/LongPressGestureHandler.d.ts.map +1 -1
- package/lib/typescript/web/handlers/NativeViewGestureHandler.d.ts +1 -0
- package/lib/typescript/web/handlers/NativeViewGestureHandler.d.ts.map +1 -1
- package/lib/typescript/web/handlers/PanGestureHandler.d.ts.map +1 -1
- package/lib/typescript/web/tools/GestureHandlerOrchestrator.d.ts +1 -0
- package/lib/typescript/web/tools/GestureHandlerOrchestrator.d.ts.map +1 -1
- package/lib/typescript/web/tools/WheelEventManager.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/components/GestureButtonsProps.ts +14 -0
- package/src/components/GestureComponents.tsx +38 -7
- package/src/components/GestureHandlerButton.web.tsx +7 -3
- package/src/components/Pressable/Pressable.tsx +33 -4
- package/src/components/Pressable/PressableProps.tsx +1 -1
- package/src/components/Pressable/index.ts +1 -0
- package/src/components/ReanimatedDrawerLayout.tsx +4 -1
- package/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx +49 -10
- package/src/components/Swipeable.tsx +6 -2
- package/src/components/Text.tsx +3 -3
- package/src/components/touchables/TouchableHighlight.tsx +4 -2
- package/src/components/touchables/TouchableNativeFeedback.android.tsx +8 -2
- package/src/components/touchables/TouchableOpacity.tsx +1 -0
- package/src/getShadowNodeFromRef.ts +11 -4
- package/src/handlers/PanGestureHandler.ts +15 -0
- package/src/handlers/gestures/GestureDetector/Wrap.tsx +78 -13
- package/src/handlers/gestures/GestureDetector/index.tsx +4 -1
- package/src/handlers/gestures/GestureDetector/useDetectorUpdater.ts +4 -1
- package/src/handlers/gestures/GestureDetector/useMountReactions.ts +6 -0
- package/src/handlers/gestures/GestureDetector/useViewRefHandler.ts +5 -2
- package/src/handlers/gestures/gestureStateManager.web.ts +9 -1
- package/src/handlers/gestures/panGesture.ts +6 -3
- package/src/hostInstance.ts +57 -0
- package/src/index.ts +1 -0
- package/src/mocks/mocks.tsx +6 -2
- package/src/specs/NativeRNGestureHandlerModule.ts +16 -10
- package/src/specs/RNGestureHandlerButtonNativeComponent.ts +16 -14
- package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +3 -3
- package/src/web/detectors/RotationGestureDetector.ts +1 -1
- package/src/web/handlers/LongPressGestureHandler.ts +3 -1
- package/src/web/handlers/NativeViewGestureHandler.ts +11 -2
- package/src/web/handlers/PanGestureHandler.ts +8 -11
- package/src/web/handlers/TapGestureHandler.ts +1 -1
- package/src/web/tools/GestureHandlerOrchestrator.ts +19 -0
- package/src/web/tools/WheelEventManager.ts +1 -0
|
@@ -6,6 +6,7 @@ import { GestureType } from '../gesture';
|
|
|
6
6
|
import { UserSelect, TouchAction } from '../../gestureHandlerCommon';
|
|
7
7
|
import { ComposedGesture } from '../gestureComposition';
|
|
8
8
|
import { isTestEnv } from '../../../utils';
|
|
9
|
+
import { resolveHostInstance } from '../../../hostInstance';
|
|
9
10
|
|
|
10
11
|
import GestureHandlerRootViewContext from '../../../GestureHandlerRootViewContext';
|
|
11
12
|
import { AttachedGestureState, GestureDetectorState } from './types';
|
|
@@ -149,7 +150,9 @@ export const GestureDetector = (props: GestureDetectorProps) => {
|
|
|
149
150
|
useAnimatedGesture(preparedGesture, needsToRebuildReanimatedEvent);
|
|
150
151
|
|
|
151
152
|
useIsomorphicLayoutEffect(() => {
|
|
152
|
-
const viewTag = findNodeHandle(
|
|
153
|
+
const viewTag = findNodeHandle(
|
|
154
|
+
resolveHostInstance(state.viewRef)
|
|
155
|
+
) as number;
|
|
153
156
|
preparedGesture.isMounted = true;
|
|
154
157
|
|
|
155
158
|
attachHandlers({
|
|
@@ -2,6 +2,7 @@ import React, { useCallback } from 'react';
|
|
|
2
2
|
import { GestureType } from '../gesture';
|
|
3
3
|
import { ComposedGesture } from '../gestureComposition';
|
|
4
4
|
|
|
5
|
+
import { resolveHostInstance } from '../../../hostInstance';
|
|
5
6
|
import {
|
|
6
7
|
AttachedGestureState,
|
|
7
8
|
GestureDetectorState,
|
|
@@ -29,7 +30,9 @@ export function useDetectorUpdater(
|
|
|
29
30
|
// skipConfigUpdate is used to prevent unnecessary updates when only checking if the view has changed
|
|
30
31
|
(skipConfigUpdate?: boolean) => {
|
|
31
32
|
// If the underlying view has changed we need to reattach handlers to the new view
|
|
32
|
-
const viewTag = findNodeHandle(
|
|
33
|
+
const viewTag = findNodeHandle(
|
|
34
|
+
resolveHostInstance(state.viewRef)
|
|
35
|
+
) as number;
|
|
33
36
|
const didUnderlyingViewChange = viewTag !== state.previousViewTag;
|
|
34
37
|
|
|
35
38
|
if (
|
|
@@ -27,6 +27,12 @@ export function useMountReactions(
|
|
|
27
27
|
) {
|
|
28
28
|
useEffect(() => {
|
|
29
29
|
return MountRegistry.addMountListener((gesture) => {
|
|
30
|
+
// The detector may already be unmounted when this fires; bail out to avoid
|
|
31
|
+
// updating a detached detector.
|
|
32
|
+
if (!state.isMounted) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
30
36
|
// At this point the ref in the gesture config should be updated, so we can check if one of the gestures
|
|
31
37
|
// set in a relation with the gesture got mounted. If so, we need to update the detector to propagate
|
|
32
38
|
// the changes to the native side.
|
|
@@ -4,6 +4,7 @@ import { getShadowNodeFromRef } from '../../../getShadowNodeFromRef';
|
|
|
4
4
|
import { GestureDetectorState } from './types';
|
|
5
5
|
import React, { useCallback } from 'react';
|
|
6
6
|
import findNodeHandle from '../../../findNodeHandle';
|
|
7
|
+
import { resolveHostInstance } from '../../../hostInstance';
|
|
7
8
|
|
|
8
9
|
declare const global: {
|
|
9
10
|
isViewFlatteningDisabled: (node: unknown) => boolean | null; // JSI function
|
|
@@ -26,7 +27,9 @@ export function useViewRefHandler(
|
|
|
26
27
|
|
|
27
28
|
// if it's the first render, also set the previousViewTag to prevent reattaching gestures when not needed
|
|
28
29
|
if (state.previousViewTag === -1) {
|
|
29
|
-
state.previousViewTag = findNodeHandle(
|
|
30
|
+
state.previousViewTag = findNodeHandle(
|
|
31
|
+
resolveHostInstance(state.viewRef)
|
|
32
|
+
) as number;
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
// Pass true as `skipConfigUpdate`. Here we only want to trigger the eventual reattaching of handlers
|
|
@@ -36,7 +39,7 @@ export function useViewRefHandler(
|
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
if (__DEV__ && isFabric() && global.isViewFlatteningDisabled) {
|
|
39
|
-
const node = getShadowNodeFromRef(ref);
|
|
42
|
+
const node = getShadowNodeFromRef(resolveHostInstance(ref));
|
|
40
43
|
if (global.isViewFlatteningDisabled(node) === false) {
|
|
41
44
|
console.error(
|
|
42
45
|
tagMessage(
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import NodeManager from '../../web/tools/NodeManager';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
export interface GestureStateManagerType {
|
|
4
|
+
begin: () => void;
|
|
5
|
+
activate: () => void;
|
|
6
|
+
fail: () => void;
|
|
7
|
+
end: () => void;
|
|
8
|
+
/** @internal */
|
|
9
|
+
handlerTag: number;
|
|
10
|
+
}
|
|
3
11
|
|
|
4
12
|
export const GestureStateManager = {
|
|
5
13
|
create(handlerTag: number): GestureStateManagerType {
|
|
@@ -147,7 +147,8 @@ export class PanGesture extends ContinousBaseGesture<
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
/**
|
|
150
|
-
* Minimum
|
|
150
|
+
* Minimum speed the pointer has to reach in order to activate handler.
|
|
151
|
+
* Expressed in points per second.
|
|
151
152
|
* @param velocity
|
|
152
153
|
*/
|
|
153
154
|
minVelocity(velocity: number) {
|
|
@@ -156,7 +157,8 @@ export class PanGesture extends ContinousBaseGesture<
|
|
|
156
157
|
}
|
|
157
158
|
|
|
158
159
|
/**
|
|
159
|
-
* Minimum
|
|
160
|
+
* Minimum speed along X axis the pointer has to reach in order to activate handler.
|
|
161
|
+
* Expressed in points per second.
|
|
160
162
|
* @param velocity
|
|
161
163
|
*/
|
|
162
164
|
minVelocityX(velocity: number) {
|
|
@@ -165,7 +167,8 @@ export class PanGesture extends ContinousBaseGesture<
|
|
|
165
167
|
}
|
|
166
168
|
|
|
167
169
|
/**
|
|
168
|
-
* Minimum
|
|
170
|
+
* Minimum speed along Y axis the pointer has to reach in order to activate handler.
|
|
171
|
+
* Expressed in points per second.
|
|
169
172
|
* @param velocity
|
|
170
173
|
*/
|
|
171
174
|
minVelocityY(velocity: number) {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Ref } from 'react';
|
|
2
|
+
|
|
3
|
+
export type WrapRef = Ref<unknown> | undefined;
|
|
4
|
+
|
|
5
|
+
export function assignRef(
|
|
6
|
+
ref: WrapRef,
|
|
7
|
+
instance: unknown
|
|
8
|
+
): (() => void) | undefined {
|
|
9
|
+
if (typeof ref === 'function') {
|
|
10
|
+
const cleanup = ref(instance as never);
|
|
11
|
+
return typeof cleanup === 'function' ? cleanup : undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (ref) {
|
|
15
|
+
ref.current = instance;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function isHostInstance(instance: unknown) {
|
|
22
|
+
return (
|
|
23
|
+
(instance as { __internalInstanceHandle?: unknown } | null | undefined)
|
|
24
|
+
?.__internalInstanceHandle !== undefined
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function preferHostInstance(instance: unknown) {
|
|
29
|
+
if (instance === null || instance === undefined || isHostInstance(instance)) {
|
|
30
|
+
return instance;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const nativeRef = (
|
|
34
|
+
instance as { getNativeScrollRef?: () => unknown }
|
|
35
|
+
).getNativeScrollRef?.();
|
|
36
|
+
|
|
37
|
+
return isHostInstance(nativeRef) ? nativeRef : instance;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface HostInstanceProvider {
|
|
41
|
+
getHostInstance: () => unknown;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function providesHostInstance(ref: unknown): ref is HostInstanceProvider {
|
|
45
|
+
return (
|
|
46
|
+
typeof (ref as HostInstanceProvider | null | undefined)?.getHostInstance ===
|
|
47
|
+
'function'
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function resolveHostInstance<T>(ref: T): T {
|
|
52
|
+
if (!providesHostInstance(ref)) {
|
|
53
|
+
return ref;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return (ref.getHostInstance() ?? ref) as T;
|
|
57
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -146,6 +146,7 @@ export type {
|
|
|
146
146
|
export type { SwipeableProps } from './components/Swipeable';
|
|
147
147
|
export { default as Swipeable } from './components/Swipeable';
|
|
148
148
|
export type {
|
|
149
|
+
PressableEvent,
|
|
149
150
|
PressableProps,
|
|
150
151
|
PressableStateCallbackType,
|
|
151
152
|
} from './components/Pressable';
|
package/src/mocks/mocks.tsx
CHANGED
|
@@ -8,7 +8,9 @@ import {
|
|
|
8
8
|
FlatList,
|
|
9
9
|
Switch,
|
|
10
10
|
TextInput,
|
|
11
|
+
TextInputProps,
|
|
11
12
|
DrawerLayoutAndroid,
|
|
13
|
+
DrawerLayoutAndroidProps,
|
|
12
14
|
View,
|
|
13
15
|
} from 'react-native';
|
|
14
16
|
import { State } from '../State';
|
|
@@ -48,8 +50,10 @@ export default {
|
|
|
48
50
|
ScrollView,
|
|
49
51
|
FlatList,
|
|
50
52
|
Switch,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
// Explicit types keep the emitted declaration portable under TS 6.
|
|
54
|
+
TextInput: TextInput as React.ComponentType<TextInputProps>,
|
|
55
|
+
DrawerLayoutAndroid:
|
|
56
|
+
DrawerLayoutAndroid as React.ComponentType<DrawerLayoutAndroidProps>,
|
|
53
57
|
NativeViewGestureHandler,
|
|
54
58
|
TapGestureHandler,
|
|
55
59
|
ForceTouchGestureHandler,
|
|
@@ -1,24 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { CodegenTypes, TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
3
|
|
|
4
4
|
export interface Spec extends TurboModule {
|
|
5
|
-
handleSetJSResponder: (
|
|
5
|
+
handleSetJSResponder: (
|
|
6
|
+
tag: CodegenTypes.Double,
|
|
7
|
+
blockNativeResponder: boolean
|
|
8
|
+
) => void;
|
|
6
9
|
handleClearJSResponder: () => void;
|
|
7
10
|
createGestureHandler: (
|
|
8
11
|
handlerName: string,
|
|
9
|
-
handlerTag: Double,
|
|
12
|
+
handlerTag: CodegenTypes.Double,
|
|
10
13
|
// Record<> is not supported by codegen
|
|
11
14
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
12
15
|
config: Object
|
|
13
16
|
) => void;
|
|
14
17
|
attachGestureHandler: (
|
|
15
|
-
handlerTag: Double,
|
|
16
|
-
newView: Double,
|
|
17
|
-
actionType: Double
|
|
18
|
+
handlerTag: CodegenTypes.Double,
|
|
19
|
+
newView: CodegenTypes.Double,
|
|
20
|
+
actionType: CodegenTypes.Double
|
|
21
|
+
) => void;
|
|
22
|
+
updateGestureHandler: (
|
|
23
|
+
handlerTag: CodegenTypes.Double,
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
25
|
+
newConfig: Object
|
|
18
26
|
) => void;
|
|
19
|
-
|
|
20
|
-
updateGestureHandler: (handlerTag: Double, newConfig: Object) => void;
|
|
21
|
-
dropGestureHandler: (handlerTag: Double) => void;
|
|
27
|
+
dropGestureHandler: (handlerTag: CodegenTypes.Double) => void;
|
|
22
28
|
install: () => boolean;
|
|
23
29
|
flushOperations: () => void;
|
|
24
30
|
}
|
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
import codegenNativeComponent from 'react-native
|
|
1
|
+
import { codegenNativeComponent } from 'react-native';
|
|
2
2
|
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
CodegenTypes,
|
|
4
|
+
HostComponent,
|
|
5
|
+
ViewProps,
|
|
6
|
+
ColorValue,
|
|
7
|
+
} from 'react-native';
|
|
8
8
|
|
|
9
9
|
// @ts-ignore - Redefining pointerEvents with WithDefault for codegen, conflicts with ViewProps type but codegen needs it
|
|
10
10
|
interface NativeProps extends ViewProps {
|
|
11
|
-
exclusive?: WithDefault<boolean, true>;
|
|
11
|
+
exclusive?: CodegenTypes.WithDefault<boolean, true>;
|
|
12
12
|
foreground?: boolean;
|
|
13
13
|
borderless?: boolean;
|
|
14
|
-
enabled?: WithDefault<boolean, true>;
|
|
14
|
+
enabled?: CodegenTypes.WithDefault<boolean, true>;
|
|
15
15
|
rippleColor?: ColorValue;
|
|
16
|
-
rippleRadius?: Int32;
|
|
17
|
-
touchSoundDisabled?: WithDefault<boolean, false>;
|
|
18
|
-
borderWidth?: Float;
|
|
16
|
+
rippleRadius?: CodegenTypes.Int32;
|
|
17
|
+
touchSoundDisabled?: CodegenTypes.WithDefault<boolean, false>;
|
|
18
|
+
borderWidth?: CodegenTypes.Float;
|
|
19
19
|
borderColor?: ColorValue;
|
|
20
|
-
borderStyle?: WithDefault<string, 'solid'>;
|
|
21
|
-
pointerEvents?: WithDefault<
|
|
20
|
+
borderStyle?: CodegenTypes.WithDefault<string, 'solid'>;
|
|
21
|
+
pointerEvents?: CodegenTypes.WithDefault<
|
|
22
22
|
'box-none' | 'none' | 'box-only' | 'auto',
|
|
23
23
|
'auto'
|
|
24
24
|
>;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export default codegenNativeComponent<NativeProps>(
|
|
27
|
+
export default codegenNativeComponent<NativeProps>(
|
|
28
|
+
'RNGestureHandlerButton'
|
|
29
|
+
) as HostComponent<NativeProps>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import codegenNativeComponent from 'react-native
|
|
2
|
-
import type { ViewProps } from 'react-native';
|
|
1
|
+
import { codegenNativeComponent } from 'react-native';
|
|
2
|
+
import type { HostComponent, ViewProps } from 'react-native';
|
|
3
3
|
|
|
4
4
|
export interface RootViewNativeProps extends ViewProps {
|
|
5
5
|
unstable_forceActive?: boolean;
|
|
@@ -7,4 +7,4 @@ export interface RootViewNativeProps extends ViewProps {
|
|
|
7
7
|
|
|
8
8
|
export default codegenNativeComponent<RootViewNativeProps>(
|
|
9
9
|
'RNGestureHandlerRootView'
|
|
10
|
-
)
|
|
10
|
+
) as HostComponent<RootViewNativeProps>;
|
|
@@ -5,6 +5,7 @@ import GestureHandler from './GestureHandler';
|
|
|
5
5
|
|
|
6
6
|
const DEFAULT_MIN_DURATION_MS = 500;
|
|
7
7
|
const DEFAULT_MAX_DIST_DP = 10;
|
|
8
|
+
const DEFAULT_NUMBER_OF_POINTERS = 1;
|
|
8
9
|
const SCALING_FACTOR = 10;
|
|
9
10
|
|
|
10
11
|
export default class LongPressGestureHandler extends GestureHandler {
|
|
@@ -12,7 +13,7 @@ export default class LongPressGestureHandler extends GestureHandler {
|
|
|
12
13
|
private defaultMaxDistSq = DEFAULT_MAX_DIST_DP * SCALING_FACTOR;
|
|
13
14
|
|
|
14
15
|
private maxDistSq = this.defaultMaxDistSq;
|
|
15
|
-
private numberOfPointers =
|
|
16
|
+
private numberOfPointers = DEFAULT_NUMBER_OF_POINTERS;
|
|
16
17
|
private startX = 0;
|
|
17
18
|
private startY = 0;
|
|
18
19
|
|
|
@@ -56,6 +57,7 @@ export default class LongPressGestureHandler extends GestureHandler {
|
|
|
56
57
|
super.resetConfig();
|
|
57
58
|
this.minDurationMs = DEFAULT_MIN_DURATION_MS;
|
|
58
59
|
this.maxDistSq = this.defaultMaxDistSq;
|
|
60
|
+
this.numberOfPointers = DEFAULT_NUMBER_OF_POINTERS;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
protected onStateChange(_newState: State, _oldState: State): void {
|
|
@@ -20,8 +20,6 @@ export default class NativeViewGestureHandler extends GestureHandler {
|
|
|
20
20
|
public init(ref: number, propsRef: React.RefObject<unknown>): void {
|
|
21
21
|
super.init(ref, propsRef);
|
|
22
22
|
|
|
23
|
-
this.shouldCancelWhenOutside = true;
|
|
24
|
-
|
|
25
23
|
if (Platform.OS !== 'web') {
|
|
26
24
|
return;
|
|
27
25
|
}
|
|
@@ -33,6 +31,9 @@ export default class NativeViewGestureHandler extends GestureHandler {
|
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
public updateGestureConfig({ enabled = true, ...props }: Config): void {
|
|
34
|
+
// Config updates are full replaces, so restore the defaults first - the
|
|
35
|
+
// module never calls `resetConfig` on its own.
|
|
36
|
+
this.resetConfig();
|
|
36
37
|
super.updateGestureConfig({ enabled: enabled, ...props });
|
|
37
38
|
|
|
38
39
|
if (this.config.shouldActivateOnStart !== undefined) {
|
|
@@ -46,6 +47,14 @@ export default class NativeViewGestureHandler extends GestureHandler {
|
|
|
46
47
|
this.restoreViewStyles(view);
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
protected override resetConfig(): void {
|
|
51
|
+
super.resetConfig();
|
|
52
|
+
|
|
53
|
+
this.shouldCancelWhenOutside = true;
|
|
54
|
+
this.shouldActivateOnStart = false;
|
|
55
|
+
this.disallowInterruption = false;
|
|
56
|
+
}
|
|
57
|
+
|
|
49
58
|
private restoreViewStyles(view: HTMLElement) {
|
|
50
59
|
if (!view) {
|
|
51
60
|
return;
|
|
@@ -82,8 +82,7 @@ export default class PanGestureHandler extends GestureHandler {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
if (this.config.minVelocity !== undefined) {
|
|
85
|
-
this.
|
|
86
|
-
this.minVelocityY = this.config.minVelocity;
|
|
85
|
+
this.minVelocitySq = this.config.minVelocity * this.config.minVelocity;
|
|
87
86
|
}
|
|
88
87
|
|
|
89
88
|
if (this.config.minVelocityX !== undefined) {
|
|
@@ -191,6 +190,7 @@ export default class PanGestureHandler extends GestureHandler {
|
|
|
191
190
|
this.maxPointers = DEFAULT_MAX_POINTERS;
|
|
192
191
|
|
|
193
192
|
this.activateAfterLongPress = 0;
|
|
193
|
+
this.enableTrackpadTwoFingerGesture = false;
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
protected transformNativeEvent() {
|
|
@@ -354,14 +354,13 @@ export default class PanGestureHandler extends GestureHandler {
|
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
-
private scheduleWheelEnd(
|
|
357
|
+
private scheduleWheelEnd() {
|
|
358
358
|
clearTimeout(this.endWheelTimeout);
|
|
359
359
|
|
|
360
360
|
this.endWheelTimeout = setTimeout(() => {
|
|
361
361
|
if (this.state === State.ACTIVE) {
|
|
362
362
|
this.end();
|
|
363
|
-
this.
|
|
364
|
-
this.state = State.UNDETERMINED;
|
|
363
|
+
this.reset();
|
|
365
364
|
}
|
|
366
365
|
|
|
367
366
|
this.wheelDevice = WheelDevice.UNDETERMINED;
|
|
@@ -383,7 +382,7 @@ export default class PanGestureHandler extends GestureHandler {
|
|
|
383
382
|
: WheelDevice.MOUSE;
|
|
384
383
|
|
|
385
384
|
if (this.wheelDevice === WheelDevice.MOUSE) {
|
|
386
|
-
this.scheduleWheelEnd(
|
|
385
|
+
this.scheduleWheelEnd();
|
|
387
386
|
return;
|
|
388
387
|
}
|
|
389
388
|
|
|
@@ -403,7 +402,7 @@ export default class PanGestureHandler extends GestureHandler {
|
|
|
403
402
|
this.updateVelocity(event.pointerId);
|
|
404
403
|
|
|
405
404
|
this.tryToSendMoveEvent(false, event);
|
|
406
|
-
this.scheduleWheelEnd(
|
|
405
|
+
this.scheduleWheelEnd();
|
|
407
406
|
}
|
|
408
407
|
|
|
409
408
|
private shouldActivate(): boolean {
|
|
@@ -452,8 +451,7 @@ export default class PanGestureHandler extends GestureHandler {
|
|
|
452
451
|
|
|
453
452
|
if (
|
|
454
453
|
this.minVelocityX !== Number.MAX_SAFE_INTEGER &&
|
|
455
|
-
(
|
|
456
|
-
(this.minVelocityX >= 0 && this.minVelocityX <= vx))
|
|
454
|
+
Math.abs(vx) >= Math.abs(this.minVelocityX)
|
|
457
455
|
) {
|
|
458
456
|
return true;
|
|
459
457
|
}
|
|
@@ -461,8 +459,7 @@ export default class PanGestureHandler extends GestureHandler {
|
|
|
461
459
|
const vy: number = this.velocityY;
|
|
462
460
|
if (
|
|
463
461
|
this.minVelocityY !== Number.MAX_SAFE_INTEGER &&
|
|
464
|
-
(
|
|
465
|
-
(this.minVelocityY >= 0 && this.minVelocityY <= vy))
|
|
462
|
+
Math.abs(vy) >= Math.abs(this.minVelocityY)
|
|
466
463
|
) {
|
|
467
464
|
return true;
|
|
468
465
|
}
|
|
@@ -159,7 +159,7 @@ export default class TapGestureHandler extends GestureHandler {
|
|
|
159
159
|
this.tracker.removeFromTracker(event.pointerId);
|
|
160
160
|
|
|
161
161
|
this.offsetX += this.lastX - this.startX;
|
|
162
|
-
this.offsetY += this.lastY
|
|
162
|
+
this.offsetY += this.lastY - this.startY;
|
|
163
163
|
|
|
164
164
|
this.updateLastCoords();
|
|
165
165
|
|
|
@@ -264,7 +264,26 @@ export default class GestureHandlerOrchestrator {
|
|
|
264
264
|
handler.activationIndex = this.activationIndex++;
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
+
// A handler whose pointer sequence ended before it began (e.g. a press
|
|
268
|
+
// outside a negative hit slop) never reaches a finished state, so
|
|
269
|
+
// `cleanupFinishedHandlers` never drops it and it would block or park every
|
|
270
|
+
// later gesture. Drop such idle entries before a new gesture consults them.
|
|
271
|
+
private dropIdleHandlers(): void {
|
|
272
|
+
for (let i = this.gestureHandlers.length - 1; i >= 0; --i) {
|
|
273
|
+
const handler = this.gestureHandlers[i];
|
|
274
|
+
|
|
275
|
+
if (
|
|
276
|
+
handler.state === State.UNDETERMINED &&
|
|
277
|
+
handler.tracker.trackedPointersCount === 0
|
|
278
|
+
) {
|
|
279
|
+
this.removeHandlerFromOrchestrator(handler);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
267
284
|
public recordHandlerIfNotPresent(handler: IGestureHandler): void {
|
|
285
|
+
this.dropIdleHandlers();
|
|
286
|
+
|
|
268
287
|
if (this.gestureHandlers.includes(handler)) {
|
|
269
288
|
return;
|
|
270
289
|
}
|