Browse Source

Apply bottomTabs options after children added (#4994)

* Apply bottomTabs options after children added

* Fix unit tests
Yogev Ben David 5 years ago
parent
commit
2bddff390d
No account linked to committer's email address

+ 2
- 0
lib/ios/RNNBasePresenter.h View File

@@ -14,6 +14,8 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);
14 14
 
15 15
 - (void)applyOptions:(RNNNavigationOptions *)options;
16 16
 
17
+- (void)applyOptionsOnSetViewControllers:(RNNNavigationOptions *)options;
18
+
17 19
 - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options;
18 20
 
19 21
 - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions;

+ 22
- 18
lib/ios/RNNBasePresenter.m View File

@@ -23,47 +23,51 @@
23 23
 }
24 24
 
25 25
 - (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
26
+	
27
+}
26 28
 
29
+- (void)applyOptionsOnSetViewControllers:(RNNNavigationOptions *)options {
30
+	
27 31
 }
28 32
 
29 33
 - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
30 34
 	UIViewController* viewController = self.bindedViewController;
31
-
35
+	
32 36
 	if (options.bottomTab.text.hasValue) {
33 37
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
34 38
 		viewController.tabBarItem = tabItem;
35 39
 	}
36
-
40
+	
37 41
 	if (options.bottomTab.icon.hasValue) {
38 42
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
39 43
 		viewController.tabBarItem = tabItem;
40 44
 	}
41
-
45
+	
42 46
 	if (options.bottomTab.selectedIcon.hasValue) {
43 47
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
44 48
 		viewController.tabBarItem = tabItem;
45 49
 	}
46
-
50
+	
47 51
 	if (options.bottomTab.badgeColor.hasValue) {
48 52
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
49 53
 		viewController.tabBarItem = tabItem;
50 54
 	}
51
-
55
+	
52 56
 	if (options.bottomTab.textColor.hasValue) {
53 57
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
54 58
 		viewController.tabBarItem = tabItem;
55 59
 	}
56
-
60
+	
57 61
 	if (options.bottomTab.iconColor.hasValue) {
58 62
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
59 63
 		viewController.tabBarItem = tabItem;
60 64
 	}
61
-
65
+	
62 66
 	if (options.bottomTab.selectedTextColor.hasValue) {
63 67
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
64 68
 		viewController.tabBarItem = tabItem;
65 69
 	}
66
-
70
+	
67 71
 	if (options.bottomTab.selectedIconColor.hasValue) {
68 72
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:options.bottomTab];
69 73
 		viewController.tabBarItem = tabItem;
@@ -72,11 +76,11 @@
72 76
 
73 77
 - (void)applyOptions:(RNNNavigationOptions *)options {
74 78
 	UIViewController* viewController = self.bindedViewController;
75
-
79
+	
76 80
 	if (options.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
77 81
 		[viewController rnn_setTabBarItemBadge:options.bottomTab.badge.get];
78 82
 	}
79
-
83
+	
80 84
 	if (options.bottomTab.badgeColor.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
81 85
 		[viewController rnn_setTabBarItemBadgeColor:options.bottomTab.badgeColor.get];
82 86
 	}
@@ -87,47 +91,47 @@
87 91
 	if (newOptions.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
88 92
 		[viewController rnn_setTabBarItemBadge:newOptions.bottomTab.badge.get];
89 93
 	}
90
-
94
+	
91 95
 	if (newOptions.bottomTab.badgeColor.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
92 96
 		[viewController rnn_setTabBarItemBadgeColor:newOptions.bottomTab.badgeColor.get];
93 97
 	}
94
-
98
+	
95 99
 	if (newOptions.bottomTab.text.hasValue) {
96 100
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
97 101
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
98 102
 		viewController.tabBarItem = tabItem;
99 103
 	}
100
-
104
+	
101 105
 	if (newOptions.bottomTab.icon.hasValue) {
102 106
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
103 107
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
104 108
 		viewController.tabBarItem = tabItem;
105 109
 	}
106
-
110
+	
107 111
 	if (newOptions.bottomTab.selectedIcon.hasValue) {
108 112
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
109 113
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
110 114
 		viewController.tabBarItem = tabItem;
111 115
 	}
112
-
116
+	
113 117
 	if (newOptions.bottomTab.textColor.hasValue) {
114 118
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
115 119
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
116 120
 		viewController.tabBarItem = tabItem;
117 121
 	}
118
-
122
+	
119 123
 	if (newOptions.bottomTab.selectedTextColor.hasValue) {
120 124
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
121 125
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
122 126
 		viewController.tabBarItem = tabItem;
123 127
 	}
124
-
128
+	
125 129
 	if (newOptions.bottomTab.iconColor.hasValue) {
126 130
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
127 131
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];
128 132
 		viewController.tabBarItem = tabItem;
129 133
 	}
130
-
134
+	
131 135
 	if (newOptions.bottomTab.selectedIconColor.hasValue) {
132 136
 		RNNNavigationOptions* buttonsResolvedOptions = [(RNNNavigationOptions *)[currentOptions overrideOptions:newOptions] withDefault:defaultOptions];
133 137
 		UITabBarItem* tabItem = [RNNTabBarItemCreator updateTabBarItem:viewController.tabBarItem bottomTabOptions:buttonsResolvedOptions.bottomTab];

+ 5
- 0
lib/ios/RNNTabBarController.m View File

@@ -4,6 +4,11 @@
4 4
 	NSUInteger _currentTabIndex;
5 5
 }
6 6
 
7
+- (void)setViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers {
8
+	[super setViewControllers:viewControllers];
9
+	[self.presenter applyOptionsOnSetViewControllers:self.resolveOptions];
10
+}
11
+
7 12
 - (id<UITabBarControllerDelegate>)delegate {
8 13
 	return self;
9 14
 }

+ 2
- 2
lib/ios/RNNTabBarPresenter.m View File

@@ -3,9 +3,9 @@
3 3
 
4 4
 @implementation RNNTabBarPresenter
5 5
 
6
-- (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
6
+- (void)applyOptionsOnSetViewControllers:(RNNNavigationOptions *)options {
7 7
 	UITabBarController* tabBarController = self.bindedViewController;
8
-	[tabBarController rnn_setCurrentTabIndex:[initialOptions.bottomTabs.currentTabIndex getWithDefaultValue:0]];
8
+	[tabBarController rnn_setCurrentTabIndex:[options.bottomTabs.currentTabIndex getWithDefaultValue:0]];
9 9
 }
10 10
 
11 11
 - (void)applyOptions:(RNNNavigationOptions *)options {

+ 2
- 2
lib/ios/ReactNativeNavigationTests/RNNTabBarPresenterTest.m View File

@@ -54,12 +54,12 @@
54 54
 	[self.bindedViewController verify];
55 55
 }
56 56
 
57
-- (void)testApplyOptions_shouldApplyOptionsOnInit {
57
+- (void)testApplyOptions_shouldApplyOptionsOnSetViewControllers {
58 58
 	RNNNavigationOptions* initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
59 59
 	initialOptions.bottomTabs.currentTabIndex = [[IntNumber alloc] initWithValue:@(1)];
60 60
 	[[self.bindedViewController expect] rnn_setCurrentTabIndex:1];
61 61
 	
62
-	[self.uut applyOptionsOnInit:initialOptions];
62
+	[self.uut applyOptionsOnSetViewControllers:initialOptions];
63 63
 	[self.bindedViewController verify];
64 64
 }
65 65