Skip to content

Commit a4f1074

Browse files
authored
Rename gesture composition hooks (#3834)
## Description - Renames composition hooks to include `Gestures` suffix. - Renames `useRace` to `useMultipleGestures` - `useRaceGesture`/`useRacingGestures` suggests that it sets up some kind of relation between gestures. It doesn't - this is the default behavior. I hope that `useMultipleGestures` sounds like the answer to "I just want to attach pan and pinch to the same view", or "I want to set the relations manually because they depend on other components". - Changes the directory they are in from `relations` to `composition`. - Removes `useGesture` from the public API ## Test plan Static checks
1 parent 2b7a1a0 commit a4f1074

File tree

8 files changed

+53
-40
lines changed

8 files changed

+53
-40
lines changed

packages/react-native-gesture-handler/src/__tests__/RelationsTraversal.test.tsx

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { tagMessage } from '../utils';
2-
import { useExclusive, useRace, useSimultaneous } from '../v3/hooks/relations';
2+
import {
3+
useExclusiveGestures,
4+
useMultipleGestures,
5+
useSimultaneousGestures,
6+
} from '../v3/hooks/composition';
37
import { useGesture } from '../v3/hooks/useGesture';
48
import { configureRelations } from '../v3/detectors/utils';
59
import { SingleGesture, SingleGestureName } from '../v3/types';
@@ -27,24 +31,26 @@ describe('Ensure only one leaf node', () => {
2731
);
2832

2933
test('useSimultaneous', () => {
30-
expect(() => useSimultaneous(pan1, pan1)).toThrow(errorMessage);
34+
expect(() => useSimultaneousGestures(pan1, pan1)).toThrow(errorMessage);
3135
});
3236

3337
test('useExclusive', () => {
34-
expect(() => useExclusive(pan1, pan1)).toThrow(errorMessage);
38+
expect(() => useExclusiveGestures(pan1, pan1)).toThrow(errorMessage);
3539
});
3640

3741
test('useRace', () => {
38-
expect(() => useRace(pan1, pan1)).toThrow(errorMessage);
42+
expect(() => useMultipleGestures(pan1, pan1)).toThrow(errorMessage);
3943
});
4044

4145
test('Complex composition', () => {
42-
const exclusive1 = renderHook(() => useExclusive(pan1, pan2)).result
46+
const exclusive1 = renderHook(() => useExclusiveGestures(pan1, pan2)).result
4347
.current;
44-
const exclusive2 = renderHook(() => useExclusive(pan1, pan3)).result
48+
const exclusive2 = renderHook(() => useExclusiveGestures(pan1, pan3)).result
4549
.current;
4650

47-
expect(() => useSimultaneous(exclusive1, exclusive2)).toThrow(errorMessage);
51+
expect(() => useSimultaneousGestures(exclusive1, exclusive2)).toThrow(
52+
errorMessage
53+
);
4854
});
4955
});
5056

@@ -62,8 +68,9 @@ describe('Simple relations', () => {
6268
});
6369

6470
test('useSimultaneous', () => {
65-
const composedGesture = renderHook(() => useSimultaneous(pan1, pan2)).result
66-
.current;
71+
const composedGesture = renderHook(() =>
72+
useSimultaneousGestures(pan1, pan2)
73+
).result.current;
6774

6875
configureRelations(composedGesture);
6976

@@ -76,8 +83,8 @@ describe('Simple relations', () => {
7683
});
7784

7885
test('useExclusive', () => {
79-
const composedGesture = renderHook(() => useExclusive(pan2, pan1)).result
80-
.current;
86+
const composedGesture = renderHook(() => useExclusiveGestures(pan2, pan1))
87+
.result.current;
8188

8289
configureRelations(composedGesture);
8390

@@ -86,8 +93,8 @@ describe('Simple relations', () => {
8693
});
8794

8895
test('useRace', () => {
89-
const composedGesture = renderHook(() => useRace(pan1, pan2)).result
90-
.current;
96+
const composedGesture = renderHook(() => useMultipleGestures(pan1, pan2))
97+
.result.current;
9198

9299
configureRelations(composedGesture);
93100

@@ -222,10 +229,13 @@ describe('Complex relations', () => {
222229

223230
// Test case from description of https://github.com/software-mansion/react-native-gesture-handler/pull/3693
224231
test('Case 1', () => {
225-
const E2 = renderHook(() => useExclusive(tap1, tap2)).result.current;
226-
const S1 = renderHook(() => useSimultaneous(E2, pan1)).result.current;
227-
const S2 = renderHook(() => useSimultaneous(pan2, pan3)).result.current;
228-
const E1 = renderHook(() => useExclusive(S1, S2)).result.current;
232+
const E2 = renderHook(() => useExclusiveGestures(tap1, tap2)).result
233+
.current;
234+
const S1 = renderHook(() => useSimultaneousGestures(E2, pan1)).result
235+
.current;
236+
const S2 = renderHook(() => useSimultaneousGestures(pan2, pan3)).result
237+
.current;
238+
const E1 = renderHook(() => useExclusiveGestures(S1, S2)).result.current;
229239

230240
configureRelations(E1);
231241

@@ -264,10 +274,10 @@ describe('Complex relations', () => {
264274
});
265275

266276
test('Case 2', () => {
267-
const simultaneous = renderHook(() => useSimultaneous(pan1, pan2)).result
268-
.current;
269-
const exclusive = renderHook(() => useExclusive(tap1, simultaneous)).result
270-
.current;
277+
const simultaneous = renderHook(() => useSimultaneousGestures(pan1, pan2))
278+
.result.current;
279+
const exclusive = renderHook(() => useExclusiveGestures(tap1, simultaneous))
280+
.result.current;
271281

272282
configureRelations(exclusive);
273283

@@ -286,8 +296,8 @@ describe('Complex relations', () => {
286296
});
287297

288298
test('Case 3', () => {
289-
const exclusive = renderHook(() => useExclusive(tap1, tap2, tap3)).result
290-
.current;
299+
const exclusive = renderHook(() => useExclusiveGestures(tap1, tap2, tap3))
300+
.result.current;
291301

292302
configureRelations(exclusive);
293303

@@ -335,9 +345,11 @@ describe('Complex relations with external gestures', () => {
335345
})
336346
).result.current;
337347

338-
const S1 = renderHook(() => useSimultaneous(pan1, pan2)).result.current;
339-
const S2 = renderHook(() => useSimultaneous(pan3, pan4)).result.current;
340-
const E = renderHook(() => useExclusive(S1, S2)).result.current;
348+
const S1 = renderHook(() => useSimultaneousGestures(pan1, pan2)).result
349+
.current;
350+
const S2 = renderHook(() => useSimultaneousGestures(pan3, pan4)).result
351+
.current;
352+
const E = renderHook(() => useExclusiveGestures(S1, S2)).result.current;
341353

342354
configureRelations(pan5);
343355
configureRelations(E);
@@ -408,8 +420,8 @@ describe('Complex relations with external gestures', () => {
408420
})
409421
).result.current;
410422

411-
const E = renderHook(() => useExclusive(pan1, pan2)).result.current;
412-
const S = renderHook(() => useSimultaneous(E, pan3)).result.current;
423+
const E = renderHook(() => useExclusiveGestures(pan1, pan2)).result.current;
424+
const S = renderHook(() => useSimultaneousGestures(E, pan3)).result.current;
413425

414426
configureRelations(pan4);
415427
configureRelations(pan5);
@@ -460,8 +472,9 @@ describe('External relations with composed gestures', () => {
460472
})
461473
).result.current;
462474

463-
const composedGesture = renderHook(() => useSimultaneous(pan1, pan2)).result
464-
.current;
475+
const composedGesture = renderHook(() =>
476+
useSimultaneousGestures(pan1, pan2)
477+
).result.current;
465478

466479
const pan3 = renderHook(() =>
467480
useGesture(SingleGestureName.Pan, {
@@ -497,8 +510,9 @@ describe('External relations with composed gestures', () => {
497510
})
498511
).result.current;
499512

500-
const composedGesture = renderHook(() => useSimultaneous(pan1, pan2)).result
501-
.current;
513+
const composedGesture = renderHook(() =>
514+
useSimultaneousGestures(pan1, pan2)
515+
).result.current;
502516

503517
const pan3 = renderHook(() =>
504518
useGesture(SingleGestureName.Pan, {

packages/react-native-gesture-handler/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ export {
156156
VirtualGestureDetector,
157157
} from './v3/detectors';
158158

159-
export * from './v3/hooks/useGesture';
160-
export * from './v3/hooks/relations';
159+
export * from './v3/hooks/composition';
161160

162161
export type { ComposedGesture } from './v3/types';
163162
export type { GestureTouchEvent as SingleGestureTouchEvent } from './handlers/gestureHandlerCommon';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { useSimultaneousGestures } from './useSimultaneousGestures';
2+
export { useExclusiveGestures } from './useExclusiveGestures';
3+
export { useMultipleGestures } from './useMultipleGestures';

packages/react-native-gesture-handler/src/v3/hooks/relations/useExclusive.ts renamed to packages/react-native-gesture-handler/src/v3/hooks/composition/useExclusiveGestures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AnyGesture, ComposedGestureName } from '../../types';
22
import { useComposedGesture } from './useComposedGesture';
33

4-
export function useExclusive(...gestures: AnyGesture[]) {
4+
export function useExclusiveGestures(...gestures: AnyGesture[]) {
55
const composedGesture = useComposedGesture(
66
ComposedGestureName.Exclusive,
77
...gestures
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AnyGesture, ComposedGestureName } from '../../types';
22
import { useComposedGesture } from './useComposedGesture';
33

4-
export function useRace(...gestures: AnyGesture[]) {
4+
export function useMultipleGestures(...gestures: AnyGesture[]) {
55
return useComposedGesture(ComposedGestureName.Race, ...gestures);
66
}

packages/react-native-gesture-handler/src/v3/hooks/relations/useSimultaneous.ts renamed to packages/react-native-gesture-handler/src/v3/hooks/composition/useSimultaneousGestures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AnyGesture, ComposedGestureName } from '../../types';
22
import { useComposedGesture } from './useComposedGesture';
33

4-
export function useSimultaneous(...gestures: AnyGesture[]) {
4+
export function useSimultaneousGestures(...gestures: AnyGesture[]) {
55
const composedGesture = useComposedGesture(
66
ComposedGestureName.Simultaneous,
77
...gestures

packages/react-native-gesture-handler/src/v3/hooks/relations/index.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)