@@ -45,7 +45,7 @@ function dispatchPressEvent(
45
45
context. dispatchEvent ( name , listener , state . pressTarget , true ) ;
46
46
}
47
47
48
- function dispatchPressInEvents (
48
+ function dispatchPressStartEvents (
49
49
context : EventResponderContext ,
50
50
props : Object ,
51
51
state : PressState ,
@@ -57,20 +57,24 @@ function dispatchPressInEvents(
57
57
dispatchPressEvent ( context , state , 'presschange' , pressChangeEventListener ) ;
58
58
}
59
59
60
- if ( props . onPressIn ) {
61
- dispatchPressEvent ( context , state , 'pressin ' , props . onPressIn ) ;
60
+ if ( props . onPressStart ) {
61
+ dispatchPressEvent ( context , state , 'pressstart ' , props . onPressStart ) ;
62
62
}
63
63
if ( props . onPressChange ) {
64
64
dispatchPressChangeEvent ( true ) ;
65
65
}
66
66
if ( ( props . onLongPress || props . onLongPressChange ) && ! state . isLongPressed ) {
67
- const longPressDelay = props . longPressDelay || 1000 ;
67
+ const delayLongPress = calculateDelayMS ( props . delayLongPress , 0 , 1000 ) ;
68
68
69
69
state . longPressTimeout = setTimeout ( ( ) => {
70
70
state . isLongPressed = true ;
71
71
state . longPressTimeout = null ;
72
72
73
- if ( props . onPressChange && props . longPressCancelsPress ) {
73
+ if (
74
+ props . onPressChange &&
75
+ props . onLongPressShouldCancelPress &&
76
+ props . onLongPressShouldCancelPress ( )
77
+ ) {
74
78
dispatchPressChangeEvent ( false ) ;
75
79
}
76
80
@@ -95,11 +99,11 @@ function dispatchPressInEvents(
95
99
longPressChangeEventListener ,
96
100
) ;
97
101
}
98
- } , longPressDelay ) ;
102
+ } , delayLongPress ) ;
99
103
}
100
104
}
101
105
102
- function dispatchPressOutEvents (
106
+ function dispatchPressEndEvents (
103
107
context : EventResponderContext ,
104
108
props : Object ,
105
109
state : PressState ,
@@ -108,8 +112,8 @@ function dispatchPressOutEvents(
108
112
clearTimeout ( state . longPressTimeout ) ;
109
113
state . longPressTimeout = null ;
110
114
}
111
- if ( props . onPressOut ) {
112
- dispatchPressEvent ( context , state , 'pressout ' , props . onPressOut ) ;
115
+ if ( props . onPressEnd ) {
116
+ dispatchPressEvent ( context , state , 'pressend ' , props . onPressEnd ) ;
113
117
}
114
118
if ( props . onPressChange ) {
115
119
const pressChangeEventListener = ( ) = > {
@@ -134,6 +138,11 @@ function isAnchorTagElement(eventTarget: EventTarget): boolean {
134
138
return ( eventTarget : any ) . nodeName === 'A' ;
135
139
}
136
140
141
+ function calculateDelayMS ( delay : ?number , min = 0 , fallback = 0 ) {
142
+ const maybeNumber = delay == null ? null : delay ;
143
+ return Math . max ( min , maybeNumber != null ? maybeNumber : fallback ) ;
144
+ }
145
+
137
146
const PressResponder = {
138
147
targetEventTypes,
139
148
createInitialState ( ) : PressState {
@@ -197,7 +206,7 @@ const PressResponder = {
197
206
return ;
198
207
}
199
208
state . pressTarget = eventTarget ;
200
- dispatchPressInEvents ( context , props , state ) ;
209
+ dispatchPressStartEvents ( context , props , state ) ;
201
210
state . isPressed = true ;
202
211
context . addRootEventTypes ( rootEventTypes ) ;
203
212
}
@@ -209,7 +218,7 @@ const PressResponder = {
209
218
return ;
210
219
}
211
220
if ( state . isPressed ) {
212
- dispatchPressOutEvents ( context , props , state ) ;
221
+ dispatchPressEndEvents ( context , props , state ) ;
213
222
if (
214
223
eventType !== 'touchcancel' &&
215
224
( props . onPress || props . onLongPress )
@@ -227,7 +236,11 @@ const PressResponder = {
227
236
) {
228
237
if (
229
238
props . onPress &&
230
- ! ( state . isLongPressed && props . longPressCancelsPress )
239
+ ! (
240
+ state . isLongPressed &&
241
+ props . onLongPressShouldCancelPress &&
242
+ props . onLongPressShouldCancelPress ( )
243
+ )
231
244
) {
232
245
dispatchPressEvent ( context , state , 'press' , props . onPress ) ;
233
246
}
@@ -263,7 +276,7 @@ const PressResponder = {
263
276
}
264
277
}
265
278
state . pressTarget = eventTarget ;
266
- dispatchPressInEvents ( context , props , state ) ;
279
+ dispatchPressStartEvents ( context , props , state ) ;
267
280
state . isPressed = true ;
268
281
context . addRootEventTypes ( rootEventTypes ) ;
269
282
}
@@ -276,15 +289,19 @@ const PressResponder = {
276
289
state . shouldSkipMouseAfterTouch = false ;
277
290
return ;
278
291
}
279
- dispatchPressOutEvents ( context , props , state ) ;
292
+ dispatchPressEndEvents ( context , props , state ) ;
280
293
if (
281
294
state . pressTarget !== null &&
282
295
( props . onPress || props . onLongPress )
283
296
) {
284
297
if ( context . isTargetWithinElement ( eventTarget , state . pressTarget ) ) {
285
298
if (
286
299
props . onPress &&
287
- ! ( state . isLongPressed && props . longPressCancelsPress )
300
+ ! (
301
+ state . isLongPressed &&
302
+ props . onLongPressShouldCancelPress &&
303
+ props . onLongPressShouldCancelPress ( )
304
+ )
288
305
) {
289
306
const pressEventListener = e => {
290
307
props . onPress ( e ) ;
@@ -309,7 +326,7 @@ const PressResponder = {
309
326
case 'pointercancel ': {
310
327
if ( state . isPressed ) {
311
328
state . shouldSkipMouseAfterTouch = false ;
312
- dispatchPressOutEvents ( context , props , state ) ;
329
+ dispatchPressEndEvents ( context , props , state ) ;
313
330
state . isPressed = false ;
314
331
state . isLongPressed = false ;
315
332
context . removeRootEventTypes ( rootEventTypes ) ;
0 commit comments