瀏覽代碼

Don't crash when selecting BottomTab by navigatorId if ScreenStack was not found

Guy Carmeli 7 年之前
父節點
當前提交
82e68cee70
共有 1 個檔案被更改,包括 8 行新增1 行删除
  1. 8
    1
      android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java

+ 8
- 1
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java 查看文件

@@ -6,6 +6,7 @@ import android.support.annotation.NonNull;
6 6
 import android.support.annotation.Nullable;
7 7
 import android.support.v4.widget.DrawerLayout;
8 8
 import android.support.v7.app.AppCompatActivity;
9
+import android.util.Log;
9 10
 import android.view.View;
10 11
 import android.widget.RelativeLayout;
11 12
 
@@ -333,7 +334,13 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
333 334
     }
334 335
 
335 336
     public void selectBottomTabByNavigatorId(String navigatorId) {
336
-        bottomTabs.setCurrentItem(getScreenStackIndex(navigatorId));
337
+        try {
338
+            bottomTabs.setCurrentItem(getScreenStackIndex(navigatorId));
339
+        } catch (ScreenStackNotFoundException e) {
340
+            Log.e("BottomTabsLayout", "Could not select bottom tab by navigatorId [" + navigatorId + "]." +
341
+                                      "This should not have happened, it probably means navigator.switchToTab()" +
342
+                                      "was called from an unmounted tab.");
343
+        }
337 344
     }
338 345
 
339 346
     private boolean hasBackgroundColor(StyleParams params) {