Skip to content

Commit

Permalink
Fix topBar title alignment on iOS (#5602)
Browse files Browse the repository at this point in the history
Fix topBar title alignment
  • Loading branch information
yogevbd authored and guyca committed Oct 24, 2019
1 parent 0dd3315 commit 094b9a7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
21 changes: 5 additions & 16 deletions lib/ios/RNNComponentPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ - (void)applyOptions:(RNNNavigationOptions *)options {
[viewController setStatusBarStyle:[withDefault.statusBar.style getWithDefaultValue:@"default"] animated:[withDefault.statusBar.animate getWithDefaultValue:YES]];
[viewController setBackButtonVisible:[withDefault.topBar.backButton.visible getWithDefaultValue:YES]];
[viewController setInterceptTouchOutside:[withDefault.overlay.interceptTouchOutside getWithDefaultValue:YES]];

if (withDefault.layout.backgroundColor.hasValue) {
[viewController setBackgroundColor:withDefault.layout.backgroundColor.get];
}

if (withDefault.topBar.searchBar.hasValue) {
BOOL hideNavBarOnFocusSearchBar = YES;
if (withDefault.topBar.hideNavBarOnFocusSearchBar.hasValue) {
hideNavBarOnFocusSearchBar = withDefault.topBar.hideNavBarOnFocusSearchBar.get;
}
[viewController setSearchBarWithPlaceholder:[withDefault.topBar.searchBarPlaceholder getWithDefaultValue:@""] hideNavBarOnFocusSearchBar:hideNavBarOnFocusSearchBar];
}

[self setTitleViewWithSubtitle:withDefault];
}

Expand Down Expand Up @@ -153,15 +153,15 @@ - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigat
rootView.passThroughTouches = !options.overlay.interceptTouchOutside.get;
}

[self setTitleViewWithSubtitle:withDefault];

if (options.topBar.title.component.name.hasValue) {
[self setCustomNavigationTitleView:options perform:nil];
} else {
[_customTitleView removeFromSuperview];
_customTitleView = nil;
}

[self setTitleViewWithSubtitle:withDefault];

if (options.topBar.backButton.hasValue) {
UIViewController *lastViewControllerInStack = viewController.navigationController.viewControllers.count > 1 ? viewController.navigationController.viewControllers[viewController.navigationController.viewControllers.count - 2] : viewController.navigationController.topViewController;
RNNNavigationOptions * resolvedOptions = (RNNNavigationOptions *) [[currentOptions overrideOptions:options] withDefault:[self defaultOptions]];
Expand Down Expand Up @@ -208,17 +208,6 @@ - (void)setTitleViewWithSubtitle:(RNNNavigationOptions *)options {
[_titleViewHelper setSubtitleOptions:options.topBar.subtitle];
}

[_titleViewHelper setup];
} else {
_titleViewHelper = [[RNNTitleViewHelper alloc] initWithTitleViewOptions:options.topBar.title subTitleOptions:options.topBar.subtitle viewController:self.boundViewController];

if (options.topBar.title.text.hasValue) {
[_titleViewHelper setTitleOptions:options.topBar.title];
}
if (options.topBar.subtitle.text.hasValue) {
[_titleViewHelper setSubtitleOptions:options.topBar.subtitle];
}

[_titleViewHelper setup];
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ios/RNNStackPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ - (void)applyOptionsBeforePopping:(RNNNavigationOptions *)options {
RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
RNNStackController* navigationController = self.boundViewController;
[navigationController setTopBarBackgroundColor:[withDefault.topBar.background.color getWithDefaultValue:nil]];
[navigationController setNavigationBarFontFamily:[withDefault.topBar.title.fontFamily getWithDefaultValue:nil] fontSize:[withDefault.topBar.title.fontSize getWithDefaultValue:nil] fontWeight:[withDefault.topBar.title.fontWeight getWithDefaultValue:nil] color:[withDefault.topBar.title.color getWithDefaultValue:[UIColor blackColor]]];
[navigationController setNavigationBarFontFamily:[withDefault.topBar.title.fontFamily getWithDefaultValue:nil] fontSize:[withDefault.topBar.title.fontSize getWithDefaultValue:nil] fontWeight:[withDefault.topBar.title.fontWeight getWithDefaultValue:nil] color:[withDefault.topBar.title.color getWithDefaultValue:nil]];
[navigationController setNavigationBarLargeTitleVisible:[withDefault.topBar.largeTitle.visible getWithDefaultValue:NO]];
}

Expand Down
3 changes: 2 additions & 1 deletion lib/ios/RNNTitleViewHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ -(UILabel*)setupTitle {
CGRect labelframe = titleLabel.frame;
labelframe.size = labelSize;
titleLabel.frame = labelframe;
[titleLabel sizeToFit];

if (!self.subtitle) {
titleLabel.center = self.titleView.center;
Expand All @@ -153,7 +154,7 @@ -(UILabel*)setupTitle {
titleLabel.textColor = color;
}

[titleLabel sizeToFit];

[self.titleView addSubview:titleLabel];

return titleLabel;
Expand Down

0 comments on commit 094b9a7

Please sign in to comment.