123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #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
|