Browse Source

Fixes bottomTab.badge - #4167 (#4170)

Yogev Ben David 5 years ago
parent
commit
33ff3568bb
No account linked to committer's email address

+ 1
- 1
lib/ios/RNNBasePresenter.m View File

@@ -29,7 +29,7 @@
29 29
 }
30 30
 
31 31
 - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
32
-	
32
+	[self.bottomTabPresenter mergeOptions:options resolvedOptions:resolvedOptions];
33 33
 }
34 34
 
35 35
 - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {

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

@@ -8,4 +8,6 @@
8 8
 
9 9
 - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions;
10 10
 
11
+- (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions;
12
+
11 13
 @end

+ 12
- 0
lib/ios/RNNBottomTabPresenter.m View File

@@ -1,5 +1,6 @@
1 1
 #import "RNNBottomTabPresenter.h"
2 2
 #import "RNNTabBarItemCreator.h"
3
+#import "UIViewController+RNNOptions.h"
3 4
 
4 5
 @interface RNNBottomTabPresenter()
5 6
 
@@ -24,6 +25,17 @@
24 25
 		[options.bottomTab.icon consume];
25 26
 		[options.bottomTab.selectedIcon consume];
26 27
 	}
28
+	
29
+	if (![viewController isKindOfClass:[UITabBarController class]]) {
30
+		[viewController rnn_setTabBarItemBadge:[options.bottomTab.badge getWithDefaultValue:nil]];
31
+	}
32
+}
33
+
34
+- (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
35
+	UIViewController* viewController = self.bindedViewController;
36
+	if (options.bottomTab.badge.hasValue && ![viewController isKindOfClass:[UITabBarController class]]) {
37
+		[viewController rnn_setTabBarItemBadge:options.bottomTab.badge.get];
38
+	}
27 39
 }
28 40
 
29 41
 - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {

+ 1
- 1
lib/ios/RNNNavigationController.m View File

@@ -48,7 +48,7 @@ const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
48 48
 }
49 49
 
50 50
 - (UITabBarItem *)tabBarItem {
51
-	return super.tabBarItem ? super.tabBarItem : self.viewControllers.lastObject.tabBarItem;
51
+	return self.viewControllers.lastObject.tabBarItem;
52 52
 }
53 53
 
54 54
 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {

+ 1
- 1
lib/ios/RNNSideMenuChildVC.m View File

@@ -49,7 +49,7 @@
49 49
 }
50 50
 
51 51
 - (UITabBarItem *)tabBarItem {
52
-	return super.tabBarItem ? super.tabBarItem : self.child.tabBarItem;
52
+	return self.child.tabBarItem;
53 53
 }
54 54
 
55 55
 - (void)bindChildViewController:(UIViewController<RNNParentProtocol>*)child {

+ 1
- 1
lib/ios/RNNSideMenuController.m View File

@@ -46,7 +46,7 @@
46 46
 }
47 47
 
48 48
 - (UITabBarItem *)tabBarItem {
49
-	return super.tabBarItem ? super.tabBarItem : self.center.tabBarItem;
49
+	return self.center.tabBarItem;
50 50
 }
51 51
 
52 52
 - (void)onChildWillAppear {

+ 1
- 1
lib/ios/RNNTabBarController.m View File

@@ -53,7 +53,7 @@
53 53
 }
54 54
 
55 55
 - (UITabBarItem *)tabBarItem {
56
-	return super.tabBarItem ? super.tabBarItem : self.viewControllers.lastObject.tabBarItem;
56
+	return self.viewControllers.lastObject.tabBarItem;
57 57
 }
58 58
 
59 59
 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {

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

@@ -23,7 +23,6 @@
23 23
 	[viewController rnn_setNavigationItemTitle:[options.topBar.title.text getWithDefaultValue:nil]];
24 24
 	[viewController rnn_setTopBarPrefersLargeTitle:[options.topBar.largeTitle.visible getWithDefaultValue:NO]];
25 25
 	[viewController rnn_setDrawBehindTabBar:[options.bottomTabs.drawBehind getWithDefaultValue:NO] || ![options.bottomTabs.visible getWithDefaultValue:YES]];
26
-	[viewController rnn_setTabBarItemBadge:[options.bottomTab.badge getWithDefaultValue:nil]];
27 26
 	[viewController rnn_setTabBarItemBadgeColor:[options.bottomTab.badgeColor getWithDefaultValue:nil]];
28 27
 	[viewController rnn_setStatusBarBlur:[options.statusBar.blur getWithDefaultValue:NO]];
29 28
 	[viewController rnn_setStatusBarStyle:[options.statusBar.style getWithDefaultValue:@"default"] animated:[options.statusBar.animate getWithDefaultValue:YES]];
@@ -83,10 +82,6 @@
83 82
 		[viewController rnn_setDrawBehindTabBar:options.bottomTabs.drawBehind.get];
84 83
 	}
85 84
 	
86
-	if (options.bottomTab.badge.hasValue) {
87
-		[viewController rnn_setTabBarItemBadge:options.bottomTab.badge.get];
88
-	}
89
-	
90 85
 	if (options.bottomTab.badgeColor.hasValue) {
91 86
 		[viewController rnn_setTabBarItemBadgeColor:options.bottomTab.badgeColor.get];
92 87
 	}

+ 28
- 0
lib/ios/ReactNativeNavigationTests/RNNBottomTabPresenterTest.m View File

@@ -1,5 +1,7 @@
1 1
 #import <XCTest/XCTest.h>
2 2
 #import "RNNBottomTabPresenter.h"
3
+#import <OCMock/OCMock.h>
4
+#import "UIViewController+RNNOptions.h"
3 5
 
4 6
 @interface RNNBottomTabPresenterTest : XCTestCase
5 7
 
@@ -13,6 +15,32 @@
13 15
 
14 16
 - (void)setUp {
15 17
     [super setUp];
18
+    self.uut = [[RNNBottomTabPresenter alloc] init];
19
+    self.bindedViewController = [OCMockObject partialMockForObject:[UIViewController new]];
20
+    [self.uut bindViewController:self.bindedViewController];
21
+    self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
22
+}
23
+
24
+- (void)testApplyOptions_shouldSetTabBarItemBadgeWithDefault {
25
+	[[self.bindedViewController expect] rnn_setTabBarItemBadge:nil];
26
+	[self.uut applyOptions:self.options];
27
+	[self.bindedViewController verify];
28
+}
29
+
30
+- (void)testApplyOptions_shouldSetTabBarItemBadgeWithValue {
31
+	self.options.bottomTab.badge = [[Text alloc] initWithValue:@"badge"];
32
+	[[self.bindedViewController expect] rnn_setTabBarItemBadge:@"badge"];
33
+	[self.uut applyOptions:self.options];
34
+	[self.bindedViewController verify];
35
+}
36
+
37
+- (void)testApplyOptions_setTabBarItemBadgeShouldNotCalledOnUITabBarController {
38
+	self.bindedViewController = [OCMockObject partialMockForObject:[UITabBarController new]];
39
+	[self.uut bindViewController:self.bindedViewController];
40
+	self.options.bottomTab.badge = [[Text alloc] initWithValue:@"badge"];
41
+	[[self.bindedViewController reject] rnn_setTabBarItemBadge:@"badge"];
42
+	[self.uut applyOptions:self.options];
43
+	[self.bindedViewController verify];
16 44
 }
17 45
 
18 46
 //- (void)test_tabBarTextFontFamily_validFont {