Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions ios/RNNReactButtonView.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#import "RNNReactButtonView.h"
#import <React/RCTSurface.h>

@implementation RNNReactButtonView
@implementation RNNReactButtonView {
NSLayoutConstraint *_widthConstraint;
NSLayoutConstraint *_heightConstraint;
BOOL _didCenter;
}

- (instancetype)initWithHost:(RCTHost *)host
moduleName:(NSString *)moduleName
Expand All @@ -10,15 +15,67 @@ - (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;
_didCenter = NO;
}
}

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;
}
}

- (void)layoutSubviews {
[super layoutSubviews];
if (@available(iOS 26.0, *)) {
if ([self designRequiresCompatibility]) return;
if (!_didCenter && self.superview && self.frame.size.width > 0) {
CGFloat wrapperWidth = self.superview.bounds.size.width;
CGFloat selfWidth = self.frame.size.width;
if (wrapperWidth > selfWidth) {
_didCenter = YES;
CGFloat tx = (wrapperWidth - selfWidth) / 2.0;
self.layer.affineTransform = CGAffineTransformMakeTranslation(tx, 0);
}
}
}
}

Expand Down