Skip to content

Commit e5c26e2

Browse files
committed
Add exclusive test
1 parent 7028e1d commit e5c26e2

7 files changed

Lines changed: 126 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { useRef, useState } from 'react';
2+
import { StyleSheet, View } from 'react-native';
3+
import {
4+
GestureDetector,
5+
useExclusiveGestures,
6+
useTapGesture,
7+
} from 'react-native-gesture-handler';
8+
9+
import TestingScreen from '../TestingScreen';
10+
import { CallbackIDs } from '../utils';
11+
12+
export default function ExclusiveScreen() {
13+
const [text, setText] = useState('');
14+
15+
const tapCallbacks = useRef(new Set<string>());
16+
const doubleTapCallbacks = useRef(new Set<string>());
17+
18+
const doubleTapGesture = useTapGesture({
19+
numberOfTaps: 2,
20+
onBegin: () => {
21+
doubleTapCallbacks.current.add(CallbackIDs.onBegin);
22+
},
23+
onActivate: () => {
24+
doubleTapCallbacks.current.add(CallbackIDs.onActivate);
25+
},
26+
onDeactivate: () => {
27+
doubleTapCallbacks.current.add(CallbackIDs.onDeactivate);
28+
},
29+
onFinalize: () => {
30+
doubleTapCallbacks.current.add(CallbackIDs.onFinalize);
31+
},
32+
runOnJS: true,
33+
});
34+
35+
const tapGesture = useTapGesture({
36+
onBegin: () => {
37+
tapCallbacks.current.add(CallbackIDs.onBegin);
38+
},
39+
onActivate: () => {
40+
tapCallbacks.current.add(CallbackIDs.onActivate);
41+
},
42+
onDeactivate: () => {
43+
tapCallbacks.current.add(CallbackIDs.onDeactivate);
44+
},
45+
onFinalize: () => {
46+
tapCallbacks.current.add(CallbackIDs.onFinalize);
47+
},
48+
runOnJS: true,
49+
});
50+
51+
const g = useExclusiveGestures(doubleTapGesture, tapGesture);
52+
53+
return (
54+
<TestingScreen
55+
text={text}
56+
buttonCallback={() => {
57+
const tapCallbacksText = Array.from(tapCallbacks.current).join('');
58+
const doubleTapCallbacksText = Array.from(
59+
doubleTapCallbacks.current
60+
).join('');
61+
62+
setText(
63+
`{DoubleTap: ${doubleTapCallbacksText}, Tap: ${tapCallbacksText}}`
64+
);
65+
66+
tapCallbacks.current.clear();
67+
doubleTapCallbacks.current.clear();
68+
}}>
69+
<GestureDetector gesture={g}>
70+
<View style={styles.gestureBox} testID="exclusive-box" />
71+
</GestureDetector>
72+
</TestingScreen>
73+
);
74+
}
75+
76+
const styles = StyleSheet.create({
77+
gestureBox: {
78+
width: 120,
79+
height: 120,
80+
borderRadius: 20,
81+
backgroundColor: '#4ecdc4',
82+
},
83+
});

apps/common-app/src/e2e_screens/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const TestScreens = {
66
Pinch: '[E2E] Pinch',
77
Rotation: '[E2E] Rotation',
88
Competing: '[E2E] Competing',
9+
Exclusive: '[E2E] Exclusive',
910
};
1011

1112
export const CallbackIDs = {

apps/common-app/src/new_api/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import PinchE2E from '../e2e_screens/gestures/Pinch';
66
import RotationE2E from '../e2e_screens/gestures/Rotation';
77
import TapE2E from '../e2e_screens/gestures/Tap';
88
import CompetingE2E from '../e2e_screens/relations/Competing';
9+
import ExclusiveE2E from '../e2e_screens/relations/Exclusive';
910
import { TestScreens } from '../e2e_screens/utils';
1011
import EmptyExample from '../empty';
1112
import CameraExample from './complicated/camera';
@@ -152,6 +153,7 @@ export const NEW_EXAMPLES: ExamplesSection[] = [
152153
{ name: TestScreens.LongPress, component: LongPressE2E },
153154
{ name: TestScreens.Fling, component: FlingE2E },
154155
{ name: TestScreens.Competing, component: CompetingE2E },
156+
{ name: TestScreens.Exclusive, component: ExclusiveE2E },
155157
],
156158
},
157159
];

apps/expo-example/e2e/__tests__/all.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { pinchTests } from '../suites/gestures/pinch';
55
import { rotationTests } from '../suites/gestures/rotation';
66
import { tapTests } from '../suites/gestures/tap';
77
import { competingTests } from '../suites/relations/competing';
8+
import { exclusiveTests } from '../suites/relations/exclusive';
89

910
tapTests();
1011
pinchTests();
@@ -13,3 +14,4 @@ longPressTests();
1314
rotationTests();
1415
panTests();
1516
competingTests();
17+
exclusiveTests();

apps/expo-example/e2e/__tests__/all_wo_argent.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { longPressTests } from '../suites/gestures/long_press';
33
import { panTests } from '../suites/gestures/pan';
44
import { tapTests } from '../suites/gestures/tap';
55
import { competingTests } from '../suites/relations/competing';
6+
import { exclusiveTests } from '../suites/relations/exclusive';
67

78
tapTests();
89
flingTests();
910
longPressTests();
1011
panTests();
1112
competingTests();
13+
exclusiveTests();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { exclusiveTests } from '../../suites/relations/exclusive';
2+
3+
exclusiveTests();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// eslint-disable-next-line import-x/no-extraneous-dependencies
2+
import { beforeAll, describe } from '@jest/globals';
3+
import { by, element, expect } from 'detox';
4+
5+
import { CB, navigateTo, TestScreens } from '../../utils';
6+
7+
export function exclusiveTests() {
8+
describe('test exclusive gestures (tap + double tap)', () => {
9+
beforeAll(async () => {
10+
await navigateTo(TestScreens.Exclusive);
11+
});
12+
13+
const gestureBox = element(by.id('exclusive-box'));
14+
const stateIndicator = element(by.id('state-indicator'));
15+
const extractButton = element(by.id('extract-button'));
16+
17+
test('Should activate only tap gesture on single tap', async () => {
18+
await gestureBox.tap();
19+
await extractButton.tap();
20+
await expect(stateIndicator).toHaveText(
21+
`{DoubleTap: ${CB.B}${CB.F}, Tap: ${CB.B}${CB.A}${CB.D}${CB.F}}`
22+
);
23+
});
24+
25+
test('Should activate only double tap gesture on double tap', async () => {
26+
await gestureBox.multiTap(2);
27+
await extractButton.tap();
28+
await expect(stateIndicator).toHaveText(
29+
`{DoubleTap: ${CB.B}${CB.A}${CB.D}${CB.F}, Tap: ${CB.B}${CB.F}}`
30+
);
31+
});
32+
});
33+
}

0 commit comments

Comments
 (0)