mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[Flare] Fix Press retention state regression (#15936)
This commit is contained in:
Vendored
+3
-1
@@ -576,6 +576,7 @@ function updateIsPressWithinResponderRegion(
|
||||
props: PressProps,
|
||||
state: PressState,
|
||||
): void {
|
||||
let isPressWithinResponderRegion = true;
|
||||
if (
|
||||
state.pressTarget != null &&
|
||||
!context.isTargetWithinElement(target, state.pressTarget)
|
||||
@@ -607,7 +608,7 @@ function updateIsPressWithinResponderRegion(
|
||||
}
|
||||
const {clientX: x, clientY: y} = (nativeEventOrTouchEvent: any);
|
||||
|
||||
state.isPressWithinResponderRegion =
|
||||
isPressWithinResponderRegion =
|
||||
left != null &&
|
||||
right != null &&
|
||||
top != null &&
|
||||
@@ -616,6 +617,7 @@ function updateIsPressWithinResponderRegion(
|
||||
y !== null &&
|
||||
(x >= left && x <= right && y >= top && y <= bottom);
|
||||
}
|
||||
state.isPressWithinResponderRegion = isPressWithinResponderRegion;
|
||||
}
|
||||
|
||||
const PressResponder = {
|
||||
|
||||
@@ -1049,6 +1049,55 @@ describe('Event responder: Press', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('no delay and "onPress*" events are correctly called with target change', () => {
|
||||
let events = [];
|
||||
const outerRef = React.createRef();
|
||||
const innerRef = React.createRef();
|
||||
const createEventHandler = msg => () => {
|
||||
events.push(msg);
|
||||
};
|
||||
|
||||
const element = (
|
||||
<div ref={outerRef}>
|
||||
<Press
|
||||
onPress={createEventHandler('onPress')}
|
||||
onPressChange={createEventHandler('onPressChange')}
|
||||
onPressMove={createEventHandler('onPressMove')}
|
||||
onPressStart={createEventHandler('onPressStart')}
|
||||
onPressEnd={createEventHandler('onPressEnd')}>
|
||||
<div ref={innerRef} />
|
||||
</Press>
|
||||
</div>
|
||||
);
|
||||
|
||||
ReactDOM.render(element, container);
|
||||
|
||||
innerRef.current.getBoundingClientRect = getBoundingClientRectMock;
|
||||
innerRef.current.dispatchEvent(createEvent('pointerdown'));
|
||||
outerRef.current.dispatchEvent(
|
||||
createEvent('pointermove', coordinatesOutside),
|
||||
);
|
||||
innerRef.current.dispatchEvent(
|
||||
createEvent('pointermove', coordinatesInside),
|
||||
);
|
||||
innerRef.current.dispatchEvent(
|
||||
createEvent('pointerup', coordinatesInside),
|
||||
);
|
||||
jest.runAllTimers();
|
||||
|
||||
expect(events).toEqual([
|
||||
'onPressStart',
|
||||
'onPressChange',
|
||||
'onPressEnd',
|
||||
'onPressChange',
|
||||
'onPressStart',
|
||||
'onPressChange',
|
||||
'onPressEnd',
|
||||
'onPressChange',
|
||||
'onPress',
|
||||
]);
|
||||
});
|
||||
|
||||
it('delay and "onPressMove" is called before "onPress*" events', () => {
|
||||
let events = [];
|
||||
const ref = React.createRef();
|
||||
|
||||
Reference in New Issue
Block a user