Skip to content

Commit 5f2d438

Browse files
authored
Filter config (#3710)
## Description This PR adds logic that filters `config` object before passing it to native side. ## Test plan <details> <summary>Tested on the following code:</summary> ```jsx import * as React from 'react'; import { Animated, Button } from 'react-native'; import { GestureHandlerRootView, NativeDetector, useTap, } from 'react-native-gesture-handler'; export default function App() { const [visible, setVisible] = React.useState(true); const gesture = useTap({ onEnd: (e) => { 'worklet'; console.log('tap', e.handlerData); }, numberOfTaps: 2, }); return ( <GestureHandlerRootView style={{ flex: 1, backgroundColor: 'white', paddingTop: 8 }}> <Button title="Toggle visibility" onPress={() => { setVisible(!visible); }} /> {visible && ( <NativeDetector gesture={gesture}> <Animated.View style={[ { width: 150, height: 150, backgroundColor: 'blue', opacity: 0.5, borderWidth: 10, borderColor: 'green', marginTop: 20, marginLeft: 40, }, ]} /> </NativeDetector> )} </GestureHandlerRootView> ); } ``` </details>
1 parent f83e085 commit 5f2d438

22 files changed

Lines changed: 493 additions & 318 deletions
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export type FlingGestureNativeProperties = {
2+
/**
3+
* Expressed allowed direction of movement. It's possible to pass one or many
4+
* directions in one parameter:
5+
*
6+
* ```js
7+
* direction={Directions.RIGHT | Directions.LEFT}
8+
* ```
9+
*
10+
* or
11+
*
12+
* ```js
13+
* direction={Directions.DOWN}
14+
* ```
15+
*/
16+
direction?: number;
17+
18+
/**
19+
* Determine exact number of points required to handle the fling gesture.
20+
*/
21+
numberOfPointers?: number;
22+
};
23+
24+
export const FlingNativeProperties = new Set<
25+
keyof FlingGestureNativeProperties
26+
>(['direction', 'numberOfPointers']);

packages/react-native-gesture-handler/src/v3/hooks/gestures/useFling.ts renamed to packages/react-native-gesture-handler/src/v3/hooks/gestures/fling/useFling.ts

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,10 @@ import {
33
ExcludeInternalConfigProps,
44
SingleGestureName,
55
WithSharedValue,
6-
} from '../../types';
7-
import { useGesture } from '../useGesture';
8-
import { cloneConfig } from '../utils';
9-
10-
type FlingGestureProperties = WithSharedValue<{
11-
/**
12-
* Expressed allowed direction of movement. It's possible to pass one or many
13-
* directions in one parameter:
14-
*
15-
* ```js
16-
* direction={Directions.RIGHT | Directions.LEFT}
17-
* ```
18-
*
19-
* or
20-
*
21-
* ```js
22-
* direction={Directions.DOWN}
23-
* ```
24-
*/
25-
direction?: number;
26-
27-
/**
28-
* Determine exact number of points required to handle the fling gesture.
29-
*/
30-
numberOfPointers?: number;
31-
}>;
6+
} from '../../../types';
7+
import { useGesture } from '../../useGesture';
8+
import { cloneConfig } from '../../utils';
9+
import type { FlingGestureNativeProperties } from './FlingProperties';
3210

3311
type FlingHandlerData = {
3412
x: number;
@@ -37,6 +15,8 @@ type FlingHandlerData = {
3715
absoluteY: number;
3816
};
3917

18+
type FlingGestureProperties = WithSharedValue<FlingGestureNativeProperties>;
19+
4020
type FlingGestureInternalConfig = BaseGestureConfig<
4121
FlingHandlerData,
4222
FlingGestureProperties
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { HoverEffect } from '../../../../handlers/gestures/hoverGesture';
2+
3+
export type HoverGestureNativeProperties = {
4+
/**
5+
* Visual effect applied to the view while the view is hovered. The possible values are:
6+
*
7+
* - `HoverEffect.None`
8+
* - `HoverEffect.Lift`
9+
* - `HoverEffect.Highlight`
10+
*
11+
* Defaults to `HoverEffect.None`
12+
*/
13+
hoverEffect?: HoverEffect;
14+
};
15+
16+
export const HoverNativeProperties = new Set<
17+
keyof HoverGestureNativeProperties
18+
>(['hoverEffect']);

packages/react-native-gesture-handler/src/v3/hooks/gestures/useHover.ts renamed to packages/react-native-gesture-handler/src/v3/hooks/gestures/hover/useHover.ts

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
1-
import { StylusData } from '../../../handlers/gestureHandlerCommon';
2-
import { HoverEffect } from '../../../handlers/gestures/hoverGesture';
1+
import { StylusData } from '../../../../handlers/gestureHandlerCommon';
2+
import { HoverEffect } from '../../../../handlers/gestures/hoverGesture';
33
import {
44
BaseGestureConfig,
55
ExcludeInternalConfigProps,
66
HandlerData,
77
SingleGestureName,
88
WithSharedValue,
9-
} from '../../types';
10-
import { useGesture } from '../useGesture';
11-
import { cloneConfig, getChangeEventCalculator } from '../utils';
12-
13-
type HoverGestureProperties = WithSharedValue<
14-
{
15-
/**
16-
* Visual effect applied to the view while the view is hovered. The possible values are:
17-
*
18-
* - `HoverEffect.None`
19-
* - `HoverEffect.Lift`
20-
* - `HoverEffect.Highlight`
21-
*
22-
* Defaults to `HoverEffect.None`
23-
*/
24-
hoverEffect?: HoverEffect;
25-
},
26-
HoverEffect
27-
>;
9+
} from '../../../types';
10+
import { useGesture } from '../../useGesture';
11+
import { cloneConfig, getChangeEventCalculator } from '../../utils';
12+
import { HoverGestureNativeProperties } from './HoverProperties';
2813

2914
type HoverHandlerData = {
3015
x: number;
@@ -36,6 +21,11 @@ type HoverHandlerData = {
3621
changeY: number;
3722
};
3823

24+
type HoverGestureProperties = WithSharedValue<
25+
HoverGestureNativeProperties,
26+
HoverEffect
27+
>;
28+
3929
type HoverGestureInternalConfig = BaseGestureConfig<
4030
HoverHandlerData,
4131
HoverGestureProperties
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
export type { TapGestureConfig } from './useTap';
2-
export { useTap } from './useTap';
1+
export type { TapGestureConfig } from './tap/useTap';
2+
export { useTap } from './tap/useTap';
33

4-
export type { FlingGestureConfig } from './useFling';
5-
export { useFling } from './useFling';
4+
export type { FlingGestureConfig } from './fling/useFling';
5+
export { useFling } from './fling/useFling';
66

7-
export type { LongPressGestureConfig } from './useLongPress';
8-
export { useLongPress } from './useLongPress';
7+
export type { LongPressGestureConfig } from './longPress/useLongPress';
8+
export { useLongPress } from './longPress/useLongPress';
99

10-
export type { PinchGestureConfig } from './usePinch';
11-
export { usePinch } from './usePinch';
10+
export type { PinchGestureConfig } from './pinch/usePinch';
11+
export { usePinch } from './pinch/usePinch';
1212

13-
export type { RotationGestureConfig } from './useRotation';
14-
export { useRotation } from './useRotation';
13+
export type { RotationGestureConfig } from './rotation/useRotation';
14+
export { useRotation } from './rotation/useRotation';
1515

16-
export type { HoverGestureConfig } from './useHover';
17-
export { useHover } from './useHover';
16+
export type { HoverGestureConfig } from './hover/useHover';
17+
export { useHover } from './hover/useHover';
1818

19-
export type { ManualGestureConfig } from './useManual';
20-
export { useManual } from './useManual';
19+
export type { ManualGestureConfig } from './manual/useManual';
20+
export { useManual } from './manual/useManual';
2121

22-
export type { NativeViewGestureConfig } from './useNative';
23-
export { useNative } from './useNative';
22+
export type { NativeViewGestureConfig } from './native/useNative';
23+
export { useNative } from './native/useNative';
2424

25-
export type { PanGestureConfig } from './usePan';
26-
export { usePan } from './usePan';
25+
export type { PanGestureConfig } from './pan/usePan';
26+
export { usePan } from './pan/usePan';
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
type CommonLongPressGestureProperties = {
2+
/**
3+
* Determine exact number of points required to handle the long press gesture.
4+
*/
5+
numberOfPointers?: number;
6+
};
7+
8+
export type LongPressGestureExternalProperties =
9+
CommonLongPressGestureProperties & {
10+
/**
11+
* Minimum time, expressed in milliseconds, that a finger must remain pressed on
12+
* the corresponding view. The default value is 500.
13+
*/
14+
minDuration?: number;
15+
16+
/**
17+
* Maximum distance, expressed in points, that defines how far the finger is
18+
* allowed to travel during a long press gesture. If the finger travels
19+
* further than the defined distance and the handler hasn't yet activated, it
20+
* will fail to recognize the gesture. The default value is 10.
21+
*/
22+
maxDistance?: number;
23+
};
24+
25+
export type LongPressGestureNativeProperties =
26+
CommonLongPressGestureProperties & {
27+
minDurationMs?: number;
28+
maxDist?: number;
29+
};
30+
31+
export const LongPressNativeProperties = new Set<
32+
keyof LongPressGestureNativeProperties
33+
>(['minDurationMs', 'maxDist', 'numberOfPointers']);

packages/react-native-gesture-handler/src/v3/hooks/gestures/useLongPress.ts renamed to packages/react-native-gesture-handler/src/v3/hooks/gestures/longPress/useLongPress.ts

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,13 @@ import {
33
ExcludeInternalConfigProps,
44
SingleGestureName,
55
WithSharedValue,
6-
} from '../../types';
7-
import { useGesture } from '../useGesture';
8-
import { cloneConfig, remapProps } from '../utils';
9-
10-
type LongPressGestureProperties = WithSharedValue<{
11-
/**
12-
* Minimum time, expressed in milliseconds, that a finger must remain pressed on
13-
* the corresponding view. The default value is 500.
14-
*/
15-
minDuration?: number;
16-
17-
/**
18-
* Maximum distance, expressed in points, that defines how far the finger is
19-
* allowed to travel during a long press gesture. If the finger travels
20-
* further than the defined distance and the handler hasn't yet activated, it
21-
* will fail to recognize the gesture. The default value is 10.
22-
*/
23-
maxDistance?: number;
24-
25-
/**
26-
* Determine exact number of points required to handle the long press gesture.
27-
*/
28-
numberOfPointers?: number;
29-
}>;
30-
31-
type LongPressGestureInternalProperties = WithSharedValue<{
32-
minDurationMs?: number;
33-
maxDist?: number;
34-
numberOfPointers?: number;
35-
}>;
6+
} from '../../../types';
7+
import { useGesture } from '../../useGesture';
8+
import { cloneConfig, remapProps } from '../../utils';
9+
import {
10+
LongPressGestureExternalProperties,
11+
LongPressGestureNativeProperties,
12+
} from './LongPressProperties';
3613

3714
type LongPressHandlerData = {
3815
x: number;
@@ -42,6 +19,12 @@ type LongPressHandlerData = {
4219
duration: number;
4320
};
4421

22+
type LongPressGestureProperties =
23+
WithSharedValue<LongPressGestureExternalProperties>;
24+
25+
type LongPressGestureInternalProperties =
26+
WithSharedValue<LongPressGestureNativeProperties>;
27+
4528
export type LongPressGestureConfig = ExcludeInternalConfigProps<
4629
BaseGestureConfig<LongPressHandlerData, LongPressGestureProperties>
4730
>;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type ManualGestureNativeProperties = Record<string, never>;

packages/react-native-gesture-handler/src/v3/hooks/gestures/useManual.ts renamed to packages/react-native-gesture-handler/src/v3/hooks/gestures/manual/useManual.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ import {
22
BaseGestureConfig,
33
ExcludeInternalConfigProps,
44
SingleGestureName,
5-
} from '../../types';
6-
import { useGesture } from '../useGesture';
7-
import { cloneConfig } from '../utils';
5+
} from '../../../types';
6+
import { useGesture } from '../../useGesture';
7+
import { cloneConfig } from '../../utils';
8+
import { ManualGestureNativeProperties } from './ManualProperties';
89

9-
type ManualGestureProperties = Record<string, never>;
1010
type ManualHandlerData = Record<string, never>;
1111

12+
type ManualGestureProperties = ManualGestureNativeProperties;
13+
1214
type ManualGestureInternalConfig = BaseGestureConfig<
1315
ManualHandlerData,
1416
ManualGestureProperties
1517
>;
16-
1718
export type ManualGestureConfig =
1819
ExcludeInternalConfigProps<ManualGestureInternalConfig>;
1920

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export type NativeGestureNativeProperties = {
2+
/**
3+
* Android only.
4+
*
5+
* Determines whether the handler should check for an existing touch event on
6+
* instantiation.
7+
*/
8+
shouldActivateOnStart?: boolean;
9+
10+
/**
11+
* When `true`, cancels all other gesture handlers when this
12+
* `NativeViewGestureHandler` receives an `ACTIVE` state event.
13+
*/
14+
disallowInterruption?: boolean;
15+
};
16+
17+
export const NativeHandlerNativeProperties = new Set<
18+
keyof NativeGestureNativeProperties
19+
>(['shouldActivateOnStart', 'disallowInterruption']);

0 commit comments

Comments
 (0)