Skip to content

Commit db70f4c

Browse files
fix(ios): center RNNReactButtonView inside navigation bar platter
On iOS 26 the internal _UITAMICAdaptorView wrapper is wider than the React button content and UIKit pins the custom view to the leading edge. Apply a one-time horizontal CGAffineTransform in layoutSubviews to center the view. Guarded by @available(iOS 26.0, *) and UIDesignRequiresCompatibility check. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent fd43bcc commit db70f4c

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

ios/RNNReactButtonView.mm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@implementation RNNReactButtonView {
55
NSLayoutConstraint *_widthConstraint;
66
NSLayoutConstraint *_heightConstraint;
7+
BOOL _didCenter;
78
}
89

910
- (instancetype)initWithHost:(RCTHost *)host
@@ -25,6 +26,7 @@ - (instancetype)initWithHost:(RCTHost *)host
2526
_heightConstraint.priority = UILayoutPriorityDefaultHigh;
2627
_widthConstraint.active = YES;
2728
_heightConstraint.active = YES;
29+
_didCenter = NO;
2830
}
2931
}
3032

@@ -61,6 +63,22 @@ - (void)updateConstraintsToFitSize {
6163
}
6264
}
6365

66+
- (void)layoutSubviews {
67+
[super layoutSubviews];
68+
if (@available(iOS 26.0, *)) {
69+
if ([self designRequiresCompatibility]) return;
70+
if (!_didCenter && self.superview && self.frame.size.width > 0) {
71+
CGFloat wrapperWidth = self.superview.bounds.size.width;
72+
CGFloat selfWidth = self.frame.size.width;
73+
if (wrapperWidth > selfWidth) {
74+
_didCenter = YES;
75+
CGFloat tx = (wrapperWidth - selfWidth) / 2.0;
76+
self.layer.affineTransform = CGAffineTransformMakeTranslation(tx, 0);
77+
}
78+
}
79+
}
80+
}
81+
6482
- (NSString *)componentType {
6583
return ComponentTypeButton;
6684
}

0 commit comments

Comments
 (0)