Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize topbar.background.component wrapper view on viewWillAppear #5142

Merged
merged 1 commit into from
May 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions lib/ios/RNNNavigationControllerPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ @interface RNNNavigationControllerPresenter() {
RNNReactComponentRegistry* _componentRegistry;
UIView* _customTopBar;
UIView* _customTopBarBackground;
RNNReactView* _customTopBarBackgroundReactView;
}

@end
Expand Down Expand Up @@ -46,6 +47,10 @@ - (void)applyOptions:(RNNNavigationOptions *)options {
[navigationController rnn_setNavigationBarFontFamily:[options.topBar.title.fontFamily getWithDefaultValue:nil] fontSize:[options.topBar.title.fontSize getWithDefaultValue:nil] color:[options.topBar.title.color getWithDefaultValue:nil]];
[navigationController rnn_setBackButtonColor:[options.topBar.backButton.color getWithDefaultValue:nil]];
[navigationController rnn_setBackButtonIcon:[options.topBar.backButton.icon getWithDefaultValue:nil] withColor:[options.topBar.backButton.color getWithDefaultValue:nil] title:[options.topBar.backButton.showTitle getWithDefaultValue:YES] ? [options.topBar.backButton.title getWithDefaultValue:nil] : @""];

if (options.topBar.background.component.name.hasValue) {
[self presentBackgroundComponent];
}
}

- (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
Expand Down Expand Up @@ -203,15 +208,9 @@ - (void)setCustomNavigationComponentBackground:(RNNNavigationOptions *)options p
}
if (options.topBar.background.component.name.hasValue) {
NSString* currentChildComponentId = [navigationController getCurrentChild].layoutInfo.componentId;
RCTRootView *reactView = [_componentRegistry createComponentIfNotExists:options.topBar.background.component parentComponentId:currentChildComponentId reactViewReadyBlock:readyBlock];
RNNReactView *reactView = [_componentRegistry createComponentIfNotExists:options.topBar.background.component parentComponentId:currentChildComponentId reactViewReadyBlock:readyBlock];
_customTopBarBackgroundReactView = reactView;

if (_customTopBarBackground) {
[_customTopBarBackground removeFromSuperview];
}
RNNCustomTitleView* customTopBarBackground = [[RNNCustomTitleView alloc] initWithFrame:navigationController.navigationBar.bounds subView:reactView alignment:@"fill"];
_customTopBarBackground = customTopBarBackground;

[navigationController.navigationBar insertSubview:_customTopBarBackground atIndex:1];
} else {
[_customTopBarBackground removeFromSuperview];
_customTopBarBackground = nil;
Expand All @@ -221,6 +220,17 @@ - (void)setCustomNavigationComponentBackground:(RNNNavigationOptions *)options p
}
}

- (void)presentBackgroundComponent {
RNNNavigationController* navigationController = self.bindedViewController;
if (_customTopBarBackground) {
[_customTopBarBackground removeFromSuperview];
}
RNNCustomTitleView* customTopBarBackground = [[RNNCustomTitleView alloc] initWithFrame:navigationController.navigationBar.bounds subView:_customTopBarBackgroundReactView alignment:@"fill"];
_customTopBarBackground = customTopBarBackground;

[navigationController.navigationBar insertSubview:_customTopBarBackground atIndex:1];
}

- (void)dealloc {
[_componentRegistry removeComponent:self.bindedComponentId];
}
Expand Down