Browse Source

Initialize topbar.background.component wrapper view on viewWillAppear, Closes #5138 (#5142)

Yogev Ben David 5 years ago
parent
commit
d2d5d0fe79
1 changed files with 18 additions and 8 deletions
  1. 18
    8
      lib/ios/RNNNavigationControllerPresenter.m

+ 18
- 8
lib/ios/RNNNavigationControllerPresenter.m View File

@@ -9,6 +9,7 @@
9 9
 	RNNReactComponentRegistry* _componentRegistry;
10 10
 	UIView* _customTopBar;
11 11
 	UIView* _customTopBarBackground;
12
+	RNNReactView* _customTopBarBackgroundReactView;
12 13
 }
13 14
 
14 15
 @end
@@ -46,6 +47,10 @@
46 47
 	[navigationController rnn_setNavigationBarFontFamily:[options.topBar.title.fontFamily getWithDefaultValue:nil] fontSize:[options.topBar.title.fontSize getWithDefaultValue:nil] color:[options.topBar.title.color getWithDefaultValue:nil]];
47 48
 	[navigationController rnn_setBackButtonColor:[options.topBar.backButton.color getWithDefaultValue:nil]];
48 49
 	[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] : @""];
50
+	
51
+	if (options.topBar.background.component.name.hasValue) {
52
+		[self presentBackgroundComponent];
53
+	}
49 54
 }
50 55
 
51 56
 - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
@@ -203,15 +208,9 @@
203 208
 	}
204 209
 	if (options.topBar.background.component.name.hasValue) {
205 210
 		NSString* currentChildComponentId = [navigationController getCurrentChild].layoutInfo.componentId;
206
-		RCTRootView *reactView = [_componentRegistry createComponentIfNotExists:options.topBar.background.component parentComponentId:currentChildComponentId reactViewReadyBlock:readyBlock];
211
+		RNNReactView *reactView = [_componentRegistry createComponentIfNotExists:options.topBar.background.component parentComponentId:currentChildComponentId reactViewReadyBlock:readyBlock];
212
+		_customTopBarBackgroundReactView = reactView;
207 213
 		
208
-		if (_customTopBarBackground) {
209
-			[_customTopBarBackground removeFromSuperview];
210
-		}
211
-		RNNCustomTitleView* customTopBarBackground = [[RNNCustomTitleView alloc] initWithFrame:navigationController.navigationBar.bounds subView:reactView alignment:@"fill"];
212
-		_customTopBarBackground = customTopBarBackground;
213
-		
214
-		[navigationController.navigationBar insertSubview:_customTopBarBackground atIndex:1];
215 214
 	} else {
216 215
 		[_customTopBarBackground removeFromSuperview];
217 216
 		_customTopBarBackground = nil;
@@ -221,6 +220,17 @@
221 220
 	}
222 221
 }
223 222
 
223
+- (void)presentBackgroundComponent {
224
+	RNNNavigationController* navigationController = self.bindedViewController;
225
+	if (_customTopBarBackground) {
226
+		[_customTopBarBackground removeFromSuperview];
227
+	}
228
+	RNNCustomTitleView* customTopBarBackground = [[RNNCustomTitleView alloc] initWithFrame:navigationController.navigationBar.bounds subView:_customTopBarBackgroundReactView alignment:@"fill"];
229
+	_customTopBarBackground = customTopBarBackground;
230
+	
231
+	[navigationController.navigationBar insertSubview:_customTopBarBackground atIndex:1];
232
+}
233
+
224 234
 - (void)dealloc {
225 235
 	[_componentRegistry removeComponent:self.bindedComponentId];
226 236
 }