Skip to content

Commit f4625f5

Browse files
necolastrueadm
authored andcommitted
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.
1 parent a41b217 commit f4625f5

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/react-events/src/Press.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function dispatchPressInEvents(
8080
true,
8181
);
8282
}
83-
if (props.onLongPress) {
83+
if (props.onLongPress && !props.longPressCancelsPress) {
8484
const longPressEventListener = e => {
8585
props.onLongPress(e);
8686
if (e.nativeEvent.defaultPrevented) {
@@ -110,7 +110,7 @@ function dispatchPressOutEvents(
110110
true,
111111
);
112112
}
113-
if (props.onPressChange) {
113+
if (props.onPressChange && !props.longPressCancelsPress) {
114114
const pressChangeEventListener = () => {
115115
props.onPressChange(false);
116116
};
@@ -121,6 +121,17 @@ function dispatchPressOutEvents(
121121
true,
122122
);
123123
}
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+
}
124135
}
125136

126137
function isAnchorTagElement(eventTarget: EventTarget): boolean {

0 commit comments

Comments
 (0)