@@ -374,18 +374,17 @@ static PointerEvent CreatePointerEventFromActiveTouch(ActiveTouch activeTouch, R
374
374
}
375
375
376
376
static PointerEvent CreatePointerEventFromIncompleteHoverData (
377
+ int pointerId,
378
+ std::string pointerType,
377
379
CGPoint clientLocation,
378
380
CGPoint screenLocation,
379
381
CGPoint offsetLocation,
380
382
UIKeyModifierFlags modifierFlags)
381
383
{
382
384
PointerEvent event = {};
383
- // "touch" events produced from a mouse cursor on iOS always have the ID 0 so
384
- // we can just assume that here since these sort of hover events only ever come
385
- // from the mouse
386
- event.pointerId = kMousePointerId ;
385
+ event.pointerId = pointerId;
387
386
event.pressure = 0.0 ;
388
- event.pointerType = " mouse " ;
387
+ event.pointerType = pointerType ;
389
388
event.clientPoint = RCTPointFromCGPoint (clientLocation);
390
389
event.screenPoint = RCTPointFromCGPoint (screenLocation);
391
390
event.offsetPoint = RCTPointFromCGPoint (offsetLocation);
@@ -473,7 +472,9 @@ @implementation RCTSurfaceTouchHandler {
473
472
__weak UIView *_rootComponentView;
474
473
IdentifierPool<11 > _identifierPool;
475
474
476
- UIHoverGestureRecognizer *_hoverRecognizer API_AVAILABLE (ios (13.0 ));
475
+ UIHoverGestureRecognizer *_mouseHoverRecognizer API_AVAILABLE (ios (13.0 ));
476
+ UIHoverGestureRecognizer *_penHoverRecognizer API_AVAILABLE (ios (13.0 ));
477
+
477
478
NSMutableDictionary <NSNumber *, NSOrderedSet <RCTReactTaggedView *> *> *_currentlyHoveredViewsPerPointer;
478
479
479
480
int _primaryTouchPointerId;
@@ -492,7 +493,9 @@ - (instancetype)init
492
493
493
494
self.delegate = self;
494
495
495
- _hoverRecognizer = nil ;
496
+ _mouseHoverRecognizer = nil ;
497
+ _penHoverRecognizer = nil ;
498
+
496
499
_currentlyHoveredViewsPerPointer = [[NSMutableDictionary alloc ] init ];
497
500
_primaryTouchPointerId = -1 ;
498
501
}
@@ -510,9 +513,14 @@ - (void)attachToView:(UIView *)view
510
513
_rootComponentView = view;
511
514
512
515
if (RCTGetDispatchW3CPointerEvents ()) {
513
- if (@available (iOS 13.0 , *)) {
514
- _hoverRecognizer = [[UIHoverGestureRecognizer alloc ] initWithTarget: self action: @selector (hovering: )];
515
- [view addGestureRecognizer: _hoverRecognizer];
516
+ if (@available (iOS 13.4 , *)) {
517
+ _mouseHoverRecognizer = [[UIHoverGestureRecognizer alloc ] initWithTarget: self action: @selector (mouseHovering: )];
518
+ _mouseHoverRecognizer.allowedTouchTypes = @[ @(UITouchTypeIndirectPointer) ];
519
+ [view addGestureRecognizer: _mouseHoverRecognizer];
520
+
521
+ _penHoverRecognizer = [[UIHoverGestureRecognizer alloc ] initWithTarget: self action: @selector (penHovering: )];
522
+ _penHoverRecognizer.allowedTouchTypes = @[ @(UITouchTypePencil) ];
523
+ [view addGestureRecognizer: _penHoverRecognizer];
516
524
}
517
525
}
518
526
}
@@ -525,9 +533,14 @@ - (void)detachFromView:(UIView *)view
525
533
[view removeGestureRecognizer: self ];
526
534
_rootComponentView = nil ;
527
535
528
- if (_hoverRecognizer != nil ) {
529
- [view removeGestureRecognizer: _hoverRecognizer];
530
- _hoverRecognizer = nil ;
536
+ if (_mouseHoverRecognizer != nil ) {
537
+ [view removeGestureRecognizer: _mouseHoverRecognizer];
538
+ _mouseHoverRecognizer = nil ;
539
+ }
540
+
541
+ if (_penHoverRecognizer != nil ) {
542
+ [view removeGestureRecognizer: _penHoverRecognizer];
543
+ _penHoverRecognizer = nil ;
531
544
}
532
545
}
533
546
@@ -845,7 +858,19 @@ - (void)_cancelTouches
845
858
[self setEnabled: YES ];
846
859
}
847
860
848
- - (void )hovering : (UIHoverGestureRecognizer *)recognizer API_AVAILABLE(ios(13.0 ))
861
+ - (void )penHovering : (UIHoverGestureRecognizer *)recognizer API_AVAILABLE(ios(13.0 ))
862
+ {
863
+ [self hovering: recognizer pointerId: kPencilPointerId pointerType: " pen" ];
864
+ }
865
+
866
+ - (void )mouseHovering : (UIHoverGestureRecognizer *)recognizer API_AVAILABLE(ios(13.0 ))
867
+ {
868
+ [self hovering: recognizer pointerId: kMousePointerId pointerType: " mouse" ];
869
+ }
870
+
871
+ - (void )hovering : (UIHoverGestureRecognizer *)recognizer
872
+ pointerId : (int )pointerId
873
+ pointerType : (std::string)pointerType API_AVAILABLE(ios(13.0 ))
849
874
{
850
875
UIView *listenerView = recognizer.view ;
851
876
CGPoint clientLocation = [recognizer locationInView: listenerView];
@@ -864,8 +889,8 @@ - (void)hovering:(UIHoverGestureRecognizer *)recognizer API_AVAILABLE(ios(13.0))
864
889
modifierFlags = 0 ;
865
890
}
866
891
867
- PointerEvent event =
868
- CreatePointerEventFromIncompleteHoverData ( clientLocation, screenLocation, offsetLocation, modifierFlags);
892
+ PointerEvent event = CreatePointerEventFromIncompleteHoverData (
893
+ pointerId, pointerType, clientLocation, screenLocation, offsetLocation, modifierFlags);
869
894
870
895
NSOrderedSet <RCTReactTaggedView *> *eventPathViews = [self handleIncomingPointerEvent: event onView: targetView];
871
896
SharedTouchEventEmitter eventEmitter = GetTouchEmitterFromView (targetView, offsetLocation);
0 commit comments