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.
This commit is contained in:
Nicolas Gallagher authored and Dominic Gannaway committed 2019-03-29 11:58:29 -07:00
1 parent a41b217708
commit f4625f5182
1 file changed
+13 -2
+13 -2
View File
@@ -80,7 +80,7 @@ function dispatchPressInEvents(
true,
);
}
if (props.onLongPress) {
if (props.onLongPress && !props.longPressCancelsPress) {
const longPressEventListener = e => {
props.onLongPress(e);
if (e.nativeEvent.defaultPrevented) {
@@ -110,7 +110,7 @@ function dispatchPressOutEvents(
true,
);
}
if (props.onPressChange) {
if (props.onPressChange && !props.longPressCancelsPress) {
const pressChangeEventListener = () => {
props.onPressChange(false);
};
@@ -121,6 +121,17 @@ function dispatchPressOutEvents(
true,
);
}
if (state.isLongPressed && props.onLongPressChange) {
const longPressChangeEventListener = () => {
props.onLongPressChange(false);
};
context.dispatchEvent(
'longpresschange',
longPressChangeEventListener,
state.pressTarget,
true,
);
}
}
function isAnchorTagElement(eventTarget: EventTarget): boolean {