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
 }
29
 }
30
 
30
 
31
 - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
31
 - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
32
-	
32
+	[self.bottomTabPresenter mergeOptions:options resolvedOptions:resolvedOptions];
33
 }
33
 }
34
 
34
 
35
 - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
35
 - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {

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

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

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

1
 #import "RNNBottomTabPresenter.h"
1
 #import "RNNBottomTabPresenter.h"
2
 #import "RNNTabBarItemCreator.h"
2
 #import "RNNTabBarItemCreator.h"
3
+#import "UIViewController+RNNOptions.h"
3
 
4
 
4
 @interface RNNBottomTabPresenter()
5
 @interface RNNBottomTabPresenter()
5
 
6
 
24
 		[options.bottomTab.icon consume];
25
 		[options.bottomTab.icon consume];
25
 		[options.bottomTab.selectedIcon consume];
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
 - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
41
 - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {

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

48
 }
48
 }
49
 
49
 
50
 - (UITabBarItem *)tabBarItem {
50
 - (UITabBarItem *)tabBarItem {
51
-	return super.tabBarItem ? super.tabBarItem : self.viewControllers.lastObject.tabBarItem;
51
+	return self.viewControllers.lastObject.tabBarItem;
52
 }
52
 }
53
 
53
 
54
 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
54
 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {

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

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

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

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

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

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

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

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

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

1
 #import <XCTest/XCTest.h>
1
 #import <XCTest/XCTest.h>
2
 #import "RNNBottomTabPresenter.h"
2
 #import "RNNBottomTabPresenter.h"
3
+#import <OCMock/OCMock.h>
4
+#import "UIViewController+RNNOptions.h"
3
 
5
 
4
 @interface RNNBottomTabPresenterTest : XCTestCase
6
 @interface RNNBottomTabPresenterTest : XCTestCase
5
 
7
 
13
 
15
 
14
 - (void)setUp {
16
 - (void)setUp {
15
     [super setUp];
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
 //- (void)test_tabBarTextFontFamily_validFont {
46
 //- (void)test_tabBarTextFontFamily_validFont {