Browse Source

Split selectBottomTab into two methods to prevent passing null parameters

Guy Carmeli 8 years ago
parent
commit
c93d4d93c8

+ 7
- 2
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactModule.java View File

@@ -76,8 +76,13 @@ public class NavigationReactModule extends ReactContextBaseJavaModule {
76 76
     }
77 77
 
78 78
     @ReactMethod
79
-    public void selectBottomTab(String navigatorId, Integer index) {
80
-        NavigationCommandsHandler.selectBottomTab(navigatorId, index);
79
+    public void selectBottomTabByTabIndex(Integer index) {
80
+        NavigationCommandsHandler.selectBottomTabByTabIndex(index);
81
+    }
82
+
83
+    @ReactMethod
84
+    public void selectBottomTabByNavigatorId(String navigatorId) {
85
+        NavigationCommandsHandler.selectBottomTabByNavigatorId(navigatorId);
81 86
     }
82 87
 
83 88
     @ReactMethod

+ 8
- 2
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java View File

@@ -213,9 +213,15 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
213 213
         layout.setSideMenuVisible(animated, visible);
214 214
     }
215 215
 
216
-    public void selectBottomTab(String navigatorId, Integer index) {
216
+    public void selectBottomTabByTabIndex(Integer index) {
217 217
         if (layout instanceof BottomTabsLayout) {
218
-            ((BottomTabsLayout) layout).selectBottomTab(navigatorId, index);
218
+            ((BottomTabsLayout) layout).selectBottomTabByTabIndex(index);
219
+        }
220
+    }
221
+
222
+    public void selectBottomTabByNavigatorId(String navigatorId) {
223
+        if (layout instanceof BottomTabsLayout) {
224
+            ((BottomTabsLayout) layout).selectBottomTabByNavigatorId(navigatorId);
219 225
         }
220 226
     }
221 227
 }

+ 16
- 2
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationCommandsHandler.java View File

@@ -239,7 +239,7 @@ public class NavigationCommandsHandler {
239 239
         });
240 240
     }
241 241
 
242
-    public static void selectBottomTab(final String navigatorId, final Integer index) {
242
+    public static void selectBottomTabByTabIndex(final Integer index) {
243 243
         final NavigationActivity currentActivity = NavigationActivity.currentActivity;
244 244
         if (currentActivity == null) {
245 245
             return;
@@ -248,7 +248,21 @@ public class NavigationCommandsHandler {
248 248
         NavigationApplication.instance.runOnMainThread(new Runnable() {
249 249
             @Override
250 250
             public void run() {
251
-                currentActivity.selectBottomTab(navigatorId, index);
251
+                currentActivity.selectBottomTabByTabIndex(index);
252
+            }
253
+        });
254
+    }
255
+
256
+    public static void selectBottomTabByNavigatorId(final String navigatorId) {
257
+        final NavigationActivity currentActivity = NavigationActivity.currentActivity;
258
+        if (currentActivity == null) {
259
+            return;
260
+        }
261
+
262
+        NavigationApplication.instance.runOnMainThread(new Runnable() {
263
+            @Override
264
+            public void run() {
265
+                currentActivity.selectBottomTabByNavigatorId(navigatorId);
252 266
             }
253 267
         });
254 268
     }

+ 6
- 6
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java View File

@@ -164,12 +164,12 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
164 164
         }
165 165
     }
166 166
 
167
-    public void selectBottomTab(String navigatorId, Integer index) {
168
-        if (index != null) {
169
-            bottomTabs.setCurrentItem(index);
170
-        } else {
171
-            bottomTabs.setCurrentItem(getScreenStackIndex(navigatorId));
172
-        }
167
+    public void selectBottomTabByTabIndex(Integer index) {
168
+        bottomTabs.setCurrentItem(index);
169
+    }
170
+
171
+    public void selectBottomTabByNavigatorId(String navigatorId) {
172
+        bottomTabs.setCurrentItem(getScreenStackIndex(navigatorId));
173 173
     }
174 174
 
175 175
     @Override

+ 6
- 1
src/deprecated/platformSpecificDeprecated.android.js View File

@@ -243,7 +243,12 @@ function navigatorSetTitle(navigator, params) {
243 243
 }
244 244
 
245 245
 function navigatorSwitchToTab(navigator, params) {
246
-  newPlatformSpecific.selectBottomTab(navigator.navigatorID, params.tabIndex);
246
+  debugger;
247
+  if (params.tabIndex >= 0) {
248
+    newPlatformSpecific.selectBottomTabByTabIndex(params.tabIndex);
249
+  } else {
250
+    newPlatformSpecific.selectBottomTabByNavigatorId(navigator.navigatorID);
251
+  }
247 252
 }
248 253
 
249 254
 function navigatorToggleDrawer(navigator, params) {

+ 8
- 3
src/platformSpecific.android.js View File

@@ -92,8 +92,12 @@ function setSideMenuVisible(animated, visible) {
92 92
   NativeReactModule.setSideMenuVisible(animated, visible);
93 93
 }
94 94
 
95
-function selectBottomTab(navigatorId, index) {
96
-  NativeReactModule.selectBottomTab(navigatorId, index);
95
+function selectBottomTabByNavigatorId(navigatorId) {
96
+  NativeReactModule.selectBottomTabByNavigatorId(navigatorId);
97
+}
98
+
99
+function selectBottomTabByTabIndex(index) {
100
+  NativeReactModule.selectBottomTabByTabIndex(index);
97 101
 }
98 102
 
99 103
 module.exports = {
@@ -111,5 +115,6 @@ module.exports = {
111 115
   dismissAllModals,
112 116
   toggleSideMenuVisible,
113 117
   setSideMenuVisible,
114
-  selectBottomTab
118
+  selectBottomTabByNavigatorId,
119
+  selectBottomTabByTabIndex
115 120
 };