Browse Source

BottomTab testId (#2668)

Guy Carmeli 7 years ago
parent
commit
d97046c210
No account linked to committer's email address

+ 2
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/BottomTabOptions.java View File

@@ -13,11 +13,13 @@ public class BottomTabOptions implements DEFAULT_VALUES {
13 13
             throw new RuntimeException("BottomTab must have an icon");
14 14
         }
15 15
         options.icon = TextParser.parse(json.optJSONObject("icon"), "uri");
16
+        options.testId = TextParser.parse(json, "testID");
16 17
         return options;
17 18
     }
18 19
 
19 20
     public Text title = new NullText();
20 21
     public Text icon = new NullText();
22
+    public Text testId = new NullText();
21 23
 
22 24
     void mergeWith(final BottomTabOptions other) {
23 25
         if (other.title.hasValue()) {

+ 3
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/BottomTabsController.java View File

@@ -76,12 +76,12 @@ public class BottomTabsController extends ParentController implements AHBottomNa
76 76
 		this.tabs = tabs;
77 77
 		getView();
78 78
 		for (int i = 0; i < tabs.size(); i++) {
79
-			createTab(tabs.get(i), tabs.get(i).options.bottomTabOptions, tabs.get(i).options.bottomTabsOptions);
79
+			createTab(i, tabs.get(i), tabs.get(i).options.bottomTabOptions, tabs.get(i).options.bottomTabsOptions);
80 80
 		}
81 81
 		selectTabAtIndex(0);
82 82
 	}
83 83
 
84
-	private void createTab(ViewController tab, final BottomTabOptions tabOptions, final BottomTabsOptions bottomTabsOptions) {
84
+	private void createTab(int index, ViewController tab, final BottomTabOptions tabOptions, final BottomTabsOptions bottomTabsOptions) {
85 85
 	    if (!tabOptions.icon.hasValue()) {
86 86
             throw new RuntimeException("BottomTab must have an icon");
87 87
         }
@@ -91,6 +91,7 @@ public class BottomTabsController extends ParentController implements AHBottomNa
91 91
                 setIconColor(drawable, bottomTabsOptions);
92 92
                 AHBottomNavigationItem item = new AHBottomNavigationItem(tabOptions.title.get(""), drawable);
93 93
                 bottomTabs.addItem(item);
94
+                bottomTabs.post(() -> bottomTabs.setTabTag(index, tabOptions.testId));
94 95
             }
95 96
 
96 97
             @Override

+ 6
- 0
lib/android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java View File

@@ -19,4 +19,10 @@ public class BottomTabs extends AHBottomNavigation {
19 19
     private void setTestId(Text testId) {
20 20
         if (testId.hasValue()) setTag(testId.get());
21 21
     }
22
+
23
+    public void setTabTag(int index, Text testId) {
24
+        if (!testId.hasValue()) return;
25
+        if (testId.hasValue()) getViewAtPosition(index).setTag(testId.get());
26
+        if (testId.hasValue()) getViewAtPosition(index).setContentDescription(testId.get());
27
+    }
22 28
 }