Skip to content

Commit

Permalink
fixed custom top bar alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
yogevbd committed Mar 4, 2018
1 parent d240378 commit 0294405
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
14 changes: 13 additions & 1 deletion ios/RCCCustomTitleView.m
Expand Up @@ -29,9 +29,10 @@ - (instancetype)initWithFrame:(CGRect)frame subView:(RCTRootView*)subView alignm

if ([alignment isEqualToString:@"fill"]) {
self.frame = frame;
self.subView.frame = self.frame;
subView.sizeFlexibility = RCTRootViewSizeFlexibilityNone;
} else {
self.subView.delegate = self;
subView.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
}

[self addSubview:subView];
Expand All @@ -40,6 +41,17 @@ - (instancetype)initWithFrame:(CGRect)frame subView:(RCTRootView*)subView alignm
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(0, 0, rootView.intrinsicContentSize.width, rootView.intrinsicContentSize.height)];
Expand Down
5 changes: 2 additions & 3 deletions ios/RCCViewController.m
Expand Up @@ -642,12 +642,11 @@ -(void)setStyleOnAppearForViewController:(UIViewController*)viewController appea

NSDictionary *initialProps = self.navigatorStyle[@"navBarCustomViewInitialProps"];
RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:bridge moduleName:navBarCustomView initialProperties:initialProps];
reactView.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;


RCCCustomTitleView *titleView = [[RCCCustomTitleView alloc] initWithFrame:self.navigationController.navigationBar.bounds
subView:reactView
alignment:self.navigatorStyle[@"navBarComponentAlignment"]];

self.navigationItem.titleView = titleView;
self.navigationItem.titleView.backgroundColor = [UIColor clearColor];
self.navigationItem.titleView.clipsToBounds = YES;
Expand Down

0 comments on commit 0294405

Please sign in to comment.