diff --git a/ios/RNNReactButtonView.mm b/ios/RNNReactButtonView.mm index 607d91286b..1da4c2735b 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; } }