Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions packages/react-native/React/Fabric/RCTSurfacePointerHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,20 @@ static PointerEvent CreatePointerEventFromActivePointer(
UIView *rootComponentView)
{
PointerEvent event = {};
#if !TARGET_OS_VISION
event.pointerId = activePointer.identifier;
event.pointerType = PointerTypeCStringFromUITouchType(activePointer.touchType);

if (eventType == RCTPointerEventTypeCancel) {
event.clientPoint = RCTPointFromCGPoint(CGPointZero);
#if TARGET_OS_VISION
event.screenPoint =
RCTPointFromCGPoint([rootComponentView convertPoint:CGPointZero
toCoordinateSpace:rootComponentView.window.coordinateSpace]);
#else
event.screenPoint =
RCTPointFromCGPoint([rootComponentView convertPoint:CGPointZero
toCoordinateSpace:rootComponentView.window.screen.coordinateSpace]);
#endif
event.offsetPoint = RCTPointFromCGPoint([rootComponentView convertPoint:CGPointZero
toView:activePointer.componentView]);
} else {
Expand Down Expand Up @@ -330,7 +335,6 @@ static PointerEvent CreatePointerEventFromActivePointer(
event.tangentialPressure = 0.0;
event.twist = 0;
event.isPrimary = activePointer.isPrimary;
#endif
return event;
}

Expand Down Expand Up @@ -370,14 +374,18 @@ static void UpdateActivePointerWithUITouch(
UIEvent *uiEvent,
UIView *rootComponentView)
{
#if !TARGET_OS_VISION
CGPoint location = [uiTouch locationInView:rootComponentView];
UIView *hitTestedView = [rootComponentView hitTest:location withEvent:nil];
activePointer.componentView = FindClosestFabricManagedTouchableView(hitTestedView);

activePointer.clientPoint = [uiTouch locationInView:rootComponentView];
#if TARGET_OS_VISION
activePointer.screenPoint = [rootComponentView convertPoint:activePointer.clientPoint
toCoordinateSpace:rootComponentView.window.coordinateSpace];
#else
activePointer.screenPoint = [rootComponentView convertPoint:activePointer.clientPoint
toCoordinateSpace:rootComponentView.window.screen.coordinateSpace];
#endif
activePointer.offsetPoint = [uiTouch locationInView:activePointer.componentView];

activePointer.timestamp = uiTouch.timestamp;
Expand All @@ -396,7 +404,6 @@ static void UpdateActivePointerWithUITouch(
activePointer.button = ButtonMaskDiffToButton(activePointer.buttonMask, nextButtonMask);
activePointer.buttonMask = nextButtonMask;
activePointer.modifierFlags = uiEvent.modifierFlags;
#endif
}

/**
Expand Down Expand Up @@ -743,12 +750,15 @@ - (void)hovering:(UIHoverGestureRecognizer *)recognizer
pointerId:(int)pointerId
pointerType:(std::string)pointerType API_AVAILABLE(ios(13.0))
{
#if !TARGET_OS_VISION
UIView *listenerView = recognizer.view;
CGPoint clientLocation = [recognizer locationInView:listenerView];
#if TARGET_OS_VISION
CGPoint screenLocation = [listenerView convertPoint:clientLocation
toCoordinateSpace:listenerView.window.coordinateSpace];
#else
CGPoint screenLocation = [listenerView convertPoint:clientLocation
toCoordinateSpace:listenerView.window.screen.coordinateSpace];

#endif
UIView *targetView = [listenerView hitTest:clientLocation withEvent:nil];
targetView = FindClosestFabricManagedTouchableView(targetView);

Expand All @@ -770,7 +780,6 @@ - (void)hovering:(UIHoverGestureRecognizer *)recognizer
eventEmitter->onPointerMove(event);
}
}
#endif
}

@end
7 changes: 5 additions & 2 deletions packages/react-native/React/Fabric/RCTSurfaceTouchHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ static void UpdateActiveTouchWithUITouch(
UIView *rootComponentView,
CGPoint rootViewOriginOffset)
{
#if !TARGET_OS_VISION
CGPoint offsetPoint = [uiTouch locationInView:activeTouch.componentView];
CGPoint pagePoint = [uiTouch locationInView:rootComponentView];
#if TARGET_OS_VISION
CGPoint screenPoint = [rootComponentView convertPoint:pagePoint
toCoordinateSpace:rootComponentView.window.coordinateSpace];
#else
CGPoint screenPoint = [rootComponentView convertPoint:pagePoint
toCoordinateSpace:rootComponentView.window.screen.coordinateSpace];
#endif
pagePoint = CGPointMake(pagePoint.x + rootViewOriginOffset.x, pagePoint.y + rootViewOriginOffset.y);

activeTouch.touch.offsetPoint = RCTPointFromCGPoint(offsetPoint);
Expand All @@ -70,7 +74,6 @@ static void UpdateActiveTouchWithUITouch(
if (RCTForceTouchAvailable()) {
activeTouch.touch.force = RCTZeroIfNaN(uiTouch.force / uiTouch.maximumPossibleForce);
}
#endif
}

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