|
1 | 1 | import type { ReactTestInstance } from 'react-test-renderer'; |
2 | 2 |
|
3 | 3 | import act from '../../act'; |
4 | | -import { getHostParent } from '../../helpers/component-tree'; |
5 | | -import { isHostText } from '../../helpers/host-component-names'; |
| 4 | +import { getEventHandler } from '../../event-handler'; |
| 5 | +import { getHostParent, isHostElement } from '../../helpers/component-tree'; |
| 6 | +import { isHostTextInput } from '../../helpers/host-component-names'; |
6 | 7 | import { isPointerEventEnabled } from '../../helpers/pointer-events'; |
7 | 8 | import { isEditableTextInput } from '../../helpers/text-input'; |
8 | 9 | import { EventBuilder } from '../event-builder'; |
@@ -45,13 +46,13 @@ const basePress = async ( |
45 | 46 | element: ReactTestInstance, |
46 | 47 | options: BasePressOptions, |
47 | 48 | ): Promise<void> => { |
48 | | - if (isPressableText(element)) { |
49 | | - await emitTextPressEvents(config, element, options); |
| 49 | + if (isEditableTextInput(element) && isPointerEventEnabled(element)) { |
| 50 | + await emitTextInputPressEvents(config, element, options); |
50 | 51 | return; |
51 | 52 | } |
52 | 53 |
|
53 | | - if (isEditableTextInput(element) && isPointerEventEnabled(element)) { |
54 | | - await emitTextInputPressEvents(config, element, options); |
| 54 | + if (isHostPressable(element)) { |
| 55 | + await emitTextPressEvents(config, element, options); |
55 | 56 | return; |
56 | 57 | } |
57 | 58 |
|
@@ -96,16 +97,16 @@ const isEnabledTouchResponder = (element: ReactTestInstance) => { |
96 | 97 | return isPointerEventEnabled(element) && element.props.onStartShouldSetResponder?.(); |
97 | 98 | }; |
98 | 99 |
|
99 | | -const isPressableText = (element: ReactTestInstance) => { |
100 | | - const hasPressEventHandler = Boolean( |
101 | | - element.props.onPress || |
102 | | - element.props.onLongPress || |
103 | | - element.props.onPressIn || |
104 | | - element.props.onPressOut, |
105 | | - ); |
| 100 | +const isHostPressable = (element: ReactTestInstance) => { |
| 101 | + const hasPressEventHandler = |
| 102 | + getEventHandler(element, 'press') || |
| 103 | + getEventHandler(element, 'longPress') || |
| 104 | + getEventHandler(element, 'pressIn') || |
| 105 | + getEventHandler(element, 'pressOut'); |
106 | 106 |
|
107 | 107 | return ( |
108 | | - isHostText(element) && |
| 108 | + isHostElement(element) && |
| 109 | + !isHostTextInput(element) && |
109 | 110 | isPointerEventEnabled(element) && |
110 | 111 | !element.props.disabled && |
111 | 112 | hasPressEventHandler |
|
0 commit comments