Fix on(Long)PressChange events in experimental press event API (#15256)
Make sure that `onPressChange` is only called if `longPressCancelsPress` is `false`. And make sure that `onLongPressChange` is called when a long press ends.
Nicolas Gallagher committed
Mar 29, 2019 at 11:58 UTC
f4625f51823dd7faa02bba95ae731249ce07246c
1 file changed
+13
-2
packages/react-events/src/Press.js
+13
-2
@@ -80,7 +80,7 @@ function dispatchPressInEvents(
80
true,
81
);
82
}
83
- if (props.onLongPress) {
83
+ if (props.onLongPress && !props.longPressCancelsPress) {
84
const longPressEventListener = e => {
85
props.onLongPress(e);
86
if (e.nativeEvent.defaultPrevented) {
@@ -110,7 +110,7 @@ function dispatchPressOutEvents(
110
true,
111
);
112
}
113
- if (props.onPressChange) {
113
+ if (props.onPressChange && !props.longPressCancelsPress) {
114
const pressChangeEventListener = () => {
115
props.onPressChange(false);
116
};
@@ -121,6 +121,17 @@ function dispatchPressOutEvents(
121
true,
122
);
123
}
124
+ if (state.isLongPressed && props.onLongPressChange) {
125
+ const longPressChangeEventListener = () => {
126
+ props.onLongPressChange(false);
127
+ };
128
+ context.dispatchEvent(
129
+ 'longpresschange',
130
+ longPressChangeEventListener,
131
+ state.pressTarget,
132
+ true,
133
+ );
134
+ }
135
}
136
137
function isAnchorTagElement(eventTarget: EventTarget): boolean {