@@ -28,8 +28,6 @@ type PressListenerProps = {|
28
28
29
29
type PressProps = { |
30
30
disabled : boolean ,
31
- delayPressEnd : number ,
32
- delayPressStart : number ,
33
31
pressRetentionOffset : {
34
32
top : number ,
35
33
right : number ,
@@ -53,7 +51,6 @@ type PressState = {
53
51
isPressWithinResponderRegion : boolean ,
54
52
pointerType : PointerType ,
55
53
pressTarget : null | Element | Document ,
56
- pressEndTimeout : null | number ,
57
54
pressStartTimeout : null | number ,
58
55
responderRegionOnActivation : null | $ReadOnly < { |
59
56
bottom : number ,
@@ -106,8 +103,6 @@ const isMac =
106
103
typeof window !== 'undefined' && window . navigator != null
107
104
? / ^ M a c / . test ( window . navigator . platform )
108
105
: false ;
109
- const DEFAULT_PRESS_END_DELAY_MS = 0 ;
110
- const DEFAULT_PRESS_START_DELAY_MS = 0 ;
111
106
const DEFAULT_PRESS_RETENTION_OFFSET = {
112
107
bottom : 20 ,
113
108
top : 20 ,
@@ -240,35 +235,6 @@ function dispatchPressChangeEvent(
240
235
context . dispatchEvent ( 'onPressChange' , bool , DiscreteEvent ) ;
241
236
}
242
237
243
- function activate ( event : ReactDOMResponderEvent , context , props , state ) {
244
- const nativeEvent : any = event . nativeEvent ;
245
- const { clientX : x , clientY : y } = state . touchEvent || nativeEvent ;
246
- const wasActivePressed = state . isActivePressed ;
247
- state . isActivePressed = true ;
248
- if ( x !== undefined && y !== undefined ) {
249
- state . activationPosition = { x, y} ;
250
- }
251
-
252
- dispatchEvent (
253
- 'onPressStart' ,
254
- event ,
255
- context ,
256
- state ,
257
- 'pressstart' ,
258
- DiscreteEvent ,
259
- ) ;
260
- if ( ! wasActivePressed ) {
261
- dispatchPressChangeEvent ( context , state ) ;
262
- }
263
- }
264
-
265
- function deactivate ( event : ?ReactDOMResponderEvent , context , props , state ) {
266
- state . isActivePressed = false ;
267
-
268
- dispatchEvent ( 'onPressEnd' , event , context , state , 'pressend' , DiscreteEvent ) ;
269
- dispatchPressChangeEvent ( context , state ) ;
270
- }
271
-
272
238
function dispatchPressStartEvents (
273
239
event : ReactDOMResponderEvent ,
274
240
context : ReactDOMResponderContext ,
@@ -277,29 +243,26 @@ function dispatchPressStartEvents(
277
243
) : void {
278
244
state . isPressed = true ;
279
245
280
- if ( state . pressEndTimeout !== null ) {
281
- context . clearTimeout ( state . pressEndTimeout ) ;
282
- state . pressEndTimeout = null ;
283
- }
284
-
285
- const dispatch = ( ) => {
246
+ if ( ! state . isActivePressStart ) {
286
247
state . isActivePressStart = true ;
287
- activate ( event , context , props , state ) ;
288
- } ;
248
+ const nativeEvent : any = event . nativeEvent ;
249
+ const { clientX : x , clientY : y } = state . touchEvent || nativeEvent ;
250
+ const wasActivePressed = state . isActivePressed ;
251
+ state . isActivePressed = true ;
252
+ if ( x !== undefined && y !== undefined ) {
253
+ state . activationPosition = { x, y} ;
254
+ }
289
255
290
- if ( ! state . isActivePressStart ) {
291
- const delayPressStart = calculateDelayMS (
292
- props . delayPressStart ,
293
- 0 ,
294
- DEFAULT_PRESS_START_DELAY_MS ,
256
+ dispatchEvent (
257
+ 'onPressStart' ,
258
+ event ,
259
+ context ,
260
+ state ,
261
+ 'pressstart' ,
262
+ DiscreteEvent ,
295
263
) ;
296
- if ( delayPressStart > 0 ) {
297
- state . pressStartTimeout = context . setTimeout ( ( ) => {
298
- state . pressStartTimeout = null ;
299
- dispatch ( ) ;
300
- } , delayPressStart ) ;
301
- } else {
302
- dispatch ( ) ;
264
+ if ( ! wasActivePressed ) {
265
+ dispatchPressChangeEvent ( context , state ) ;
303
266
}
304
267
}
305
268
}
@@ -310,40 +273,20 @@ function dispatchPressEndEvents(
310
273
props : PressProps ,
311
274
state : PressState ,
312
275
) : void {
313
- const wasActivePressStart = state . isActivePressStart ;
314
- let activationWasForced = false ;
315
-
316
276
state . isActivePressStart = false ;
317
277
state . isPressed = false ;
318
278
319
- if ( ! wasActivePressStart && state . pressStartTimeout !== null ) {
320
- context . clearTimeout ( state . pressStartTimeout ) ;
321
- state . pressStartTimeout = null ;
322
- // don't activate if a press has moved beyond the responder region
323
- if ( state . isPressWithinResponderRegion && event != null ) {
324
- // if we haven't yet activated (due to delays), activate now
325
- activate ( event , context , props , state ) ;
326
- activationWasForced = true ;
327
- }
328
- }
329
-
330
279
if ( state . isActivePressed ) {
331
- const delayPressEnd = calculateDelayMS (
332
- props . delayPressEnd ,
333
- // if activation and deactivation occur during the same event there's no
334
- // time for visual user feedback therefore a small delay is added before
335
- // deactivating.
336
- activationWasForced ? 10 : 0 ,
337
- DEFAULT_PRESS_END_DELAY_MS ,
280
+ state . isActivePressed = false ;
281
+ dispatchEvent (
282
+ 'onPressEnd' ,
283
+ event ,
284
+ context ,
285
+ state ,
286
+ 'pressend' ,
287
+ DiscreteEvent ,
338
288
) ;
339
- if ( delayPressEnd > 0 ) {
340
- state . pressEndTimeout = context . setTimeout ( ( ) => {
341
- state . pressEndTimeout = null ;
342
- deactivate ( event , context , props , state ) ;
343
- } , delayPressEnd ) ;
344
- } else {
345
- deactivate ( event , context , props , state ) ;
346
- }
289
+ dispatchPressChangeEvent ( context , state ) ;
347
290
}
348
291
349
292
state . responderRegionOnDeactivation = null ;
@@ -380,11 +323,6 @@ function isValidKeyboardEvent(nativeEvent: Object): boolean {
380
323
) ;
381
324
}
382
325
383
- function calculateDelayMS ( delay : ?number , min = 0 , fallback = 0 ) {
384
- const maybeNumber = delay == null ? null : delay ;
385
- return Math . max ( min , maybeNumber != null ? maybeNumber : fallback ) ;
386
- }
387
-
388
326
// TODO: account for touch hit slop
389
327
function calculateResponderRegion (
390
328
context : ReactDOMResponderContext ,
@@ -550,7 +488,6 @@ const pressResponderImpl = {
550
488
isPressed : false ,
551
489
isPressWithinResponderRegion : true ,
552
490
pointerType : '' ,
553
- pressEndTimeout : null ,
554
491
pressStartTimeout : null ,
555
492
pressTarget : null ,
556
493
responderRegionOnActivation : null ,
0 commit comments