Skip to content

Commit a124647

Browse files
Saadnajmiclaude
andcommitted
Fix macOS transform anchor point compensation in updateLayoutMetrics
The updateLayoutMetrics code path re-applies the transform when the view size changes, but was missing the macOS anchor point compensation that adjusts for CALayer.anchorPoint being {0,0} instead of {0.5,0.5}. This caused the correctly compensated transform from updateProps to be overwritten with an uncompensated one on every layout change. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2a222b2 commit a124647

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,16 @@ - (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics
718718
if ((_props->transformOrigin.isSet() || _props->transform.operations.size() > 0) &&
719719
layoutMetrics.frame.size != oldLayoutMetrics.frame.size) {
720720
auto newTransform = _props->resolveTransform(layoutMetrics);
721-
self.layer.transform = RCTCATransform3DFromTransformMatrix(newTransform);
721+
CATransform3D caTransform = RCTCATransform3DFromTransformMatrix(newTransform);
722+
#if TARGET_OS_OSX // [macOS
723+
CGPoint anchorPoint = self.layer.anchorPoint;
724+
if (CGPointEqualToPoint(anchorPoint, CGPointZero) && !CATransform3DEqualToTransform(caTransform, CATransform3DIdentity)) {
725+
// This compensates for the fact that layer.anchorPoint is {0, 0} instead of {0.5, 0.5} on macOS for some reason.
726+
CATransform3D originAdjust = CATransform3DTranslate(CATransform3DIdentity, self.frame.size.width / 2, self.frame.size.height / 2, 0);
727+
caTransform = CATransform3DConcat(CATransform3DConcat(CATransform3DInvert(originAdjust), caTransform), originAdjust);
728+
}
729+
#endif // macOS]
730+
self.layer.transform = caTransform;
722731
}
723732
}
724733

0 commit comments

Comments
 (0)