11#import " RNNReactTitleView.h"
22
3+ static const CGFloat kTitleViewDefaultHeight = 44.0 ;
4+
35@implementation RNNReactTitleView {
46 BOOL _fillParent;
57 CGFloat _expectedHeight;
@@ -11,19 +13,30 @@ - (NSString *)componentType {
1113
1214- (CGSize)intrinsicContentSize {
1315 if (_fillParent) {
14- return CGSizeMake (UILayoutFittingExpandedSize.width , _expectedHeight > 0 ? _expectedHeight : 44 );
15- } else {
16- return [super intrinsicContentSize ];
16+ return CGSizeMake (UILayoutFittingExpandedSize.width ,
17+ _expectedHeight > 0 ? _expectedHeight : kTitleViewDefaultHeight );
1718 }
19+ return [super intrinsicContentSize ];
20+ }
21+
22+ - (CGSize)sizeThatFits : (CGSize)size {
23+ if (_fillParent) {
24+ return size;
25+ }
26+ return [super sizeThatFits: size];
1827}
1928
2029- (void )setAlignment : (NSString *)alignment inFrame : (CGRect)frame {
2130 if ([alignment isEqualToString: @" fill" ]) {
2231 _fillParent = YES ;
23- _expectedHeight = frame.size .height ;
24- self.translatesAutoresizingMaskIntoConstraints = NO ;
32+ _expectedHeight = frame.size .height > 0 ? frame.size .height : kTitleViewDefaultHeight ;
33+ self.frame = frame;
34+ self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin |
35+ UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
2536 self.sizeFlexibility = RCTRootViewSizeFlexibilityNone;
2637 } else {
38+ _fillParent = NO ;
39+ self.autoresizingMask = UIViewAutoresizingNone;
2740 self.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
2841 __weak RNNReactView *weakSelf = self;
2942 [self setRootViewDidChangeIntrinsicSize: ^(CGSize intrinsicSize) {
@@ -32,6 +45,14 @@ - (void)setAlignment:(NSString *)alignment inFrame:(CGRect)frame {
3245 }
3346}
3447
48+ - (void )layoutSubviews {
49+ [super layoutSubviews ];
50+ if (_fillParent && self.bounds .size .height > 0 && _expectedHeight != self.bounds .size .height ) {
51+ _expectedHeight = self.bounds .size .height ;
52+ [self invalidateIntrinsicContentSize ];
53+ }
54+ }
55+
3556- (void )setRootViewDidChangeIntrinsicSize : (void (^)(CGSize))rootViewDidChangeIntrinsicSize {
3657 _rootViewDidChangeIntrinsicSize = rootViewDidChangeIntrinsicSize;
3758 self.delegate = self;
0 commit comments