Browse Source

Support null bottomTab.badge

yogevbd 6 years ago
parent
commit
811ad9b368

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

64
     await expect(element(by.text('TeSt'))).toBeVisible();
64
     await expect(element(by.text('TeSt'))).toBeVisible();
65
   });
65
   });
66
 
66
 
67
+  test('set Tab Bar badge null on a current Tab should reset badge', async () => {
68
+    await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
69
+    await elementById(testIDs.SET_TAB_BADGE_BUTTON).tap();
70
+    await expect(element(by.text('TeSt'))).toBeVisible();
71
+    await elementById(testIDs.SET_TAB_BADGE_BUTTON_NULL).tap();
72
+    await expect(element(by.text('TeSt'))).toBeNotVisible();
73
+  });
74
+
67
   test(':android: hide Tab Bar', async () => {
75
   test(':android: hide Tab Bar', async () => {
68
     await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
76
     await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
69
     await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeVisible();
77
     await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeVisible();

+ 21
- 0
lib/ios/ReactNativeNavigationTests/UIViewController+RNNOptionsTest.m View File

11
 
11
 
12
 - (void)setUp {
12
 - (void)setUp {
13
     [super setUp];
13
     [super setUp];
14
+	self.uut = [UIViewController new];
15
+}
16
+
17
+- (void)test_setTabBarItemBadge_shouldSetValidValue {
18
+	NSString* badgeValue = @"badge";
19
+	[self.uut rnn_setTabBarItemBadge:badgeValue];
20
+	XCTAssertEqual(self.uut.tabBarItem.badgeValue, badgeValue);
21
+}
22
+
23
+- (void)test_setTabBarItemBadge_shouldResetWhenValueIsEmptyString {
24
+	[self.uut rnn_setTabBarItemBadge:@"badge"];
25
+	NSString* badgeValue = @"";
26
+	[self.uut rnn_setTabBarItemBadge:badgeValue];
27
+	XCTAssertEqual(self.uut.tabBarItem.badgeValue, nil);
28
+}
29
+
30
+- (void)test_setTabBarItemBadge_shouldResetWhenValueIsNullObject {
31
+	[self.uut rnn_setTabBarItemBadge:@"badge"];
32
+	NSNull* nullBadgeValue = [NSNull new];
33
+	[self.uut rnn_setTabBarItemBadge:nullBadgeValue];
34
+	XCTAssertEqual(self.uut.tabBarItem.badgeValue, nil);
14
 }
35
 }
15
 
36
 
16
 @end
37
 @end

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

5
 @implementation TextParser
5
 @implementation TextParser
6
 
6
 
7
 + (Text *)parse:(NSDictionary *)json key:(NSString *)key {
7
 + (Text *)parse:(NSDictionary *)json key:(NSString *)key {
8
-	return json[key] && ![json[key] isKindOfClass:[NSNull class]] ? [[Text alloc] initWithValue:[RCTConvert NSString:json[key]]] : [NullText new];
8
+	return json[key] ? [[Text alloc] initWithValue:json[key]] : [NullText new];
9
 }
9
 }
10
 
10
 
11
 @end
11
 @end

+ 2
- 1
lib/ios/UIViewController+RNNOptions.m View File

74
 
74
 
75
 - (void)rnn_setTabBarItemBadge:(NSString *)badge {
75
 - (void)rnn_setTabBarItemBadge:(NSString *)badge {
76
 	UITabBarItem *tabBarItem = self.tabBarItem;
76
 	UITabBarItem *tabBarItem = self.tabBarItem;
77
-	tabBarItem.badgeValue = badge;
78
 	
77
 	
79
 	if ([badge isKindOfClass:[NSNull class]] || [badge isEqualToString:@""]) {
78
 	if ([badge isKindOfClass:[NSNull class]] || [badge isEqualToString:@""]) {
80
 		tabBarItem.badgeValue = nil;
79
 		tabBarItem.badgeValue = nil;
80
+	} else {
81
+		tabBarItem.badgeValue = badge;
81
 	}
82
 	}
82
 }
83
 }
83
 
84
 

+ 9
- 0
playground/src/screens/TextScreen.js View File

27
           {this.renderTextFromFunctionInProps()}
27
           {this.renderTextFromFunctionInProps()}
28
           <Text style={styles.footer}>{`this.props.componentId = ${this.props.componentId}`}</Text>
28
           <Text style={styles.footer}>{`this.props.componentId = ${this.props.componentId}`}</Text>
29
           <Button title={'Set Tab Badge'} testID={testIDs.SET_TAB_BADGE_BUTTON} onPress={() => this.onClickSetBadge()} />
29
           <Button title={'Set Tab Badge'} testID={testIDs.SET_TAB_BADGE_BUTTON} onPress={() => this.onClickSetBadge()} />
30
+          <Button title={'Set empty Tab Badge'} testID={testIDs.SET_TAB_BADGE_BUTTON_NULL} onPress={() => this.onClickSetNullBadge()} />
30
           <Button title={'Switch To Tab 2'} testID={testIDs.SWITCH_SECOND_TAB_BUTTON} onPress={() => this.onClickSwitchToTab()} />
31
           <Button title={'Switch To Tab 2'} testID={testIDs.SWITCH_SECOND_TAB_BUTTON} onPress={() => this.onClickSwitchToTab()} />
31
           <Button title={'Switch To Tab 1 by componentID'} testID={testIDs.SWITCH_FIRST_TAB_BUTTON} onPress={() => this.onClickSwitchToTabByComponentID()} />
32
           <Button title={'Switch To Tab 1 by componentID'} testID={testIDs.SWITCH_FIRST_TAB_BUTTON} onPress={() => this.onClickSwitchToTabByComponentID()} />
32
           {/* tslint:disable-next-line:max-line-length */}
33
           {/* tslint:disable-next-line:max-line-length */}
51
     });
52
     });
52
   }
53
   }
53
 
54
 
55
+  onClickSetNullBadge() {
56
+    Navigation.mergeOptions(this.props.componentId, {
57
+      bottomTab: {
58
+        badge: null
59
+      }
60
+    });
61
+  }
62
+
54
   onClickPush = async () => {
63
   onClickPush = async () => {
55
     await Navigation.push(this.props.componentId, {
64
     await Navigation.push(this.props.componentId, {
56
       component: {
65
       component: {

+ 1
- 0
playground/src/testIDs.js View File

45
   SHOW_SNACKBAR_BUTTON: `SHOW_SNACKBAR_BUTTON`,
45
   SHOW_SNACKBAR_BUTTON: `SHOW_SNACKBAR_BUTTON`,
46
   TOGGLE_TOP_BAR_HIDE_ON_SCROLL: `TOGGLE_TOP_BAR_HIDE_ON_SCROLL`,
46
   TOGGLE_TOP_BAR_HIDE_ON_SCROLL: `TOGGLE_TOP_BAR_HIDE_ON_SCROLL`,
47
   SET_TAB_BADGE_BUTTON: `SET_TAB_BADGE_BUTTON`,
47
   SET_TAB_BADGE_BUTTON: `SET_TAB_BADGE_BUTTON`,
48
+  SET_TAB_BADGE_BUTTON_NULL: `SET_TAB_BADGE_BUTTON_NULL`,
48
   PUSH_TO_TEST_DID_DISAPPEAR_BUTTON: `PUSH_TO_TEST_DID_DISAPPEAR_BUTTON`,
49
   PUSH_TO_TEST_DID_DISAPPEAR_BUTTON: `PUSH_TO_TEST_DID_DISAPPEAR_BUTTON`,
49
   PUSH_BUTTON_WAIT_FOR_RENDER: `PUSH_AND_WAIT_FOR_RENDER`,
50
   PUSH_BUTTON_WAIT_FOR_RENDER: `PUSH_AND_WAIT_FOR_RENDER`,
50
   SHOW_LEFT_SIDE_MENU_BUTTON: `SHOW_LEFT_SIDE_MENU_BUTTON`,
51
   SHOW_LEFT_SIDE_MENU_BUTTON: `SHOW_LEFT_SIDE_MENU_BUTTON`,