Browse Source

Fixes bottomTab.badge for bottomTabs inside sideMenu - #4171

yogevbd 5 years ago
parent
commit
8e9c647fa5

+ 6
- 0
e2e/ScreenStyle.test.js View File

@@ -58,6 +58,12 @@ describe('screen style', () => {
58 58
     await expect(element(by.text('TeSt'))).toBeVisible();
59 59
   });
60 60
 
61
+  test('set Tab Bar badge on a current Tab appear once', async () => {
62
+    await elementById(testIDs.TAB_BASED_APP_SIDE_BUTTON).tap();
63
+    await elementById(testIDs.SET_TAB_BADGE_BUTTON).tap();
64
+    await expect(element(by.text('TeSt'))).toBeVisible();
65
+  });
66
+
61 67
   test(':android: hide Tab Bar', async () => {
62 68
     await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
63 69
     await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeVisible();

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

@@ -26,14 +26,14 @@
26 26
 		[options.bottomTab.selectedIcon consume];
27 27
 	}
28 28
 	
29
-	if (![viewController isKindOfClass:[UITabBarController class]]) {
29
+	if ([viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
30 30
 		[viewController rnn_setTabBarItemBadge:[options.bottomTab.badge getWithDefaultValue:nil]];
31 31
 	}
32 32
 }
33 33
 
34 34
 - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
35 35
 	UIViewController* viewController = self.bindedViewController;
36
-	if (options.bottomTab.badge.hasValue && ![viewController isKindOfClass:[UITabBarController class]]) {
36
+	if (options.bottomTab.badge.hasValue && [viewController.parentViewController isKindOfClass:[UITabBarController class]]) {
37 37
 		[viewController rnn_setTabBarItemBadge:options.bottomTab.badge.get];
38 38
 	}
39 39
 }

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

@@ -52,10 +52,6 @@
52 52
 	[((UIViewController<RNNLayoutProtocol> *)self.parentViewController) mergeOptions:options];
53 53
 }
54 54
 
55
-- (UITabBarItem *)tabBarItem {
56
-	return self.viewControllers.lastObject.tabBarItem;
57
-}
58
-
59 55
 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
60 56
 	return self.selectedViewController.supportedInterfaceOrientations;
61 57
 }

+ 11
- 1
lib/ios/ReactNativeNavigationTests/RNNBottomTabPresenterTest.m View File

@@ -21,13 +21,23 @@
21 21
     self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
22 22
 }
23 23
 
24
-- (void)testApplyOptions_shouldSetTabBarItemBadgeWithDefault {
24
+- (void)testApplyOptions_shouldSetTabBarItemBadgeWithDefaultWhenParentIsUITabBarController {
25
+	UITabBarController* tabBarController = [[UITabBarController alloc] init];
26
+	[tabBarController setViewControllers:@[self.bindedViewController]];
25 27
 	[[self.bindedViewController expect] rnn_setTabBarItemBadge:nil];
26 28
 	[self.uut applyOptions:self.options];
27 29
 	[self.bindedViewController verify];
28 30
 }
29 31
 
32
+- (void)testApplyOptions_shouldSetTabBarItemBadgeOnlyWhenParentIsUITabBarController {
33
+	[[self.bindedViewController reject] rnn_setTabBarItemBadge:[OCMArg any]];
34
+	[self.uut applyOptions:self.options];
35
+	[self.bindedViewController verify];
36
+}
37
+
30 38
 - (void)testApplyOptions_shouldSetTabBarItemBadgeWithValue {
39
+	UITabBarController* tabBarController = [[UITabBarController alloc] init];
40
+	[tabBarController setViewControllers:@[self.bindedViewController]];
31 41
 	self.options.bottomTab.badge = [[Text alloc] initWithValue:@"badge"];
32 42
 	[[self.bindedViewController expect] rnn_setTabBarItemBadge:@"badge"];
33 43
 	[self.uut applyOptions:self.options];