|
1 | | -import { StyleSheet } from 'react-native'; |
2 | 1 | import type { TestInstance } from 'test-renderer'; |
3 | 2 |
|
4 | 3 | import { isHostTextInput } from '../../helpers/host-component-names'; |
5 | 4 | import { isEditableTextInput } from '../../helpers/text-input'; |
6 | | - |
7 | | -/** |
8 | | - * pointerEvents controls whether the View can be the target of touch events. |
9 | | - * 'auto': The View and its children can be the target of touch events. |
10 | | - * 'none': The View is never the target of touch events. |
11 | | - * 'box-none': The View is never the target of touch events but its subviews can be |
12 | | - * 'box-only': The view can be the target of touch events but its subviews cannot be |
13 | | - * see the official react native doc https://reactnative.dev/docs/view#pointerevents */ |
14 | | -export function isPointerEventEnabled(instance: TestInstance): boolean { |
15 | | - return getPointerEventsBlocker(instance) == null; |
16 | | -} |
17 | | - |
18 | | -/** |
19 | | - * Returns the element whose `pointerEvents` prevents the instance from being the target of |
20 | | - * touch events: the instance itself or one of its ancestors. Returns `null` if nothing blocks it. |
21 | | - */ |
22 | | -export function getPointerEventsBlocker(instance: TestInstance): TestInstance | null { |
23 | | - return findPointerEventsBlocker(instance, false); |
24 | | -} |
| 5 | +import { isPointerEventEnabled } from '../shared/pointer-events'; |
25 | 6 |
|
26 | 7 | export function isTouchResponder(instance: TestInstance) { |
27 | 8 | return Boolean(instance.props.onStartShouldSetResponder) || isHostTextInput(instance); |
@@ -73,21 +54,3 @@ export function isEventEnabled( |
73 | 54 |
|
74 | 55 | return touchStart === undefined && touchMove === undefined; |
75 | 56 | } |
76 | | - |
77 | | -function findPointerEventsBlocker(instance: TestInstance, isParent: boolean): TestInstance | null { |
78 | | - // Check both props.pointerEvents and props.style.pointerEvents |
79 | | - const pointerEvents = |
80 | | - instance?.props.pointerEvents ?? StyleSheet.flatten(instance?.props.style)?.pointerEvents; |
81 | | - |
82 | | - const parentCondition = isParent ? pointerEvents === 'box-only' : pointerEvents === 'box-none'; |
83 | | - |
84 | | - if (pointerEvents === 'none' || parentCondition) { |
85 | | - return instance; |
86 | | - } |
87 | | - |
88 | | - if (!instance.parent) { |
89 | | - return null; |
90 | | - } |
91 | | - |
92 | | - return findPointerEventsBlocker(instance.parent, true); |
93 | | -} |
0 commit comments