Skip to content

Commit 48c9d32

Browse files
Saadnajmiclaude
andcommitted
fix(macOS): use transform3D in Fabric component views
Use self.transform3D instead of self.layer.transform on macOS in RCTViewComponentView, which routes through RCTUIView's persistence and anchor point compensation. Remove duplicated anchor point compensation and hitTest: override that are now handled by RCTUIView. Update hit testing callers to use the new RCTUIViewHitTestWithEvent signature with fromView parameter. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7c405e5 commit 48c9d32

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ - (RCTPlatformView *)betterHitTest:(CGPoint)point withEvent:(UIEvent *)event //
536536
}
537537

538538
for (RCTPlatformView *subview in [_containerView.subviews reverseObjectEnumerator]) { // [macOS]
539-
RCTPlatformView *hitView = RCTUIViewHitTestWithEvent(subview, [subview convertPoint:point fromView:self], event); // [macOS]
539+
RCTPlatformView *hitView = RCTUIViewHitTestWithEvent(subview, point, self, event); // [macOS]
540540
if (hitView) {
541541
return hitView;
542542
}

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -368,16 +368,10 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
368368
auto newTransform = newViewProps.resolveTransform(_layoutMetrics);
369369
CATransform3D caTransform = RCTCATransform3DFromTransformMatrix(newTransform);
370370
#if TARGET_OS_OSX // [macOS
371-
CGPoint anchorPoint = self.layer.anchorPoint;
372-
if (CGPointEqualToPoint(anchorPoint, CGPointZero) && !CATransform3DEqualToTransform(caTransform, CATransform3DIdentity)) {
373-
// https://developer.apple.com/documentation/quartzcore/calayer/1410817-anchorpoint
374-
// This compensates for the fact that layer.anchorPoint is {0, 0} instead of {0.5, 0.5} on macOS for some reason.
375-
CATransform3D originAdjust = CATransform3DTranslate(CATransform3DIdentity, self.frame.size.width / 2, self.frame.size.height / 2, 0);
376-
caTransform = CATransform3DConcat(CATransform3DConcat(CATransform3DInvert(originAdjust), caTransform), originAdjust);
377-
}
378-
#endif // macOS]
379-
371+
self.transform3D = caTransform;
372+
#else
380373
self.layer.transform = caTransform;
374+
#endif // macOS]
381375
// Enable edge antialiasing in rotation, skew, or perspective transforms
382376
self.layer.allowsEdgeAntialiasing = caTransform.m12 != 0.0f || caTransform.m21 != 0.0f || caTransform.m34 != 0.0f;
383377
}
@@ -718,7 +712,12 @@ - (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics
718712
if ((_props->transformOrigin.isSet() || _props->transform.operations.size() > 0) &&
719713
layoutMetrics.frame.size != oldLayoutMetrics.frame.size) {
720714
auto newTransform = _props->resolveTransform(layoutMetrics);
721-
self.layer.transform = RCTCATransform3DFromTransformMatrix(newTransform);
715+
CATransform3D caTransform = RCTCATransform3DFromTransformMatrix(newTransform);
716+
#if TARGET_OS_OSX // [macOS
717+
self.transform3D = caTransform;
718+
#else
719+
self.layer.transform = caTransform;
720+
#endif // macOS]
722721
}
723722
}
724723

@@ -812,7 +811,7 @@ - (RCTPlatformView *)betterHitTest:(CGPoint)point withEvent:(UIEvent *)event //
812811
}
813812

814813
for (RCTPlatformView *subview in [self.subviews reverseObjectEnumerator]) { // [macOS]
815-
RCTPlatformView *hitView = RCTUIViewHitTestWithEvent(subview, [subview convertPoint:point fromView:self], event); // [macOS]
814+
RCTPlatformView *hitView = RCTUIViewHitTestWithEvent(subview, point, self, event); // [macOS]
816815
if (hitView) {
817816
return hitView;
818817
}

0 commit comments

Comments
 (0)