Skip to content

Commit ee42ccc

Browse files
committed
Add simultaneous
1 parent e5c26e2 commit ee42ccc

7 files changed

Lines changed: 119 additions & 0 deletions

File tree

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

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

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

1213
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
@@ -7,6 +7,7 @@ import RotationE2E from '../e2e_screens/gestures/Rotation';
77
import TapE2E from '../e2e_screens/gestures/Tap';
88
import CompetingE2E from '../e2e_screens/relations/Competing';
99
import ExclusiveE2E from '../e2e_screens/relations/Exclusive';
10+
import SimultaneousE2E from '../e2e_screens/relations/Simultaneous';
1011
import { TestScreens } from '../e2e_screens/utils';
1112
import EmptyExample from '../empty';
1213
import CameraExample from './complicated/camera';
@@ -154,6 +155,7 @@ export const NEW_EXAMPLES: ExamplesSection[] = [
154155
{ name: TestScreens.Fling, component: FlingE2E },
155156
{ name: TestScreens.Competing, component: CompetingE2E },
156157
{ name: TestScreens.Exclusive, component: ExclusiveE2E },
158+
{ name: TestScreens.Simultaneous, component: SimultaneousE2E },
157159
],
158160
},
159161
];

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { rotationTests } from '../suites/gestures/rotation';
66
import { tapTests } from '../suites/gestures/tap';
77
import { competingTests } from '../suites/relations/competing';
88
import { exclusiveTests } from '../suites/relations/exclusive';
9+
import { simultaneousTests } from '../suites/relations/simultaneous';
910

1011
tapTests();
1112
pinchTests();
@@ -15,3 +16,4 @@ rotationTests();
1516
panTests();
1617
competingTests();
1718
exclusiveTests();
19+
simultaneousTests();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import { panTests } from '../suites/gestures/pan';
44
import { tapTests } from '../suites/gestures/tap';
55
import { competingTests } from '../suites/relations/competing';
66
import { exclusiveTests } from '../suites/relations/exclusive';
7+
import { simultaneousTests } from '../suites/relations/simultaneous';
78

89
tapTests();
910
flingTests();
1011
longPressTests();
1112
panTests();
1213
competingTests();
1314
exclusiveTests();
15+
simultaneousTests();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { simultaneousTests } from '../../suites/relations/simultaneous';
2+
3+
simultaneousTests();
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 simultaneousTests() {
8+
describe('test simultaneous gestures', () => {
9+
beforeAll(async () => {
10+
await navigateTo(TestScreens.Simultaneous);
11+
});
12+
13+
const gestureBox = element(by.id('simultaneous-box'));
14+
const stateIndicator = element(by.id('state-indicator'));
15+
const extractButton = element(by.id('extract-button'));
16+
17+
test('Should activate both pan gestures on swipe', async () => {
18+
await gestureBox.swipe('right', 'fast');
19+
await extractButton.tap();
20+
await expect(stateIndicator).toHaveText(
21+
`{Pan1: ${CB.B}${CB.A}${CB.U}${CB.D}${CB.F}, Pan2: ${CB.B}${CB.A}${CB.U}${CB.D}${CB.F}}`
22+
);
23+
});
24+
});
25+
}

0 commit comments

Comments
 (0)