From fd43bcc8c42961d17b65f7fe6a1f9421d47f40a8 Mon Sep 17 00:00:00 2001 From: Isaac Israel Date: Wed, 13 May 2026 18:44:02 +0300 Subject: [PATCH] fix(ios): add Auto Layout constraints to RNNReactButtonView on iOS 26 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On iOS 26 the Liquid Glass navigation bar wraps custom-view bar button items in several internal layout containers. Without explicit size constraints the wrapper views can collapse to zero height after a pop → tab-switch → tab-switch → push cycle, making the React button invisible. - Guard all new logic behind @available(iOS 26.0, *) AND a runtime check for UIDesignRequiresCompatibility (compatibility mode disables Liquid Glass and uses the legacy view hierarchy) - Set translatesAutoresizingMaskIntoConstraints = NO - Add width/height constraints at UILayoutPriorityDefaultHigh - Update constraints in didMountComponentsWithRootTag: after sizeToFit Co-authored-by: Cursor --- ios/RNNReactButtonView.mm | 43 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/ios/RNNReactButtonView.mm b/ios/RNNReactButtonView.mm index 607d91286bf..1da4c2735b4 100644 --- a/ios/RNNReactButtonView.mm +++ b/ios/RNNReactButtonView.mm @@ -1,6 +1,10 @@ #import "RNNReactButtonView.h" +#import -@implementation RNNReactButtonView +@implementation RNNReactButtonView { + NSLayoutConstraint *_widthConstraint; + NSLayoutConstraint *_heightConstraint; +} - (instancetype)initWithHost:(RCTHost *)host moduleName:(NSString *)moduleName @@ -10,15 +14,50 @@ - (instancetype)initWithHost:(RCTHost *)host reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock { self = [super initWithHost:host moduleName:moduleName initialProperties:initialProperties eventEmitter:eventEmitter sizeMeasureMode:convertToSurfaceSizeMeasureMode(RCTRootViewSizeFlexibilityWidthAndHeight) reactViewReadyBlock:reactViewReadyBlock]; [host.surfacePresenter addObserver:self]; - self.backgroundColor = UIColor.clearColor; + self.backgroundColor = [UIColor clearColor]; + + if (@available(iOS 26.0, *)) { + if (![self designRequiresCompatibility]) { + self.translatesAutoresizingMaskIntoConstraints = NO; + _widthConstraint = [self.widthAnchor constraintEqualToConstant:0]; + _heightConstraint = [self.heightAnchor constraintEqualToConstant:0]; + _widthConstraint.priority = UILayoutPriorityDefaultHigh; + _heightConstraint.priority = UILayoutPriorityDefaultHigh; + _widthConstraint.active = YES; + _heightConstraint.active = YES; + } + } return self; } +- (BOOL)designRequiresCompatibility { + static BOOL checked = NO; + static BOOL result = NO; + if (!checked) { + checked = YES; + result = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIDesignRequiresCompatibility"] boolValue]; + } + return result; +} + - (void)didMountComponentsWithRootTag:(NSInteger)rootTag { if (self.surface.rootTag == rootTag) { [super didMountComponentsWithRootTag:rootTag]; [self sizeToFit]; + if (@available(iOS 26.0, *)) { + if (![self designRequiresCompatibility]) { + [self updateConstraintsToFitSize]; + } + } + } +} + +- (void)updateConstraintsToFitSize { + CGSize size = self.frame.size; + if (size.width > 0 && size.height > 0) { + _widthConstraint.constant = size.width; + _heightConstraint.constant = size.height; } }