Skip to content

Commit b88c7c2

Browse files
committed
fix: pointer events
1 parent a3be3d7 commit b88c7c2

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

packages/react-native/React/Fabric/RCTSurfacePointerHandler.mm

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,20 @@ static PointerEvent CreatePointerEventFromActivePointer(
281281
UIView *rootComponentView)
282282
{
283283
PointerEvent event = {};
284-
#if !TARGET_OS_VISION
285284
event.pointerId = activePointer.identifier;
286285
event.pointerType = PointerTypeCStringFromUITouchType(activePointer.touchType);
287286

288287
if (eventType == RCTPointerEventTypeCancel) {
289288
event.clientPoint = RCTPointFromCGPoint(CGPointZero);
289+
#if TARGET_OS_VISION
290+
event.screenPoint =
291+
RCTPointFromCGPoint([rootComponentView convertPoint:CGPointZero
292+
toCoordinateSpace:rootComponentView.window.coordinateSpace]);
293+
#else
290294
event.screenPoint =
291295
RCTPointFromCGPoint([rootComponentView convertPoint:CGPointZero
292296
toCoordinateSpace:rootComponentView.window.screen.coordinateSpace]);
297+
#endif
293298
event.offsetPoint = RCTPointFromCGPoint([rootComponentView convertPoint:CGPointZero
294299
toView:activePointer.componentView]);
295300
} else {
@@ -330,7 +335,6 @@ static PointerEvent CreatePointerEventFromActivePointer(
330335
event.tangentialPressure = 0.0;
331336
event.twist = 0;
332337
event.isPrimary = activePointer.isPrimary;
333-
#endif
334338
return event;
335339
}
336340

@@ -370,14 +374,18 @@ static void UpdateActivePointerWithUITouch(
370374
UIEvent *uiEvent,
371375
UIView *rootComponentView)
372376
{
373-
#if !TARGET_OS_VISION
374377
CGPoint location = [uiTouch locationInView:rootComponentView];
375378
UIView *hitTestedView = [rootComponentView hitTest:location withEvent:nil];
376379
activePointer.componentView = FindClosestFabricManagedTouchableView(hitTestedView);
377380

378381
activePointer.clientPoint = [uiTouch locationInView:rootComponentView];
382+
#if TARGET_OS_VISION
383+
activePointer.screenPoint = [rootComponentView convertPoint:activePointer.clientPoint
384+
toCoordinateSpace:rootComponentView.window.coordinateSpace];
385+
#else
379386
activePointer.screenPoint = [rootComponentView convertPoint:activePointer.clientPoint
380387
toCoordinateSpace:rootComponentView.window.screen.coordinateSpace];
388+
#endif
381389
activePointer.offsetPoint = [uiTouch locationInView:activePointer.componentView];
382390

383391
activePointer.timestamp = uiTouch.timestamp;
@@ -396,7 +404,6 @@ static void UpdateActivePointerWithUITouch(
396404
activePointer.button = ButtonMaskDiffToButton(activePointer.buttonMask, nextButtonMask);
397405
activePointer.buttonMask = nextButtonMask;
398406
activePointer.modifierFlags = uiEvent.modifierFlags;
399-
#endif
400407
}
401408

402409
/**
@@ -743,12 +750,15 @@ - (void)hovering:(UIHoverGestureRecognizer *)recognizer
743750
pointerId:(int)pointerId
744751
pointerType:(std::string)pointerType API_AVAILABLE(ios(13.0))
745752
{
746-
#if !TARGET_OS_VISION
747753
UIView *listenerView = recognizer.view;
748754
CGPoint clientLocation = [recognizer locationInView:listenerView];
755+
#if TARGET_OS_VISION
756+
CGPoint screenLocation = [listenerView convertPoint:clientLocation
757+
toCoordinateSpace:listenerView.window.coordinateSpace];
758+
#else
749759
CGPoint screenLocation = [listenerView convertPoint:clientLocation
750760
toCoordinateSpace:listenerView.window.screen.coordinateSpace];
751-
761+
#endif
752762
UIView *targetView = [listenerView hitTest:clientLocation withEvent:nil];
753763
targetView = FindClosestFabricManagedTouchableView(targetView);
754764

@@ -770,7 +780,6 @@ - (void)hovering:(UIHoverGestureRecognizer *)recognizer
770780
eventEmitter->onPointerMove(event);
771781
}
772782
}
773-
#endif
774783
}
775784

776785
@end

packages/react-native/React/Fabric/RCTSurfaceTouchHandler.mm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,15 @@ static void UpdateActiveTouchWithUITouch(
5454
UIView *rootComponentView,
5555
CGPoint rootViewOriginOffset)
5656
{
57-
#if !TARGET_OS_VISION
5857
CGPoint offsetPoint = [uiTouch locationInView:activeTouch.componentView];
5958
CGPoint pagePoint = [uiTouch locationInView:rootComponentView];
59+
#if TARGET_OS_VISION
60+
CGPoint screenPoint = [rootComponentView convertPoint:pagePoint
61+
toCoordinateSpace:rootComponentView.window.coordinateSpace];
62+
#else
6063
CGPoint screenPoint = [rootComponentView convertPoint:pagePoint
6164
toCoordinateSpace:rootComponentView.window.screen.coordinateSpace];
65+
#endif
6266
pagePoint = CGPointMake(pagePoint.x + rootViewOriginOffset.x, pagePoint.y + rootViewOriginOffset.y);
6367

6468
activeTouch.touch.offsetPoint = RCTPointFromCGPoint(offsetPoint);
@@ -70,7 +74,6 @@ static void UpdateActiveTouchWithUITouch(
7074
if (RCTForceTouchAvailable()) {
7175
activeTouch.touch.force = RCTZeroIfNaN(uiTouch.force / uiTouch.maximumPossibleForce);
7276
}
73-
#endif
7477
}
7578

7679
static ActiveTouch CreateTouchWithUITouch(UITouch *uiTouch, UIView *rootComponentView, CGPoint rootViewOriginOffset)

0 commit comments

Comments
 (0)