Skip to content

Commit

Permalink
Initialize topbar.background.component wrapper view on viewWillAppear,
Browse files Browse the repository at this point in the history
…Closes #5138 (#5142)
  • Loading branch information
yogevbd authored and guyca committed May 23, 2019
1 parent 2090c3d commit d2d5d0f
Showing 1 changed file with 18 additions and 8 deletions.
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

0 comments on commit d2d5d0f

Please sign in to comment.