forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRNNReactButtonView.mm
More file actions
68 lines (59 loc) · 2.36 KB
/
RNNReactButtonView.mm
File metadata and controls
68 lines (59 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#import "RNNReactButtonView.h"
#import <React/RCTSurface.h>
@implementation RNNReactButtonView {
NSLayoutConstraint *_widthConstraint;
NSLayoutConstraint *_heightConstraint;
}
- (instancetype)initWithHost:(RCTHost *)host
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
eventEmitter:(RNNEventEmitter *)eventEmitter
sizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode
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];
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;
}
}
- (NSString *)componentType {
return ComponentTypeButton;
}
@end