Sfoglia il codice sorgente

Support null bottomTab.badge

yogevbd 6 anni fa
parent
commit
811ad9b368

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

@@ -64,6 +64,14 @@ describe('screen style', () => {
64 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 75
   test(':android: hide Tab Bar', async () => {
68 76
     await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
69 77
     await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeVisible();

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

@@ -11,6 +11,27 @@
11 11
 
12 12
 - (void)setUp {
13 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 37
 @end

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

@@ -5,7 +5,7 @@
5 5
 @implementation TextParser
6 6
 
7 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 11
 @end

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

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

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

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

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

@@ -45,6 +45,7 @@ module.exports = {
45 45
   SHOW_SNACKBAR_BUTTON: `SHOW_SNACKBAR_BUTTON`,
46 46
   TOGGLE_TOP_BAR_HIDE_ON_SCROLL: `TOGGLE_TOP_BAR_HIDE_ON_SCROLL`,
47 47
   SET_TAB_BADGE_BUTTON: `SET_TAB_BADGE_BUTTON`,
48
+  SET_TAB_BADGE_BUTTON_NULL: `SET_TAB_BADGE_BUTTON_NULL`,
48 49
   PUSH_TO_TEST_DID_DISAPPEAR_BUTTON: `PUSH_TO_TEST_DID_DISAPPEAR_BUTTON`,
49 50
   PUSH_BUTTON_WAIT_FOR_RENDER: `PUSH_AND_WAIT_FOR_RENDER`,
50 51
   SHOW_LEFT_SIDE_MENU_BUTTON: `SHOW_LEFT_SIDE_MENU_BUTTON`,