@@ -80,6 +80,15 @@ function dispatchPressInEvents(
80
80
true ,
81
81
) ;
82
82
}
83
+ if ( props . onLongPress ) {
84
+ const longPressEventListener = e => {
85
+ props . onLongPress ( e ) ;
86
+ if ( e . nativeEvent . defaultPrevented ) {
87
+ state . defaultPrevented = true ;
88
+ }
89
+ } ;
90
+ dispatchPressEvent ( context , 'longpress' , state , longPressEventListener ) ;
91
+ }
83
92
} , longPressDelay ) ;
84
93
}
85
94
}
@@ -112,17 +121,6 @@ function dispatchPressOutEvents(
112
121
true ,
113
122
) ;
114
123
}
115
- if ( props . onLongPressChange && state . isLongPressed ) {
116
- const longPressChangeEventListener = ( ) = > {
117
- props . onLongPressChange ( false ) ;
118
- } ;
119
- context . dispatchEvent (
120
- 'longpresschange' ,
121
- longPressChangeEventListener ,
122
- state . pressTarget ,
123
- true ,
124
- ) ;
125
- }
126
124
}
127
125
128
126
function isAnchorTagElement ( eventTarget : EventTarget ) : boolean {
@@ -220,14 +218,10 @@ const PressResponder = {
220
218
target !== null &&
221
219
context . isTargetWithinEventComponent ( target )
222
220
) {
223
- if ( state . isLongPressed && props . onLongPress ) {
224
- dispatchPressEvent (
225
- context ,
226
- 'longpress' ,
227
- state ,
228
- props . onLongPress ,
229
- ) ;
230
- } else if ( props . onPress ) {
221
+ if (
222
+ props . onPress &&
223
+ ! ( state . isLongPressed && props . longPressCancelsPress )
224
+ ) {
231
225
dispatchPressEvent ( context , 'press' , state , props . onPress ) ;
232
226
}
233
227
}
@@ -256,7 +250,7 @@ const PressResponder = {
256
250
) {
257
251
return ;
258
252
}
259
- // Ignore right-clicks
253
+ // Ignore middle- and right-clicks
260
254
if ( event . button === 2 || event . button === 1 ) {
261
255
return ;
262
256
}
@@ -281,20 +275,10 @@ const PressResponder = {
281
275
( props . onPress || props . onLongPress )
282
276
) {
283
277
if ( context . isTargetWithinElement ( eventTarget , state . pressTarget ) ) {
284
- if ( state . isLongPressed && props . onLongPress ) {
285
- const longPressEventListener = e => {
286
- props . onLongPress ( e ) ;
287
- if ( e . nativeEvent . defaultPrevented ) {
288
- state . defaultPrevented = true ;
289
- }
290
- } ;
291
- dispatchPressEvent (
292
- context ,
293
- 'longpress' ,
294
- state ,
295
- longPressEventListener ,
296
- ) ;
297
- } else if ( props . onPress ) {
278
+ if (
279
+ props . onPress &&
280
+ ! ( state . isLongPressed && props . longPressCancelsPress )
281
+ ) {
298
282
const pressEventListener = ( e , key ) = > {
299
283
props . onPress ( e , key ) ;
300
284
if ( e . nativeEvent . defaultPrevented ) {
0 commit comments