Skip to content

Commit cbaffd2

Browse files
committed
Merge branch '@mbert/gesture-hooks' into @mbert/add-event-calculators
2 parents ff6a3c6 + b496adf commit cbaffd2

File tree

14 files changed

+156
-90
lines changed

14 files changed

+156
-90
lines changed

packages/react-native-gesture-handler/src/handlers/gestures/GestureDetector/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,8 @@ export function useWebEventHandlers() {
175175
onGestureHandlerStateChange: (e: ResultEvent) => {
176176
onGestureHandlerEvent(e.nativeEvent as GestureHandlerNativeEvent);
177177
},
178+
onGestureHandlerTouchEvent: () => {
179+
// no-op
180+
},
178181
});
179182
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import { useGesture } from '../useGesture';
77
import { cloneConfig } from '../utils';
88

9-
type FlingGestureProps = {
9+
type FlingGestureProperties = {
1010
/**
1111
* Expressed allowed direction of movement. It's possible to pass one or many
1212
* directions in one parameter:
@@ -38,14 +38,16 @@ type FlingHandlerData = {
3838

3939
type FlingGestureInternalConfig = BaseGestureConfig<
4040
FlingHandlerData,
41-
FlingGestureProps
41+
FlingGestureProperties
4242
>;
4343

4444
export type FlingGestureConfig =
4545
ExcludeInternalConfigProps<FlingGestureInternalConfig>;
4646

4747
export function useFling(config: FlingGestureConfig) {
48-
const flingConfig = cloneConfig<FlingHandlerData, FlingGestureProps>(config);
48+
const flingConfig = cloneConfig<FlingHandlerData, FlingGestureProperties>(
49+
config
50+
);
4951

5052
return useGesture(SingleGestureName.Fling, flingConfig);
5153
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { useGesture } from '../useGesture';
1010
import { cloneConfig, getChangeEventCalculator } from '../utils';
1111

12-
type HoverGestureProps = {
12+
type HoverGestureProperties = {
1313
/**
1414
* Visual effect applied to the view while the view is hovered. The possible values are:
1515
*
@@ -34,7 +34,7 @@ type HoverHandlerData = {
3434

3535
type HoverGestureInternalConfig = BaseGestureConfig<
3636
HoverHandlerData,
37-
HoverGestureProps
37+
HoverGestureProperties
3838
>;
3939

4040
export type HoverGestureConfig =
@@ -52,7 +52,9 @@ function diffCalculator(
5252
}
5353

5454
export function useHover(config: HoverGestureConfig) {
55-
const hoverConfig = cloneConfig<HoverHandlerData, HoverGestureProps>(config);
55+
const hoverConfig = cloneConfig<HoverHandlerData, HoverGestureProperties>(
56+
config
57+
);
5658

5759
hoverConfig.changeEventCalculator = getChangeEventCalculator(diffCalculator);
5860

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import {
44
SingleGestureName,
55
} from '../../types';
66
import { useGesture } from '../useGesture';
7-
import { remapProps } from '../utils';
7+
import { cloneConfig, remapProps } from '../utils';
88

9-
type LongPressGestureProps = {
9+
type LongPressGestureProperties = {
1010
/**
1111
* Minimum time, expressed in milliseconds, that a finger must remain pressed on
1212
* the corresponding view. The default value is 500.
@@ -27,7 +27,7 @@ type LongPressGestureProps = {
2727
numberOfPointers?: number;
2828
};
2929

30-
type LongPressGestureInternalProps = {
30+
type LongPressGestureInternalProperties = {
3131
minDurationMs?: number;
3232
maxDist?: number;
3333
numberOfPointers?: number;
@@ -42,33 +42,38 @@ type LongPressHandlerData = {
4242
};
4343

4444
export type LongPressGestureConfig = ExcludeInternalConfigProps<
45-
BaseGestureConfig<LongPressHandlerData, LongPressGestureProps>
45+
BaseGestureConfig<LongPressHandlerData, LongPressGestureProperties>
4646
>;
4747

4848
type LongPressGestureInternalConfig = BaseGestureConfig<
4949
LongPressHandlerData,
50-
LongPressGestureInternalProps
50+
LongPressGestureInternalProperties
5151
>;
5252

5353
const LongPressPropsMapping = new Map<
54-
keyof LongPressGestureProps,
55-
keyof LongPressGestureInternalProps
54+
keyof LongPressGestureProperties,
55+
keyof LongPressGestureInternalProperties
5656
>([
5757
['minDuration', 'minDurationMs'],
5858
['maxDistance', 'maxDist'],
5959
]);
6060

6161
export function useLongPress(config: LongPressGestureConfig) {
62-
const longPressConfig = remapProps<
63-
LongPressGestureConfig,
64-
LongPressGestureInternalConfig
65-
>(config, LongPressPropsMapping);
62+
const longPressConfig = cloneConfig<
63+
LongPressHandlerData,
64+
LongPressGestureInternalProperties
65+
>(config);
66+
67+
remapProps<LongPressGestureConfig, LongPressGestureInternalConfig>(
68+
longPressConfig,
69+
LongPressPropsMapping
70+
);
6671

6772
if (longPressConfig.shouldCancelWhenOutside === undefined) {
6873
longPressConfig.shouldCancelWhenOutside = true;
6974
}
7075

71-
return useGesture<LongPressHandlerData, LongPressGestureInternalProps>(
76+
return useGesture<LongPressHandlerData, LongPressGestureInternalProperties>(
7277
SingleGestureName.LongPress,
7378
longPressConfig
7479
);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import {
66
import { useGesture } from '../useGesture';
77
import { cloneConfig } from '../utils';
88

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

1212
type ManualGestureInternalConfig = BaseGestureConfig<
1313
ManualHandlerData,
14-
ManualGestureProps
14+
ManualGestureProperties
1515
>;
1616

1717
export type ManualGestureConfig =
1818
ExcludeInternalConfigProps<ManualGestureInternalConfig>;
1919

2020
export function useManual(config: ManualGestureConfig) {
21-
const manualConfig = cloneConfig<ManualHandlerData, ManualGestureProps>(
21+
const manualConfig = cloneConfig<ManualHandlerData, ManualGestureProperties>(
2222
config
2323
);
2424

packages/react-native-gesture-handler/src/v3/hooks/gestures/useNative.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import { useGesture } from '../useGesture';
77
import { cloneConfig } from '../utils';
88

9-
type NativeViewGestureProps = {
9+
type NativeViewGestureProperties = {
1010
/**
1111
* Android only.
1212
*
@@ -28,7 +28,7 @@ type NativeViewHandlerData = {
2828

2929
type NativeViewGestureInternalConfig = BaseGestureConfig<
3030
NativeViewHandlerData,
31-
NativeViewGestureProps
31+
NativeViewGestureProperties
3232
>;
3333

3434
export type NativeViewGestureConfig =
@@ -37,7 +37,7 @@ export type NativeViewGestureConfig =
3737
export function useNative(config: NativeViewGestureConfig) {
3838
const nativeConfig = cloneConfig<
3939
NativeViewHandlerData,
40-
NativeViewGestureProps
40+
NativeViewGestureProperties
4141
>(config);
4242

4343
return useGesture(SingleGestureName.Native, nativeConfig);

packages/react-native-gesture-handler/src/v3/hooks/gestures/usePan.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {
66
SingleGestureName,
77
} from '../../types';
88
import { useGesture } from '../useGesture';
9-
import { getChangeEventCalculator, remapProps } from '../utils';
9+
import { getChangeEventCalculator, remapProps, cloneConfig } from '../utils';
1010

11-
type CommonPanGestureProps = {
11+
type CommonPanGestureProperties = {
1212
/**
1313
* Minimum distance the finger (or multiple finger) need to travel before the
1414
* handler activates. Expressed in points.
@@ -47,7 +47,7 @@ type CommonPanGestureProps = {
4747
activateAfterLongPress?: number;
4848
};
4949

50-
export type PanGestureProps = CommonPanGestureProps & {
50+
export type PanGestureProperties = CommonPanGestureProperties & {
5151
/**
5252
* Range along X axis (in points) where fingers travels without activation of
5353
* handler. Moving outside of this range implies activation of handler. Range
@@ -93,7 +93,7 @@ export type PanGestureProps = CommonPanGestureProps & {
9393
failOffsetX?: number | [failOffsetXStart: number, failOffsetXEnd: number];
9494
};
9595

96-
type PanGestureInternalProps = CommonPanGestureProps & {
96+
type PanGestureInternalProperties = CommonPanGestureProperties & {
9797
minDist?: number;
9898
activeOffsetYStart?: number;
9999
activeOffsetYEnd?: number;
@@ -120,17 +120,17 @@ type PanHandlerData = {
120120
};
121121

122122
export type PanGestureConfig = ExcludeInternalConfigProps<
123-
BaseGestureConfig<PanHandlerData, PanGestureProps>
123+
BaseGestureConfig<PanHandlerData, PanGestureProperties>
124124
>;
125125

126126
type PanGestureInternalConfig = BaseGestureConfig<
127127
PanHandlerData,
128-
PanGestureInternalProps
128+
PanGestureInternalProperties
129129
>;
130130

131131
const PanPropsMapping = new Map<
132-
keyof PanGestureProps,
133-
keyof PanGestureInternalProps
132+
keyof PanGestureProperties,
133+
keyof PanGestureInternalProperties
134134
>([['minDistance', 'minDist']]);
135135

136136
function validatePanConfig(config: PanGestureConfig) {
@@ -259,16 +259,20 @@ export function usePan(config: PanGestureConfig) {
259259
validatePanConfig(config);
260260
}
261261

262-
const panConfig = remapProps<PanGestureConfig, PanGestureInternalConfig>(
263-
config,
262+
const panConfig = cloneConfig<PanHandlerData, PanGestureInternalProperties>(
263+
config
264+
);
265+
266+
remapProps<PanGestureConfig, PanGestureInternalConfig>(
267+
panConfig,
264268
PanPropsMapping
265269
);
266270

267271
transformPanProps(panConfig);
268272

269273
panConfig.changeEventCalculator = getChangeEventCalculator(diffCalculator);
270274

271-
return useGesture<PanHandlerData, PanGestureInternalProps>(
275+
return useGesture<PanHandlerData, PanGestureInternalProperties>(
272276
SingleGestureName.Pan,
273277
panConfig
274278
);

packages/react-native-gesture-handler/src/v3/hooks/gestures/usePinch.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
import { useGesture } from '../useGesture';
88
import { cloneConfig, getChangeEventCalculator } from '../utils';
99

10-
type PinchGestureProps = Record<string, never>;
10+
type PinchGestureProperties = Record<string, never>;
1111

1212
type PinchHandlerData = {
1313
scale: number;
@@ -19,7 +19,7 @@ type PinchHandlerData = {
1919

2020
type PinchGestureInternalConfig = BaseGestureConfig<
2121
PinchHandlerData,
22-
PinchGestureProps
22+
PinchGestureProperties
2323
>;
2424

2525
export type PinchGestureConfig =
@@ -36,7 +36,9 @@ function diffCalculator(
3636
}
3737

3838
export function usePinch(config: PinchGestureConfig) {
39-
const pinchConfig = cloneConfig<PinchHandlerData, PinchGestureProps>(config);
39+
const pinchConfig = cloneConfig<PinchHandlerData, PinchGestureProperties>(
40+
config
41+
);
4042

4143
pinchConfig.changeEventCalculator = getChangeEventCalculator(diffCalculator);
4244

packages/react-native-gesture-handler/src/v3/hooks/gestures/useRotation.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
import { useGesture } from '../useGesture';
88
import { cloneConfig, getChangeEventCalculator } from '../utils';
99

10-
type RotationGestureProps = Record<string, never>;
10+
type RotationGestureProperties = Record<string, never>;
1111

1212
type RotationHandlerData = {
1313
rotation: number;
@@ -19,7 +19,7 @@ type RotationHandlerData = {
1919

2020
type RotationGestureInternalConfig = BaseGestureConfig<
2121
RotationHandlerData,
22-
RotationGestureProps
22+
RotationGestureProperties
2323
>;
2424

2525
export type RotationGestureConfig =
@@ -38,9 +38,10 @@ function diffCalculator(
3838
}
3939

4040
export function useRotation(config: RotationGestureConfig) {
41-
const rotationConfig = cloneConfig<RotationHandlerData, RotationGestureProps>(
42-
config
43-
);
41+
const rotationConfig = cloneConfig<
42+
RotationHandlerData,
43+
RotationGestureProperties
44+
>(config);
4445

4546
rotationConfig.changeEventCalculator =
4647
getChangeEventCalculator(diffCalculator);

packages/react-native-gesture-handler/src/v3/hooks/gestures/useTap.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import {
44
SingleGestureName,
55
} from '../../types';
66
import { useGesture } from '../useGesture';
7-
import { remapProps } from '../utils';
7+
import { cloneConfig, remapProps } from '../utils';
88

9-
type TapGestureProps = {
9+
type TapGestureProperties = {
1010
/**
1111
* Minimum number of pointers (fingers) required to be placed before the
1212
* handler activates. Should be a positive integer.
@@ -57,7 +57,7 @@ type TapGestureProps = {
5757
maxDistance?: number;
5858
};
5959

60-
type TapGestureInternalProps = {
60+
type TapGestureInternalProperties = {
6161
minPointers?: number;
6262
numberOfTaps?: number;
6363
maxDeltaX?: number;
@@ -75,30 +75,34 @@ type TapHandlerData = {
7575
};
7676

7777
export type TapGestureConfig = ExcludeInternalConfigProps<
78-
BaseGestureConfig<TapHandlerData, TapGestureProps>
78+
BaseGestureConfig<TapHandlerData, TapGestureProperties>
7979
>;
8080

8181
type TapGestureInternalConfig = BaseGestureConfig<
8282
TapHandlerData,
83-
TapGestureInternalProps
83+
TapGestureInternalProperties
8484
>;
8585

8686
const TapPropsMapping = new Map<
87-
keyof TapGestureProps,
88-
keyof TapGestureInternalProps
87+
keyof TapGestureProperties,
88+
keyof TapGestureInternalProperties
8989
>([
9090
['maxDistance', 'maxDist'],
9191
['maxDuration', 'maxDurationMs'],
9292
['maxDelay', 'maxDelayMs'],
9393
]);
9494

9595
export function useTap(config: TapGestureConfig) {
96-
const tapConfig = remapProps<TapGestureConfig, TapGestureInternalConfig>(
97-
config,
96+
const tapConfig = cloneConfig<TapHandlerData, TapGestureInternalProperties>(
97+
config
98+
);
99+
100+
remapProps<TapGestureConfig, TapGestureInternalConfig>(
101+
tapConfig,
98102
TapPropsMapping
99103
);
100104

101-
return useGesture<TapHandlerData, TapGestureInternalProps>(
105+
return useGesture<TapHandlerData, TapGestureInternalProperties>(
102106
SingleGestureName.Tap,
103107
tapConfig
104108
);

0 commit comments

Comments
 (0)