@samitouri / QOS-React-2 / commits / 47656bf2a1

[Flare] Remove longpress from press responder (#16242)

Long press will move to a separate responder.

Nicolas Gallagher committed Jul 29, 2019 at 13:12 UTC 47656bf2a1bdff25d6ade5bb580ea6ec4e4fcc94
3 files changed +24 -467
packages/react-events/docs/Press.md
+8 -33
@@ -3,9 +3,9 @@
3 The `Press` module responds to press events on the element it wraps. Press
4 events are dispatched for `mouse`, `pen`, `touch`, `trackpad`, and `keyboard`
5 pointer types. Press events are only dispatched for keyboards when pressing the
6 -Enter or Spacebar keys. If neither `onPress` nor `onLongPress` are called, this
7 -signifies that the press ended outside of the element hit bounds (i.e., the user
8 -aborted the press).
6 +Enter or Spacebar keys. If `onPress` is not called, this signifies that the
7 +press ended outside of the element hit bounds (i.e., the user aborted the
8 +press).
9
10 Press events do not propagate between `Press` event responders.
11
@@ -17,7 +17,6 @@ const Button = (props) => (
17 <Press
18 onPress={props.onPress}
19 onPressChange={setPressed}
20 - onLongPress={props.onLongPress}
20 >
21 <div
22 {...props}
@@ -60,8 +59,6 @@ type PressEvent = {
59 | 'pressend'
60 | 'presschange'
61 | 'pressmove'
63 - | 'longpress'
64 - | 'longpresschange'
62 | 'contextmenu',
63 x: number,
64 y: number
@@ -77,10 +74,6 @@ type PressOffset = {
74
75 ## Props
76
80 -### delayLongPress: number = 500ms
81 -
82 -The duration of a press before `onLongPress` and `onLongPressChange` are called.
83 -
77 ### delayPressEnd: number
78
79 The duration of the delay between when the press ends and when `onPressEnd` is
@@ -101,27 +94,10 @@ Disables all `Press` events.
94 Called when the context menu is shown. When a press is active, the context menu
95 will only be shown (and the press cancelled) if `preventDefault` is `false`.
96
104 -### onLongPress: (e: PressEvent) => void
105 -
106 -Called once the element has been pressed for the length of `delayLongPress`. If
107 -the press point moves more than 10px `onLongPress` is cancelled.
108 -
109 -### onLongPressChange: boolean => void
110 -
111 -Called when the element changes long-press state.
112 -
113 -### longPressShouldCancelPress: () => boolean
114 -
115 -Determines whether calling `onPress` should be cancelled if `onLongPress` or
116 -`onLongPressChange` have already been called. Default is `false`.
117 -
97 ### onPress: (e: PressEvent) => void
98
120 -Called immediately after a press is released, unless either 1) the press is
121 -released outside the hit bounds of the element (accounting for
122 -`pressRetentionOffset`), or 2) the press was a long press,
123 -and `onLongPress` or `onLongPressChange` props are provided, and
124 -`onLongPressCancelsPress()` is `true`.
99 +Called immediately after a press is released, unless the press is released
100 +outside the hit bounds of the element (accounting for `pressRetentionOffset`.
101
102 ### onPressChange: boolean => void
103
@@ -164,7 +140,6 @@ is still called.
140
141 Whether to `preventDefault()` native events. Native behavior is prevented by
142 default. If an anchor is the child of `Press`, internal and external navigation
167 -should be performed in `onPress`/`onLongPress`. To rely on native behavior
168 -instead, set `preventDefault` to `false`, but be aware that native behavior will
169 -take place immediately after interaction without respect for delays or long
170 -press.
143 +should be performed in `onPress`. To rely on native behavior instead, set
144 +`preventDefault` to `false`, but be aware that native behavior will take place
145 +immediately after interaction without respect for delays or long press.
packages/react-events/src/dom/Press.js
+8 -82
@@ -19,8 +19,6 @@ import {DiscreteEvent, UserBlockingEvent} from 'shared/ReactTypes';
19
20 type PressListenerProps = {|
21 onContextMenu: (e: PressEvent) => void,
22 - onLongPress: (e: PressEvent) => void,
23 - onLongPressChange: boolean => void,
22 onPress: (e: PressEvent) => void,
23 onPressChange: boolean => void,
24 onPressEnd: (e: PressEvent) => void,
@@ -30,7 +28,6 @@ type PressListenerProps = {|
28
29 type PressProps = {|
30 disabled: boolean,
33 - delayLongPress: number,
31 delayPressEnd: number,
32 delayPressStart: number,
33 pressRetentionOffset: {
@@ -42,8 +39,6 @@ type PressProps = {|
39 preventContextMenu: boolean,
40 preventDefault: boolean,
41 stopPropagation: boolean,
45 - enableLongPress: boolean,
46 - longPressShouldCancelPress: () => boolean,
42 |};
43
44 type PressState = {
@@ -54,10 +49,8 @@ type PressState = {
49 addedRootEvents: boolean,
50 isActivePressed: boolean,
51 isActivePressStart: boolean,
57 - isLongPressed: boolean,
52 isPressed: boolean,
53 isPressWithinResponderRegion: boolean,
60 - longPressTimeout: null | number,
54 pointerType: PointerType,
55 pressTarget: null | Element | Document,
56 pressEndTimeout: null | number,
@@ -86,8 +79,6 @@ type PressEventType =
79 | 'pressstart'
80 | 'pressend'
81 | 'presschange'
89 - | 'longpress'
90 - | 'longpresschange'
82 | 'contextmenu';
83
84 type PressEvent = {|
@@ -117,7 +108,6 @@ const isMac =
108 : false;
109 const DEFAULT_PRESS_END_DELAY_MS = 0;
110 const DEFAULT_PRESS_START_DELAY_MS = 0;
120 -const DEFAULT_LONG_PRESS_DELAY_MS = 500;
111 const DEFAULT_PRESS_RETENTION_OFFSET = {
112 bottom: 20,
113 top: 20,
@@ -250,14 +240,6 @@ function dispatchPressChangeEvent(
240 context.dispatchEvent('onPressChange', bool, DiscreteEvent);
241 }
242
253 -function dispatchLongPressChangeEvent(
254 - context: ReactDOMResponderContext,
255 - state: PressState,
256 -): void {
257 - const bool = state.isLongPressed;
258 - context.dispatchEvent('onLongPressChange', bool, DiscreteEvent);
259 -}
260 -
243 function activate(event: ReactDOMResponderEvent, context, props, state) {
244 const nativeEvent: any = event.nativeEvent;
245 const {clientX: x, clientY: y} = state.touchEvent || nativeEvent;
@@ -281,15 +263,10 @@ function activate(event: ReactDOMResponderEvent, context, props, state) {
263 }
264
265 function deactivate(event: ?ReactDOMResponderEvent, context, props, state) {
284 - const wasLongPressed = state.isLongPressed;
266 state.isActivePressed = false;
286 - state.isLongPressed = false;
267
268 dispatchEvent('onPressEnd', event, context, state, 'pressend', DiscreteEvent);
269 dispatchPressChangeEvent(context, state);
290 - if (wasLongPressed && props.enableLongPress) {
291 - dispatchLongPressChangeEvent(context, state);
292 - }
270 }
271
272 function dispatchPressStartEvents(
@@ -308,27 +285,6 @@ function dispatchPressStartEvents(
285 const dispatch = () => {
286 state.isActivePressStart = true;
287 activate(event, context, props, state);
311 -
312 - if (!state.isLongPressed && props.enableLongPress) {
313 - const delayLongPress = calculateDelayMS(
314 - props.delayLongPress,
315 - 10,
316 - DEFAULT_LONG_PRESS_DELAY_MS,
317 - );
318 - state.longPressTimeout = context.setTimeout(() => {
319 - state.isLongPressed = true;
320 - state.longPressTimeout = null;
321 - dispatchEvent(
322 - 'onLongPress',
323 - event,
324 - context,
325 - state,
326 - 'longpress',
327 - DiscreteEvent,
328 - );
329 - dispatchLongPressChangeEvent(context, state);
330 - }, delayLongPress);
331 - }
288 };
289
290 if (!state.isActivePressStart) {
@@ -360,11 +316,6 @@ function dispatchPressEndEvents(
316 state.isActivePressStart = false;
317 state.isPressed = false;
318
363 - if (state.longPressTimeout !== null) {
364 - context.clearTimeout(state.longPressTimeout);
365 - state.longPressTimeout = null;
366 - }
367 -
319 if (!wasActivePressStart && state.pressStartTimeout !== null) {
320 context.clearTimeout(state.pressStartTimeout);
321 state.pressStartTimeout = null;
@@ -596,10 +547,8 @@ const pressResponderImpl = {
547 addedRootEvents: false,
548 isActivePressed: false,
549 isActivePressStart: false,
599 - isLongPressed: false,
550 isPressed: false,
551 isPressWithinResponderRegion: true,
602 - longPressTimeout: null,
552 pointerType: '',
553 pressEndTimeout: null,
554 pressStartTimeout: null,
@@ -823,19 +772,6 @@ const pressResponderImpl = {
772 'pressmove',
773 UserBlockingEvent,
774 );
826 - if (
827 - state.activationPosition != null &&
828 - state.longPressTimeout != null
829 - ) {
830 - const deltaX = state.activationPosition.x - nativeEvent.clientX;
831 - const deltaY = state.activationPosition.y - nativeEvent.clientY;
832 - if (
833 - Math.hypot(deltaX, deltaY) > 10 &&
834 - state.longPressTimeout != null
835 - ) {
836 - context.clearTimeout(state.longPressTimeout);
837 - }
838 - }
775 } else {
776 dispatchPressStartEvents(event, context, props, state);
777 }
@@ -900,7 +836,6 @@ const pressResponderImpl = {
836 }
837 }
838
903 - const wasLongPressed = state.isLongPressed;
839 const pressTarget = state.pressTarget;
840 dispatchPressEndEvents(event, context, props, state);
841
@@ -928,23 +863,14 @@ const pressResponderImpl = {
863 }
864 }
865 if (state.isPressWithinResponderRegion && button !== 1) {
931 - if (
932 - !(
933 - wasLongPressed &&
934 - props.enableLongPress &&
935 - props.longPressShouldCancelPress &&
936 - props.longPressShouldCancelPress()
937 - )
938 - ) {
939 - dispatchEvent(
940 - 'onPress',
941 - event,
942 - context,
943 - state,
944 - 'press',
945 - DiscreteEvent,
946 - );
947 - }
866 + dispatchEvent(
867 + 'onPress',
868 + event,
869 + context,
870 + state,
871 + 'press',
872 + DiscreteEvent,
873 + );
874 }
875 }
876 state.touchEvent = null;
packages/react-events/src/dom/__tests__/Press-test.internal.js
+8 -352
@@ -928,258 +928,6 @@ describe('Event responder: Press', () => {
928 // });
929 });
930
931 - describe('onLongPress', () => {
932 - let onLongPress, ref;
933 -
934 - beforeEach(() => {
935 - onLongPress = jest.fn();
936 - ref = React.createRef();
937 - const Component = () => {
938 - usePressListener({
939 - onLongPress,
940 - });
941 - return (
942 - <div
943 - ref={ref}
944 - responders={<PressResponder enableLongPress={true} />}
945 - />
946 - );
947 - };
948 - ReactDOM.render(<Component />, container);
949 - });
950 -
951 - it('is called if "pointerdown" lasts default delay', () => {
952 - ref.current.dispatchEvent(
953 - createEvent('pointerdown', {pointerType: 'pen'}),
954 - );
955 - ref.current.dispatchEvent(
956 - createTouchEvent('touchstart', 0, {
957 - target: ref.current,
958 - }),
959 - );
960 - jest.advanceTimersByTime(DEFAULT_LONG_PRESS_DELAY - 1);
961 - expect(onLongPress).not.toBeCalled();
962 - jest.advanceTimersByTime(1);
963 - expect(onLongPress).toHaveBeenCalledTimes(1);
964 - expect(onLongPress).toHaveBeenCalledWith(
965 - expect.objectContaining({pointerType: 'pen', type: 'longpress'}),
966 - );
967 - });
968 -
969 - it('is not called if "pointerup" is dispatched before delay', () => {
970 - ref.current.dispatchEvent(createEvent('pointerdown'));
971 - jest.advanceTimersByTime(DEFAULT_LONG_PRESS_DELAY - 1);
972 - ref.current.dispatchEvent(createEvent('pointerup'));
973 - jest.advanceTimersByTime(1);
974 - expect(onLongPress).not.toBeCalled();
975 - });
976 -
977 - it('is called if valid "keydown" lasts default delay', () => {
978 - ref.current.dispatchEvent(createKeyboardEvent('keydown', {key: 'Enter'}));
979 - jest.advanceTimersByTime(DEFAULT_LONG_PRESS_DELAY - 1);
980 - expect(onLongPress).not.toBeCalled();
981 - jest.advanceTimersByTime(1);
982 - expect(onLongPress).toHaveBeenCalledTimes(1);
983 - expect(onLongPress).toHaveBeenCalledWith(
984 - expect.objectContaining({pointerType: 'keyboard', type: 'longpress'}),
985 - );
986 - });
987 -
988 - it('is not called if valid "keyup" is dispatched before delay', () => {
989 - ref.current.dispatchEvent(createKeyboardEvent('keydown', {key: 'Enter'}));
990 - jest.advanceTimersByTime(DEFAULT_LONG_PRESS_DELAY - 1);
991 - ref.current.dispatchEvent(createKeyboardEvent('keyup', {key: 'Enter'}));
992 - jest.advanceTimersByTime(1);
993 - expect(onLongPress).not.toBeCalled();
994 - });
995 -
996 - it('is not called when a large enough move occurs before delay', () => {
997 - ref.current.getBoundingClientRect = () => ({
998 - top: 0,
999 - left: 0,
1000 - bottom: 100,
1001 - right: 100,
1002 - });
1003 - ref.current.dispatchEvent(
1004 - createEvent('pointerdown', {clientX: 10, clientY: 10}),
1005 - );
1006 - ref.current.dispatchEvent(
1007 - createEvent('pointermove', {clientX: 50, clientY: 50}),
1008 - );
1009 - jest.runAllTimers();
1010 - expect(onLongPress).not.toBeCalled();
1011 - });
1012 -
1013 - describe('delayLongPress', () => {
1014 - it('can be configured', () => {
1015 - const Component = () => {
1016 - usePressListener({
1017 - onLongPress,
1018 - });
1019 - return (
1020 - <div
1021 - ref={ref}
1022 - responders={
1023 - <PressResponder delayLongPress={2000} enableLongPress={true} />
1024 - }
1025 - />
1026 - );
1027 - };
1028 - ReactDOM.render(<Component />, container);
1029 -
1030 - ref.current.dispatchEvent(createEvent('pointerdown'));
1031 - jest.advanceTimersByTime(1999);
1032 - expect(onLongPress).not.toBeCalled();
1033 - jest.advanceTimersByTime(1);
1034 - expect(onLongPress).toHaveBeenCalledTimes(1);
1035 - });
1036 -
1037 - it('uses 10ms minimum delay length', () => {
1038 - const Component = () => {
1039 - usePressListener({
1040 - onLongPress,
1041 - });
1042 - return (
1043 - <div
1044 - ref={ref}
1045 - responders={
1046 - <PressResponder delayLongPress={0} enableLongPress={true} />
1047 - }
1048 - />
1049 - );
1050 - };
1051 - ReactDOM.render(<Component />, container);
1052 -
1053 - ref.current.dispatchEvent(createEvent('pointerdown'));
1054 - jest.advanceTimersByTime(9);
1055 - expect(onLongPress).not.toBeCalled();
1056 - jest.advanceTimersByTime(1);
1057 - expect(onLongPress).toHaveBeenCalledTimes(1);
1058 - });
1059 -
1060 - it('compounds with "delayPressStart"', () => {
1061 - const delayPressStart = 100;
1062 - const Component = () => {
1063 - usePressListener({
1064 - onLongPress,
1065 - });
1066 - return (
1067 - <div
1068 - ref={ref}
1069 - responders={
1070 - <PressResponder
1071 - delayPressStart={delayPressStart}
1072 - enableLongPress={true}
1073 - />
1074 - }
1075 - />
1076 - );
1077 - };
1078 - ReactDOM.render(<Component />, container);
1079 -
1080 - ref.current.dispatchEvent(createEvent('pointerdown'));
1081 - jest.advanceTimersByTime(
1082 - delayPressStart + DEFAULT_LONG_PRESS_DELAY - 1,
1083 - );
1084 - expect(onLongPress).not.toBeCalled();
1085 - jest.advanceTimersByTime(1);
1086 - expect(onLongPress).toHaveBeenCalledTimes(1);
1087 - });
1088 - });
1089 - });
1090 -
1091 - describe('onLongPressChange', () => {
1092 - it('is called when long press state changes', () => {
1093 - const onLongPressChange = jest.fn();
1094 - const ref = React.createRef();
1095 - const Component = () => {
1096 - usePressListener({
1097 - onLongPressChange,
1098 - });
1099 - return (
1100 - <div
1101 - ref={ref}
1102 - responders={<PressResponder enableLongPress={true} />}
1103 - />
1104 - );
1105 - };
1106 - ReactDOM.render(<Component />, container);
1107 -
1108 - ref.current.dispatchEvent(createEvent('pointerdown'));
1109 - jest.advanceTimersByTime(DEFAULT_LONG_PRESS_DELAY);
1110 - expect(onLongPressChange).toHaveBeenCalledTimes(1);
1111 - expect(onLongPressChange).toHaveBeenCalledWith(true);
1112 - ref.current.dispatchEvent(createEvent('pointerup'));
1113 - expect(onLongPressChange).toHaveBeenCalledTimes(2);
1114 - expect(onLongPressChange).toHaveBeenCalledWith(false);
1115 - });
1116 -
1117 - it('is called after delayed onPressEnd', () => {
1118 - const onLongPressChange = jest.fn();
1119 - const ref = React.createRef();
1120 - const Component = () => {
1121 - usePressListener({
1122 - onLongPressChange,
1123 - });
1124 - return (
1125 - <div
1126 - ref={ref}
1127 - responders={
1128 - <PressResponder delayPressEnd={500} enableLongPress={true} />
1129 - }
1130 - />
1131 - );
1132 - };
1133 - ReactDOM.render(<Component />, container);
1134 -
1135 - ref.current.dispatchEvent(createEvent('pointerdown'));
1136 - jest.advanceTimersByTime(DEFAULT_LONG_PRESS_DELAY);
1137 - expect(onLongPressChange).toHaveBeenCalledTimes(1);
1138 - expect(onLongPressChange).toHaveBeenCalledWith(true);
1139 - ref.current.dispatchEvent(createEvent('pointerup'));
1140 - jest.advanceTimersByTime(499);
1141 - expect(onLongPressChange).toHaveBeenCalledTimes(1);
1142 - jest.advanceTimersByTime(1);
1143 - expect(onLongPressChange).toHaveBeenCalledTimes(2);
1144 - expect(onLongPressChange).toHaveBeenCalledWith(false);
1145 - });
1146 - });
1147 -
1148 - describe('longPressShouldCancelPress', () => {
1149 - it('if true it cancels "onPress"', () => {
1150 - const onPress = jest.fn();
1151 - const onPressChange = jest.fn();
1152 - const ref = React.createRef();
1153 - const Component = () => {
1154 - usePressListener({
1155 - onLongPress: () => {},
1156 - onPressChange,
1157 - onPress,
1158 - });
1159 - return (
1160 - <div
1161 - ref={ref}
1162 - responders={
1163 - <PressResponder
1164 - longPressShouldCancelPress={() => true}
1165 - enableLongPress={true}
1166 - />
1167 - }
1168 - />
1169 - );
1170 - };
1171 - ReactDOM.render(<Component />, container);
1172 -
1173 - // NOTE: onPressChange behavior should not be affected
1174 - ref.current.dispatchEvent(createEvent('pointerdown'));
1175 - expect(onPressChange).toHaveBeenCalledTimes(1);
1176 - jest.advanceTimersByTime(DEFAULT_LONG_PRESS_DELAY);
1177 - ref.current.dispatchEvent(createEvent('pointerup'));
1178 - expect(onPress).not.toBeCalled();
1179 - expect(onPressChange).toHaveBeenCalledTimes(2);
1180 - });
1181 - });
1182 -
931 describe('onPressMove', () => {
932 it('is called after "pointermove"', () => {
933 const onPressMove = jest.fn();
@@ -1621,7 +1369,6 @@ describe('Event responder: Press', () => {
1369
1370 const Component = () => {
1371 usePressListener({
1624 - onLongPress: createEventHandler('onLongPress'),
1372 onPress: createEventHandler('onPress'),
1373 onPressChange: createEventHandler('onPressChange'),
1374 onPressMove: createEventHandler('onPressMove'),
@@ -1632,11 +1379,7 @@ describe('Event responder: Press', () => {
1379 <div
1380 ref={ref}
1381 responders={
1635 - <PressResponder
1636 - delayPressStart={500}
1637 - delayPressEnd={500}
1638 - enableLongPress={true}
1639 - />
1382 + <PressResponder delayPressStart={500} delayPressEnd={500} />
1383 }
1384 />
1385 );
@@ -2243,7 +1986,6 @@ describe('Event responder: Press', () => {
1986
1987 const Component = () => {
1988 usePressListener({
2246 - onLongPress: createEventHandler('onLongPress'),
1989 onPress: createEventHandler('onPress'),
1990 onPressChange: createEventHandler('onPressChange'),
1991 onPressMove: createEventHandler('onPressMove'),
@@ -2254,11 +1996,7 @@ describe('Event responder: Press', () => {
1996 <div
1997 ref={ref}
1998 responders={
2257 - <PressResponder
2258 - delayPressStart={500}
2259 - delayPressEnd={500}
2260 - enableLongPress={true}
2261 - />
1999 + <PressResponder delayPressStart={500} delayPressEnd={500} />
2000 }
2001 />
2002 );
@@ -2378,8 +2116,6 @@ describe('Event responder: Press', () => {
2116
2117 const Component = () => {
2118 usePressListener({
2381 - onLongPress: createEventHandler('onLongPress'),
2382 - onLongPressChange: createEventHandler('onLongPressChange'),
2119 onPress: createEventHandler('onPress'),
2120 onPressChange: createEventHandler('onPressChange'),
2121 onPressMove: createEventHandler('onPressMove'),
@@ -2390,11 +2126,7 @@ describe('Event responder: Press', () => {
2126 <div
2127 ref={ref}
2128 responders={
2393 - <PressResponder
2394 - delayPressStart={250}
2395 - delayPressEnd={250}
2396 - enableLongPress={true}
2397 - />
2129 + <PressResponder delayPressStart={250} delayPressEnd={250} />
2130 }
2131 />
2132 );
@@ -2443,12 +2175,9 @@ describe('Event responder: Press', () => {
2175 expect(events).toEqual([
2176 'onPressStart',
2177 'onPressChange',
2446 - 'onLongPress',
2447 - 'onLongPressChange',
2178 'onPress',
2179 'onPressEnd',
2180 'onPressChange',
2451 - 'onLongPressChange',
2181 ]);
2182 });
2183 });
@@ -2557,40 +2286,6 @@ describe('Event responder: Press', () => {
2286 expect(fn).toHaveBeenCalledTimes(1);
2287 });
2288
2560 - it('for onLongPress', () => {
2561 - const ref = React.createRef();
2562 - const fn = jest.fn();
2563 -
2564 - const Inner = () => {
2565 - usePressListener({
2566 - onLongPress: fn,
2567 - });
2568 - return (
2569 - <div
2570 - ref={ref}
2571 - responders={<PressResponder enableLongPress={true} />}
2572 - />
2573 - );
2574 - };
2575 -
2576 - const Outer = () => {
2577 - usePressListener({
2578 - onLongPress: fn,
2579 - });
2580 - return (
2581 - <div responders={<PressResponder enableLongPress={true} />}>
2582 - <Inner />
2583 - </div>
2584 - );
2585 - };
2586 - ReactDOM.render(<Outer />, container);
2587 -
2588 - ref.current.dispatchEvent(createEvent('pointerdown'));
2589 - jest.advanceTimersByTime(DEFAULT_LONG_PRESS_DELAY);
2590 - ref.current.dispatchEvent(createEvent('pointerup'));
2591 - expect(fn).toHaveBeenCalledTimes(1);
2592 - });
2593 -
2289 it('for onPressStart/onPressEnd', () => {
2290 const ref = React.createRef();
2291 const fn = jest.fn();
@@ -2863,22 +2558,14 @@ describe('Event responder: Press', () => {
2558
2559 describe('responder cancellation', () => {
2560 it('ends on "pointercancel", "touchcancel", "scroll", and "dragstart"', () => {
2866 - const onLongPress = jest.fn();
2561 const onPressEnd = jest.fn();
2562 const ref = React.createRef();
2563
2564 const Component = () => {
2565 usePressListener({
2872 - onLongPress,
2566 onPressEnd,
2567 });
2875 - return (
2876 - <a
2877 - href="#"
2878 - ref={ref}
2879 - responders={<PressResponder enableLongPress={true} />}
2880 - />
2881 - );
2568 + return <a href="#" ref={ref} responders={<PressResponder />} />;
2569 };
2570 ReactDOM.render(<Component />, container);
2571
@@ -2890,8 +2577,6 @@ describe('Event responder: Press', () => {
2577 );
2578 ref.current.dispatchEvent(createEvent('scroll'));
2579 expect(onPressEnd).toHaveBeenCalledTimes(1);
2893 - jest.runAllTimers();
2894 - expect(onLongPress).not.toBeCalled();
2580
2581 onPressEnd.mockReset();
2582
@@ -2903,9 +2588,6 @@ describe('Event responder: Press', () => {
2588 );
2589 ref.current.dispatchEvent(createEvent('scroll'));
2590 expect(onPressEnd).toHaveBeenCalledTimes(0);
2906 - jest.runAllTimers();
2907 -
2908 - onLongPress.mockReset();
2591
2592 // When pointer events are supported
2593 ref.current.dispatchEvent(
@@ -2919,10 +2601,7 @@ describe('Event responder: Press', () => {
2601 }),
2602 );
2603 expect(onPressEnd).toHaveBeenCalledTimes(1);
2922 - jest.runAllTimers();
2923 - expect(onLongPress).not.toBeCalled();
2604
2925 - onLongPress.mockReset();
2605 onPressEnd.mockReset();
2606
2607 // Touch fallback
@@ -2937,18 +2616,13 @@ describe('Event responder: Press', () => {
2616 }),
2617 );
2618 expect(onPressEnd).toHaveBeenCalledTimes(1);
2940 - jest.runAllTimers();
2941 - expect(onLongPress).not.toBeCalled();
2619
2943 - onLongPress.mockReset();
2620 onPressEnd.mockReset();
2621
2622 // Mouse fallback
2623 ref.current.dispatchEvent(createEvent('mousedown'));
2624 ref.current.dispatchEvent(createEvent('dragstart'));
2625 expect(onPressEnd).toHaveBeenCalledTimes(1);
2950 - jest.runAllTimers();
2951 - expect(onLongPress).not.toBeCalled();
2626 });
2627 });
2628
@@ -3059,15 +2733,9 @@ describe('Event responder: Press', () => {
2733 onPressStart: logEvent,
2734 onPressEnd: logEvent,
2735 onPressMove: logEvent,
3062 - onLongPress: logEvent,
2736 onPress: logEvent,
2737 });
3065 - return (
3066 - <button
3067 - ref={ref}
3068 - responders={<PressResponder enableLongPress={true} />}
3069 - />
3070 - );
2738 + return <button ref={ref} responders={<PressResponder />} />;
2739 };
2740 ReactDOM.render(<Component />, container);
2741
@@ -3137,18 +2805,6 @@ describe('Event responder: Press', () => {
2805 timeStamp: timeStamps[0],
2806 type: 'pressstart',
2807 },
3140 - {
3141 - pointerType: 'mouse',
3142 - pageX: 15,
3143 - pageY: 16,
3144 - screenX: 20,
3145 - screenY: 21,
3146 - clientX: 30,
3147 - clientY: 31,
3148 - target: ref.current,
3149 - timeStamp: timeStamps[0] + DEFAULT_LONG_PRESS_DELAY,
3150 - type: 'longpress',
3151 - },
2808 {
2809 pointerType: 'mouse',
2810 pageX: 16,
@@ -3158,7 +2814,7 @@ describe('Event responder: Press', () => {
2814 clientX: 31,
2815 clientY: 32,
2816 target: ref.current,
3161 - timeStamp: timeStamps[2],
2817 + timeStamp: timeStamps[1],
2818 type: 'pressmove',
2819 },
2820 {
@@ -3170,7 +2826,7 @@ describe('Event responder: Press', () => {
2826 clientX: 32,
2827 clientY: 33,
2828 target: ref.current,
3173 - timeStamp: timeStamps[3],
2829 + timeStamp: timeStamps[2],
2830 type: 'pressend',
2831 },
2832 {
@@ -3194,7 +2850,7 @@ describe('Event responder: Press', () => {
2850 clientX: 33,
2851 clientY: 34,
2852 target: ref.current,
3197 - timeStamp: timeStamps[5],
2853 + timeStamp: timeStamps[4],
2854 type: 'pressstart',
2855 },
2856 ]);