@@ -426,7 +426,8 @@ const PressResponder = {
426
426
props : PressProps ,
427
427
state : PressState ,
428
428
) : void {
429
- const { target , type , nativeEvent } = event ;
429
+ const { target , type } = event ;
430
+ const nativeEvent : any = event . nativeEvent ;
430
431
431
432
switch ( type ) {
432
433
/**
@@ -442,21 +443,23 @@ const PressResponder = {
442
443
const pointerType = getPointerType ( nativeEvent ) ;
443
444
state . pointerType = pointerType ;
444
445
445
- if ( pointerType === 'mouse' || type === 'mousedown' ) {
446
- if (
447
- // Ignore right- and middle-clicks
448
- nativeEvent . button === 1 ||
449
- nativeEvent . button === 2 ||
450
- // Ignore pressing on hit slop area with mouse
451
- context . isPositionWithinTouchHitTarget (
452
- target . ownerDocument ,
453
- ( nativeEvent : any ) . x ,
454
- ( nativeEvent : any ) . y ,
455
- )
456
- ) {
457
- return ;
458
- }
446
+ // Ignore any device buttons except left-mouse and touch/pen contact
447
+ if ( nativeEvent . button > 0 ) {
448
+ return ;
449
+ }
450
+
451
+ // Ignore pressing on hit slop area with mouse
452
+ if (
453
+ ( pointerType === 'mouse' || type === 'mousedown' ) &&
454
+ context . isPositionWithinTouchHitTarget (
455
+ target . ownerDocument ,
456
+ nativeEvent . x ,
457
+ nativeEvent . y ,
458
+ )
459
+ ) {
460
+ return ;
459
461
}
462
+
460
463
state . pressTarget = target ;
461
464
state . isPressWithinResponderRegion = true ;
462
465
dispatchPressStartEvents ( context , props , state ) ;
@@ -574,7 +577,7 @@ const PressResponder = {
574
577
575
578
if ( type !== 'touchcancel' && props . onPress ) {
576
579
// Find if the X/Y of the end touch is still that of the original target
577
- const changedTouch = ( nativeEvent : any ) . changedTouches [ 0 ] ;
580
+ const changedTouch = nativeEvent . changedTouches [ 0 ] ;
578
581
const doc = ( target : any ) . ownerDocument ;
579
582
const fromTarget = doc . elementFromPoint (
580
583
changedTouch . screenX ,
@@ -607,14 +610,11 @@ const PressResponder = {
607
610
*/
608
611
case 'keydown' :
609
612
case 'keypress ': {
610
- if (
611
- ! context . hasOwnership ( ) &&
612
- isValidKeyPress ( ( nativeEvent : any ) . key )
613
- ) {
613
+ if ( ! context . hasOwnership ( ) && isValidKeyPress ( nativeEvent . key ) ) {
614
614
if ( state . isPressed ) {
615
615
// Prevent spacebar press from scrolling the window
616
- if ( ( nativeEvent : any ) . key === ' ' ) {
617
- ( nativeEvent : any ) . preventDefault ( ) ;
616
+ if ( nativeEvent . key === ' ' ) {
617
+ nativeEvent . preventDefault ( ) ;
618
618
}
619
619
} else {
620
620
const pointerType = getPointerType ( nativeEvent ) ;
@@ -627,7 +627,7 @@ const PressResponder = {
627
627
break ;
628
628
}
629
629
case 'keyup' : {
630
- if ( state . isPressed && isValidKeyPress ( ( nativeEvent : any ) . key ) ) {
630
+ if ( state . isPressed && isValidKeyPress ( nativeEvent . key ) ) {
631
631
const wasLongPressed = state . isLongPressed ;
632
632
dispatchPressEndEvents ( context , props , state ) ;
633
633
if ( state . pressTarget !== null && props . onPress ) {
@@ -659,11 +659,11 @@ const PressResponder = {
659
659
660
660
case 'click' : {
661
661
if ( isAnchorTagElement ( target ) ) {
662
- const { ctrlKey , metaKey , shiftKey } = ( ( nativeEvent : any ) : MouseEvent ) ;
662
+ const { ctrlKey , metaKey , shiftKey } = ( nativeEvent : MouseEvent ) ;
663
663
// Check "open in new window/tab" and "open context menu" key modifiers
664
664
const preventDefault = props . preventDefault ;
665
665
if ( preventDefault !== false && ! shiftKey && ! metaKey && ! ctrlKey ) {
666
- ( nativeEvent : any ) . preventDefault ( ) ;
666
+ nativeEvent . preventDefault ( ) ;
667
667
}
668
668
}
669
669
break ;
@@ -672,7 +672,7 @@ const PressResponder = {
672
672
case 'contextmenu ': {
673
673
if ( state . isPressed ) {
674
674
if ( props . preventDefault !== false ) {
675
- ( nativeEvent : any ) . preventDefault ( ) ;
675
+ nativeEvent . preventDefault ( ) ;
676
676
} else {
677
677
state . shouldSkipMouseAfterTouch = false ;
678
678
dispatchPressEndEvents ( context , props , state ) ;
0 commit comments