forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRNNReactTitleView.m
44 lines (37 loc) · 1.24 KB
/
RNNReactTitleView.m
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
#import "RNNReactTitleView.h"
@implementation RNNReactTitleView {
BOOL _fillParent;
}
- (NSString *)componentType {
return ComponentTypeTitle;
}
- (CGSize)intrinsicContentSize {
if (_fillParent) {
return UILayoutFittingExpandedSize;
} else {
return [super intrinsicContentSize];
}
}
- (void)setAlignment:(NSString *)alignment inFrame:(CGRect)frame {
if ([alignment isEqualToString:@"fill"]) {
_fillParent = YES;
self.frame = frame;
self.sizeFlexibility = RCTRootViewSizeFlexibilityNone;
} else {
self.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
__weak RNNReactView *weakSelf = self;
[self setRootViewDidChangeIntrinsicSize:^(CGSize intrinsicSize) {
[weakSelf setFrame:CGRectMake(0, 0, intrinsicSize.width, intrinsicSize.height)];
}];
}
}
- (void)setRootViewDidChangeIntrinsicSize:(void (^)(CGSize))rootViewDidChangeIntrinsicSize {
_rootViewDidChangeIntrinsicSize = rootViewDidChangeIntrinsicSize;
self.delegate = self;
}
- (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
if (_rootViewDidChangeIntrinsicSize) {
_rootViewDidChangeIntrinsicSize(rootView.intrinsicContentSize);
}
}
@end