Browse Source

Apply button options on viewController init

yogevbd 5 years ago
parent
commit
be2933f913

+ 4
- 4
lib/ios/RNNViewControllerPresenter.m View File

31
 	if (options.topBar.searchBar.hasValue) {
31
 	if (options.topBar.searchBar.hasValue) {
32
 		[viewController rnn_setSearchBarWithPlaceholder:[options.topBar.searchBarPlaceholder getWithDefaultValue:@""]];
32
 		[viewController rnn_setSearchBarWithPlaceholder:[options.topBar.searchBarPlaceholder getWithDefaultValue:@""]];
33
 	}
33
 	}
34
-	
35
-	if ((options.topBar.leftButtons || options.topBar.rightButtons)) {
36
-		[_navigationButtons applyLeftButtons:options.topBar.leftButtons rightButtons:options.topBar.rightButtons defaultLeftButtonStyle:options.topBar.leftButtonStyle defaultRightButtonStyle:options.topBar.rightButtonStyle];
37
-	}
38
 }
34
 }
39
 
35
 
40
 - (void)applyOptionsOnInit:(RNNNavigationOptions *)options {
36
 - (void)applyOptionsOnInit:(RNNNavigationOptions *)options {
45
 	[viewController rnn_setModalTransitionStyle:[RCTConvert UIModalTransitionStyle:[options.modalTransitionStyle getWithDefaultValue:@"coverVertical"]]];
41
 	[viewController rnn_setModalTransitionStyle:[RCTConvert UIModalTransitionStyle:[options.modalTransitionStyle getWithDefaultValue:@"coverVertical"]]];
46
 	[viewController rnn_setDrawBehindTopBar:[options.topBar.drawBehind getWithDefaultValue:NO]];
42
 	[viewController rnn_setDrawBehindTopBar:[options.topBar.drawBehind getWithDefaultValue:NO]];
47
 	[viewController rnn_setDrawBehindTabBar:[options.bottomTabs.drawBehind getWithDefaultValue:NO] || ![options.bottomTabs.visible getWithDefaultValue:YES]];
43
 	[viewController rnn_setDrawBehindTabBar:[options.bottomTabs.drawBehind getWithDefaultValue:NO] || ![options.bottomTabs.visible getWithDefaultValue:YES]];
44
+	
45
+	if ((options.topBar.leftButtons || options.topBar.rightButtons)) {
46
+		[_navigationButtons applyLeftButtons:options.topBar.leftButtons rightButtons:options.topBar.rightButtons defaultLeftButtonStyle:options.topBar.leftButtonStyle defaultRightButtonStyle:options.topBar.rightButtonStyle];
47
+	}
48
 }
48
 }
49
 
49
 
50
 - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions {
50
 - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions {

+ 8
- 9
lib/ios/ReactNativeNavigationTests/RNNRootViewControllerTest.m View File

414
 
414
 
415
 -(void)testRightButtonsWithTitle_withoutStyle {
415
 -(void)testRightButtonsWithTitle_withoutStyle {
416
 	self.options.topBar.rightButtons = @[@{@"id": @"testId", @"text": @"test"}];
416
 	self.options.topBar.rightButtons = @[@{@"id": @"testId", @"text": @"test"}];
417
-	__unused RNNNavigationController* nav = [self createNavigationController];
418
-	[self.uut viewWillAppear:false];
417
+	self.uut = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNViewControllerPresenter new] options:self.options defaultOptions:nil];
418
+	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[self.uut] options:nil defaultOptions:nil presenter:nil];
419
 
419
 
420
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
420
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
421
 	NSString* expectedButtonId = @"testId";
421
 	NSString* expectedButtonId = @"testId";
429
 	NSNumber* inputColor = @(0xFFFF0000);
429
 	NSNumber* inputColor = @(0xFFFF0000);
430
 
430
 
431
 	self.options.topBar.rightButtons = @[@{@"id": @"testId", @"text": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
431
 	self.options.topBar.rightButtons = @[@{@"id": @"testId", @"text": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
432
-	__unused RNNNavigationController* nav = [self createNavigationController];
433
-	[self.uut viewWillAppear:false];
432
+	self.uut = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNViewControllerPresenter new] options:self.options defaultOptions:nil];
433
+	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[self.uut] options:nil defaultOptions:nil presenter:nil];
434
 
434
 
435
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
435
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
436
 	NSString* expectedButtonId = @"testId";
436
 	NSString* expectedButtonId = @"testId";
445
 
445
 
446
 -(void)testLeftButtonsWithTitle_withoutStyle {
446
 -(void)testLeftButtonsWithTitle_withoutStyle {
447
 	self.options.topBar.leftButtons = @[@{@"id": @"testId", @"text": @"test"}];
447
 	self.options.topBar.leftButtons = @[@{@"id": @"testId", @"text": @"test"}];
448
-	__unused RNNNavigationController* nav = [self createNavigationController];
449
-	[self.uut viewWillAppear:false];
448
+	self.uut = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNViewControllerPresenter new] options:self.options defaultOptions:nil];
449
+	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[self.uut] options:nil defaultOptions:nil presenter:nil];
450
 
450
 
451
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
451
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
452
 	NSString* expectedButtonId = @"testId";
452
 	NSString* expectedButtonId = @"testId";
460
 	NSNumber* inputColor = @(0xFFFF0000);
460
 	NSNumber* inputColor = @(0xFFFF0000);
461
 
461
 
462
 	self.options.topBar.leftButtons = @[@{@"id": @"testId", @"text": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
462
 	self.options.topBar.leftButtons = @[@{@"id": @"testId", @"text": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
463
-	__unused RNNNavigationController* nav = [self createNavigationController];
464
-
465
-	[self.uut viewWillAppear:false];
463
+	self.uut = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[RNNViewControllerPresenter new] options:self.options defaultOptions:nil];
464
+	RNNNavigationController* nav = [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[self.uut] options:nil defaultOptions:nil presenter:nil];
466
 
465
 
467
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
466
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
468
 	NSString* expectedButtonId = @"testId";
467
 	NSString* expectedButtonId = @"testId";