[Flare] Fix Press retention state regression (#15936)

This commit is contained in:
Dominic Gannaway
2019-06-20 13:01:56 +01:00
committed by GitHub
parent 76864f7ff7
commit e61c9e0a26
2 changed files with 52 additions and 1 deletions
+3 -1
View File
@@ -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();