diff --git a/Libraries/Pressability/Pressability.js b/Libraries/Pressability/Pressability.js index fc1e00ad5d4..d77baa8c11e 100644 --- a/Libraries/Pressability/Pressability.js +++ b/Libraries/Pressability/Pressability.js @@ -546,6 +546,12 @@ export default class Pressability { }, }; + if (process.env.NODE_ENV === 'test') { + // We are setting this in order to find this node in ReactNativeTestTools + responderEventHandlers.onStartShouldSetResponder.testOnly_pressabilityConfig = () => + this._config; + } + const mouseEventHandlers = Platform.OS === 'ios' || Platform.OS === 'android' ? null diff --git a/Libraries/Utilities/ReactNativeTestTools.js b/Libraries/Utilities/ReactNativeTestTools.js index fbe4e094ca4..124437ae8ef 100644 --- a/Libraries/Utilities/ReactNativeTestTools.js +++ b/Libraries/Utilities/ReactNativeTestTools.js @@ -18,7 +18,13 @@ const ReactTestRenderer = require('react-test-renderer'); const ShallowRenderer = require('react-test-renderer/shallow'); const shallowRenderer = new ShallowRenderer(); -const {Switch, Text, TextInput, VirtualizedList} = require('react-native'); +const { + Switch, + Text, + TextInput, + View, + VirtualizedList, +} = require('react-native'); import type { ReactTestInstance, @@ -36,6 +42,8 @@ function byClickable(): Predicate { typeof node.props.onPress === 'function') || // note: Special casing since it doesn't use touchable (node.type === Switch && node.props && node.props.disabled !== true) || + (node.type === View && + node?.props?.onStartShouldSetResponder?.testOnly_pressabilityConfig) || // HACK: Find components that use `Pressability`. node.instance?.state?.pressability != null || // TODO: Remove this after deleting `Touchable`. @@ -177,6 +185,16 @@ function tap(instance: ReactTestInstance) { const {onChange, onValueChange} = touchable.props; onChange && onChange({nativeEvent: {value}}); onValueChange && onValueChange(value); + } else if ( + touchable?.props?.onStartShouldSetResponder?.testOnly_pressabilityConfig + ) { + const { + onPress, + disabled, + } = touchable.props.onStartShouldSetResponder.testOnly_pressabilityConfig(); + if (!disabled) { + onPress({nativeEvent: {}}); + } } else { // Only tap when props.disabled isn't set (or there aren't any props) if (!touchable.props || !touchable.props.disabled) {