Skip to content

Commit

Permalink
Fix on(Long)PressChange events in experimental press event API (#15256)
Browse files Browse the repository at this point in the history
Make sure that `onPressChange` is only called if `longPressCancelsPress` is `false`.
And make sure that `onLongPressChange` is called when a long press ends.
  • Loading branch information
necolas authored and trueadm committed Mar 29, 2019
1 parent a41b217 commit f4625f5
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/react-events/src/Press.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -110,7 +110,7 @@ function dispatchPressOutEvents(
true,
);
}
if (props.onPressChange) {
if (props.onPressChange && !props.longPressCancelsPress) {
const pressChangeEventListener = () => {
props.onPressChange(false);
};
Expand All @@ -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 {
Expand Down

0 comments on commit f4625f5

Please sign in to comment.