Skip to content

Commit 8dc38eb

Browse files
authored
[General] Allow to create gestures with no config (#4115)
## Description Updates gesture hook signatures to include the default, empty config for each gesture. This allows for creating gesture objects without passing a config, like so: ```jsx const nativeGesture = useNativeGesture() ``` `Native` gesture would be the most useful here, since its config is often empty when pulling in a host component into RNGH's gesture system. Other gestures may be a nice DX improvement, though, since now it's simpler to create a "placeholder" gesture. The default config is referentially stable, so it shouldn't cause unnecessary updates between renders as opposed to passing an empty object (with no compiler and memoization). ## Test plan Static checks
1 parent 4b3f497 commit 8dc38eb

9 files changed

Lines changed: 41 additions & 9 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import type {
88
FlingHandlerData,
99
} from './FlingTypes';
1010

11-
export function useFlingGesture(config: FlingGestureConfig): FlingGesture {
11+
const EMPTY_FLING_CONFIG: FlingGestureConfig = {};
12+
13+
export function useFlingGesture(
14+
config: FlingGestureConfig = EMPTY_FLING_CONFIG
15+
): FlingGesture {
1216
const flingConfig = useClonedAndRemappedConfig<
1317
FlingGestureProperties,
1418
FlingHandlerData

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ function transformHoverProps(
4444

4545
const HoverPropsMapping = new Map<string, string>([['effect', 'hoverEffect']]);
4646

47-
export function useHoverGesture(config: HoverGestureConfig): HoverGesture {
47+
const EMPTY_HOVER_CONFIG: HoverGestureConfig = {};
48+
49+
export function useHoverGesture(
50+
config: HoverGestureConfig = EMPTY_HOVER_CONFIG
51+
): HoverGesture {
4852
const hoverConfig = useClonedAndRemappedConfig<
4953
HoverGestureProperties,
5054
HoverHandlerData,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ function transformLongPressProps(
2828
return config;
2929
}
3030

31+
const EMPTY_LONG_PRESS_CONFIG: LongPressGestureConfig = {};
32+
3133
export function useLongPressGesture(
32-
config: LongPressGestureConfig
34+
config: LongPressGestureConfig = EMPTY_LONG_PRESS_CONFIG
3335
): LongPressGesture {
3436
const longPressConfig = useClonedAndRemappedConfig<
3537
LongPressGestureProperties,

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import type {
88
ManualHandlerData,
99
} from './ManualTypes';
1010

11-
export function useManualGesture(config: ManualGestureConfig): ManualGesture {
11+
const EMPTY_MANUAL_CONFIG: ManualGestureConfig = {};
12+
13+
export function useManualGesture(
14+
config: ManualGestureConfig = EMPTY_MANUAL_CONFIG
15+
): ManualGesture {
1216
const manualConfig = useClonedAndRemappedConfig<
1317
ManualGestureProperties,
1418
ManualHandlerData

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import type {
88
NativeHandlerData,
99
} from './NativeTypes';
1010

11-
export function useNativeGesture(config: NativeGestureConfig): NativeGesture {
11+
const EMPTY_NATIVE_CONFIG: NativeGestureConfig = {};
12+
13+
export function useNativeGesture(
14+
config: NativeGestureConfig = EMPTY_NATIVE_CONFIG
15+
): NativeGesture {
1216
const nativeConfig = useClonedAndRemappedConfig<
1317
NativeGestureProperties,
1418
NativeHandlerData

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ function transformPanProps(
139139
return config;
140140
}
141141

142-
export function usePanGesture(config: PanGestureConfig): PanGesture {
142+
const EMPTY_PAN_CONFIG: PanGestureConfig = {};
143+
144+
export function usePanGesture(
145+
config: PanGestureConfig = EMPTY_PAN_CONFIG
146+
): PanGesture {
143147
if (__DEV__) {
144148
validatePanConfig(config);
145149
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ function transformPinchProps(
4040

4141
const PinchPropsMapping = new Map<string, string>();
4242

43-
export function usePinchGesture(config: PinchGestureConfig): PinchGesture {
43+
const EMPTY_PINCH_CONFIG: PinchGestureConfig = {};
44+
45+
export function usePinchGesture(
46+
config: PinchGestureConfig = EMPTY_PINCH_CONFIG
47+
): PinchGesture {
4448
const pinchConfig = useClonedAndRemappedConfig<
4549
PinchGestureProperties,
4650
PinchHandlerData,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ function transformRotationProps(
4242

4343
const RotationPropsMapping = new Map<string, string>();
4444

45+
const EMPTY_ROTATION_CONFIG: RotationGestureConfig = {};
46+
4547
export function useRotationGesture(
46-
config: RotationGestureConfig
48+
config: RotationGestureConfig = EMPTY_ROTATION_CONFIG
4749
): RotationGesture {
4850
const rotationConfig = useClonedAndRemappedConfig<
4951
RotationGestureProperties,

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ const TapPropsMapping = new Map<
1818
['maxDelay', 'maxDelayMs'],
1919
]);
2020

21-
export function useTapGesture(config: TapGestureConfig): TapGesture {
21+
const EMPTY_TAP_CONFIG: TapGestureConfig = {};
22+
23+
export function useTapGesture(
24+
config: TapGestureConfig = EMPTY_TAP_CONFIG
25+
): TapGesture {
2226
const tapConfig = useClonedAndRemappedConfig<
2327
TapGestureProperties,
2428
TapHandlerData,

0 commit comments

Comments
 (0)