Преглед изворни кода

Add support in switchToTab() with no parameters

Amit Davidi пре 8 година
родитељ
комит
3c154f8203

+ 2
- 0
android/app/src/main/java/com/reactnativenavigation/activities/BaseReactActivity.java Прегледај датотеку

@@ -59,6 +59,8 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
59 59
     protected static final String KEY_TAB_INDEX = "tabIndex";
60 60
     protected static final String KEY_TITLE = "title";
61 61
     protected static final String KEY_TO = "to";
62
+    protected static final String KEY_NAVIGATOR_ID = "navigatorID";
63
+
62 64
     private static final String TAG = "BaseReactActivity";
63 65
     private static final String REDBOX_PERMISSION_MESSAGE =
64 66
             "Overlay permissions needs to be granted in order for react native apps to run in dev mode";

+ 19
- 1
android/app/src/main/java/com/reactnativenavigation/activities/BottomTabActivity.java Прегледај датотеку

@@ -212,7 +212,13 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
212 212
     }
213 213
 
214 214
     public void switchToTab(ReadableMap params) {
215
-        int tabIndex = params.getInt(KEY_TAB_INDEX);
215
+        Integer tabIndex;
216
+        if (params.hasKey(KEY_TAB_INDEX)) {
217
+            tabIndex = params.getInt(KEY_TAB_INDEX);
218
+        } else {
219
+            final String navigatorId = params.getString(KEY_NAVIGATOR_ID);
220
+            tabIndex = findNavigatorTabIndex(navigatorId);
221
+        }
216 222
         mBottomNavigation.setCurrentItem(tabIndex);
217 223
     }
218 224
 
@@ -255,6 +261,17 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
255 261
         }
256 262
     }
257 263
 
264
+    protected Integer findNavigatorTabIndex(String navigatorId) {
265
+        for (int i = 0; i < mScreenStacks.size(); i++) {
266
+            ScreenStack stack = mScreenStacks.get(i);
267
+            if (!stack.isEmpty() && stack.peek().navigatorId.equals(navigatorId)) {
268
+                return i;
269
+            }
270
+        }
271
+
272
+        return null;
273
+    }
274
+
258 275
     private void setTabsWithIcons(ArrayList<Screen> screens, Map<Screen, Drawable> icons) {
259 276
         mScreenStacks = new ArrayList<>();
260 277
         for (Screen screen : screens) {
@@ -268,6 +285,7 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
268 285
         this.onTabSelected(0, false);
269 286
     }
270 287
 
288
+
271 289
     @Override
272 290
     protected void removeAllReactViews() {
273 291
         for (ScreenStack screenStack : mScreenStacks) {

+ 1
- 0
src/platformSpecific.android.js Прегледај датотеку

@@ -99,6 +99,7 @@ function navigatorSetTitle(navigator, params) {
99 99
 
100 100
 function navigatorSwitchToTab(navigator, params) {
101 101
   RctActivity.switchToTab({
102
+    navigatorID: navigator.navigatorID,
102 103
     tabIndex: params.tabIndex
103 104
   });
104 105
 }