@@ -210,6 +210,10 @@ - (UIBarButtonItem *)getUIBarButtonItem
210210{
211211 if (_barButtonItem == nil ) {
212212#if RNS_IPHONE_OS_VERSION_AVAILABLE(26_0)
213+ // Starting from iOS 26, UIBarButtonItem's customView is streched to have at least 36 width.
214+ // Stretching RNSScreenStackHeaderSubview means that its subviews are aligned to left instead
215+ // of the center. To mitigate this, we add a wrapper view that will center
216+ // RNSScreenStackHeaderSubview inside of itself.
213217 UIView *wrapperView = [UIView new ];
214218 wrapperView.translatesAutoresizingMaskIntoConstraints = NO ;
215219
@@ -219,6 +223,10 @@ - (UIBarButtonItem *)getUIBarButtonItem
219223 [self .centerXAnchor constraintEqualToAnchor: wrapperView.centerXAnchor].active = YES ;
220224 [self .centerYAnchor constraintEqualToAnchor: wrapperView.centerYAnchor].active = YES ;
221225
226+ // To prevent UIKit from stretching subviews to all available width, we need to:
227+ // 1. Set width of wrapperView to match RNSScreenStackHeaderSubview BUT when
228+ // RNSScreenStackHeaderSubview's width is smaller that minimal required 36 width, it breaks
229+ // UIKit's constraint. That's why we need to lower the priority of the constraint.
222230 NSLayoutConstraint *widthEqual = [wrapperView.widthAnchor constraintEqualToAnchor: self .widthAnchor];
223231 widthEqual.priority = UILayoutPriorityDefaultHigh;
224232 widthEqual.active = YES ;
@@ -227,6 +235,7 @@ - (UIBarButtonItem *)getUIBarButtonItem
227235 heightEqual.priority = UILayoutPriorityDefaultHigh;
228236 heightEqual.active = YES ;
229237
238+ // 2. Set content hugging prriority for RNSScreenStackHeaderSubview.
230239 [self setContentHuggingPriority: UILayoutPriorityRequired forAxis: UILayoutConstraintAxisHorizontal];
231240 [self setContentHuggingPriority: UILayoutPriorityRequired forAxis: UILayoutConstraintAxisVertical];
232241
0 commit comments