Skip to content

Commit 87eea00

Browse files
author
Andrzej Antoni Kwaśniewski
committed
virtual detector
1 parent 694761e commit 87eea00

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

  • packages/react-native-gesture-handler/src/__tests__
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React, { useRef } from 'react';
2+
import { render, cleanup } from '@testing-library/react-native';
3+
import {
4+
GestureHandlerRootView,
5+
InterceptingGestureDetector,
6+
usePanGesture,
7+
useTapGesture,
8+
} from '../index';
9+
import { findNodeHandle, View } from 'react-native';
10+
import { VirtualDetector } from '../v3/detectors/VirtualDetector/VirtualDetector';
11+
12+
beforeEach(() => cleanup());
13+
jest.mock('react-native/Libraries/ReactNative/RendererProxy', () => ({
14+
findNodeHandle: jest.fn(),
15+
}));
16+
17+
describe('VirtualDetector', () => {
18+
test('virtual detector must be under InterceptingGestureDetector', () => {
19+
function VirtualDetectorWithNoBoundary() {
20+
const tap = useTapGesture({});
21+
return (
22+
<GestureHandlerRootView>
23+
<VirtualDetector gesture={tap}>
24+
<View />
25+
</VirtualDetector>
26+
</GestureHandlerRootView>
27+
);
28+
}
29+
expect(() => render(<VirtualDetectorWithNoBoundary />)).toThrow(
30+
'VirtualGestureDetector must be a descendant of an InterceptingGestureDetector'
31+
);
32+
});
33+
test('virtual detector does not handle animated events', () => {
34+
(findNodeHandle as jest.Mock).mockReturnValue(123);
35+
36+
function VirtualDetectorAnimated() {
37+
const tap = usePanGesture({ useAnimated: true });
38+
const ref = useRef(null);
39+
return (
40+
<GestureHandlerRootView>
41+
<InterceptingGestureDetector>
42+
<VirtualDetector gesture={tap}>
43+
<View ref={ref} />
44+
</VirtualDetector>
45+
</InterceptingGestureDetector>
46+
</GestureHandlerRootView>
47+
);
48+
}
49+
expect(() => render(<VirtualDetectorAnimated />)).toThrow(
50+
'[react-native-gesture-handler] VirtualGestureDetector cannot handle Animated events with native driver when used inside InterceptingGestureDetector. Use Reanimated or Animated events without native driver instead.'
51+
);
52+
});
53+
});

0 commit comments

Comments
 (0)