@samitouri / QOS-React-2 / commits / e61c9e0a26

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

Dominic Gannaway committed Jun 20, 2019 at 13:01 UTC e61c9e0a2618acde0c6000ef59b0ca3694587e44
2 files changed +52 -1
packages/react-events/src/Press.js
+3 -1
@@ -576,6 +576,7 @@ function updateIsPressWithinResponderRegion(
576 props: PressProps,
577 state: PressState,
578 ): void {
579 + let isPressWithinResponderRegion = true;
580 if (
581 state.pressTarget != null &&
582 !context.isTargetWithinElement(target, state.pressTarget)
@@ -607,7 +608,7 @@ function updateIsPressWithinResponderRegion(
608 }
609 const {clientX: x, clientY: y} = (nativeEventOrTouchEvent: any);
610
610 - state.isPressWithinResponderRegion =
611 + isPressWithinResponderRegion =
612 left != null &&
613 right != null &&
614 top != null &&
@@ -616,6 +617,7 @@ function updateIsPressWithinResponderRegion(
617 y !== null &&
618 (x >= left && x <= right && y >= top && y <= bottom);
619 }
620 + state.isPressWithinResponderRegion = isPressWithinResponderRegion;
621 }
622
623 const PressResponder = {
packages/react-events/src/__tests__/Press-test.internal.js
+49
@@ -1049,6 +1049,55 @@ describe('Event responder: Press', () => {
1049 ]);
1050 });
1051
1052 + it('no delay and "onPress*" events are correctly called with target change', () => {
1053 + let events = [];
1054 + const outerRef = React.createRef();
1055 + const innerRef = React.createRef();
1056 + const createEventHandler = msg => () => {
1057 + events.push(msg);
1058 + };
1059 +
1060 + const element = (
1061 + <div ref={outerRef}>
1062 + <Press
1063 + onPress={createEventHandler('onPress')}
1064 + onPressChange={createEventHandler('onPressChange')}
1065 + onPressMove={createEventHandler('onPressMove')}
1066 + onPressStart={createEventHandler('onPressStart')}
1067 + onPressEnd={createEventHandler('onPressEnd')}>
1068 + <div ref={innerRef} />
1069 + </Press>
1070 + </div>
1071 + );
1072 +
1073 + ReactDOM.render(element, container);
1074 +
1075 + innerRef.current.getBoundingClientRect = getBoundingClientRectMock;
1076 + innerRef.current.dispatchEvent(createEvent('pointerdown'));
1077 + outerRef.current.dispatchEvent(
1078 + createEvent('pointermove', coordinatesOutside),
1079 + );
1080 + innerRef.current.dispatchEvent(
1081 + createEvent('pointermove', coordinatesInside),
1082 + );
1083 + innerRef.current.dispatchEvent(
1084 + createEvent('pointerup', coordinatesInside),
1085 + );
1086 + jest.runAllTimers();
1087 +
1088 + expect(events).toEqual([
1089 + 'onPressStart',
1090 + 'onPressChange',
1091 + 'onPressEnd',
1092 + 'onPressChange',
1093 + 'onPressStart',
1094 + 'onPressChange',
1095 + 'onPressEnd',
1096 + 'onPressChange',
1097 + 'onPress',
1098 + ]);
1099 + });
1100 +
1101 it('delay and "onPressMove" is called before "onPress*" events', () => {
1102 let events = [];
1103 const ref = React.createRef();