Selaa lähdekoodia

Split selectBottomTab into two methods to prevent passing null parameters

Guy Carmeli 8 vuotta sitten
vanhempi
commit
c93d4d93c8

+ 7
- 2
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactModule.java Näytä tiedosto

76
     }
76
     }
77
 
77
 
78
     @ReactMethod
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
     @ReactMethod
88
     @ReactMethod

+ 8
- 2
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java Näytä tiedosto

213
         layout.setSideMenuVisible(animated, visible);
213
         layout.setSideMenuVisible(animated, visible);
214
     }
214
     }
215
 
215
 
216
-    public void selectBottomTab(String navigatorId, Integer index) {
216
+    public void selectBottomTabByTabIndex(Integer index) {
217
         if (layout instanceof BottomTabsLayout) {
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 Näytä tiedosto

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
         final NavigationActivity currentActivity = NavigationActivity.currentActivity;
243
         final NavigationActivity currentActivity = NavigationActivity.currentActivity;
244
         if (currentActivity == null) {
244
         if (currentActivity == null) {
245
             return;
245
             return;
248
         NavigationApplication.instance.runOnMainThread(new Runnable() {
248
         NavigationApplication.instance.runOnMainThread(new Runnable() {
249
             @Override
249
             @Override
250
             public void run() {
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 Näytä tiedosto

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
     @Override
175
     @Override

+ 6
- 1
src/deprecated/platformSpecificDeprecated.android.js Näytä tiedosto

243
 }
243
 }
244
 
244
 
245
 function navigatorSwitchToTab(navigator, params) {
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
 function navigatorToggleDrawer(navigator, params) {
254
 function navigatorToggleDrawer(navigator, params) {

+ 8
- 3
src/platformSpecific.android.js Näytä tiedosto

92
   NativeReactModule.setSideMenuVisible(animated, visible);
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
 module.exports = {
103
 module.exports = {
111
   dismissAllModals,
115
   dismissAllModals,
112
   toggleSideMenuVisible,
116
   toggleSideMenuVisible,
113
   setSideMenuVisible,
117
   setSideMenuVisible,
114
-  selectBottomTab
118
+  selectBottomTabByNavigatorId,
119
+  selectBottomTabByTabIndex
115
 };
120
 };