1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #import "RNNCustomTitleView.h"
-
- @interface RNNCustomTitleView ()
-
- @property (nonatomic, strong) RCTRootView *subView;
- @property (nonatomic, strong) NSString *alignment;
-
- @end
-
- @implementation RNNCustomTitleView
-
- - (instancetype)initWithFrame:(CGRect)frame subView:(RCTRootView*)subView alignment:(NSString*)alignment {
- self = [super init];
-
- if (self) {
- self.subView = subView;
- self.alignment = alignment;
-
- self.backgroundColor = [UIColor clearColor];
- self.subView.backgroundColor = [UIColor clearColor];
-
- if ([alignment isEqualToString:@"fill"]) {
- self.frame = frame;
- subView.sizeFlexibility = RCTRootViewSizeFlexibilityNone;
- } else {
- self.subView.delegate = self;
- subView.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
- }
-
- [self addSubview:subView];
- }
-
- return self;
- }
-
- - (void)layoutSubviews {
- [super layoutSubviews];
- if ([self.alignment isEqualToString:@"fill"]) {
- [self.subView setFrame:self.bounds];
- }
- }
-
- - (NSString *)alignment {
- return _alignment ? _alignment : @"center";
- }
-
- - (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
- if ([self.alignment isEqualToString:@"center"]) {
- [self setFrame:CGRectMake(self.frame.origin.x, self.frame.origin.y, self.subView.intrinsicContentSize.width, self.subView.intrinsicContentSize.height)];
- [self.subView setFrame:CGRectMake(0, 0, rootView.intrinsicContentSize.width, rootView.intrinsicContentSize.height)];
- }
- }
-
- @end
-
|