mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
Add onMoveShouldSetResponder to element enabled checking (#577)
* fix: add onMoveShouldSetResponder to element enabled checking * Update src/fireEvent.js Co-authored-by: Maciej Jastrzebski <mdjastrzebski@gmail.com> Co-authored-by: Michał Pierzchała <thymikee@gmail.com> Co-authored-by: Maciej Jastrzebski <mdjastrzebski@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@ import React from 'react';
|
||||
import {
|
||||
View,
|
||||
TouchableOpacity,
|
||||
PanResponder,
|
||||
Pressable,
|
||||
Text,
|
||||
ScrollView,
|
||||
@@ -305,3 +306,27 @@ test('is not fooled by non-responder wrapping host elements', () => {
|
||||
fireEvent.press(screen.getByText('Trigger'));
|
||||
expect(handlePress).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
function TestDraggableComponent({ onDrag }) {
|
||||
const responderHandlers = PanResponder.create({
|
||||
onMoveShouldSetPanResponder: (_evt, _gestureState) => true,
|
||||
onPanResponderMove: onDrag,
|
||||
}).panHandlers;
|
||||
|
||||
return (
|
||||
<View {...responderHandlers}>
|
||||
<Text>Trigger</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
test('has only onMove', () => {
|
||||
const handleDrag = jest.fn();
|
||||
|
||||
const screen = render(<TestDraggableComponent onDrag={handleDrag} />);
|
||||
|
||||
fireEvent(screen.getByText('Trigger'), 'responderMove', {
|
||||
touchHistory: { mostRecentTimeStamp: '2', touchBank: [] },
|
||||
});
|
||||
expect(handleDrag).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
+6
-1
@@ -23,7 +23,12 @@ const isEventEnabled = (
|
||||
) => {
|
||||
if (isTextInput(element)) return element?.props.editable !== false;
|
||||
|
||||
return touchResponder?.props.onStartShouldSetResponder?.() !== false;
|
||||
const touchStart = touchResponder?.props.onStartShouldSetResponder?.();
|
||||
const touchMove = touchResponder?.props.onMoveShouldSetResponder?.();
|
||||
|
||||
if (touchStart || touchMove) return true;
|
||||
|
||||
return touchStart === undefined && touchMove === undefined;
|
||||
};
|
||||
|
||||
const findEventHandler = (
|
||||
|
||||
Reference in New Issue
Block a user