From 6bfcf16bc47a9fd1c67cb8ebfe84bc0f51de9d0c Mon Sep 17 00:00:00 2001 From: Khoa Luu Date: Sat, 14 Oct 2023 17:38:07 +0700 Subject: [PATCH] fix: Tab index out of number of tabs range --- .../viewcontrollers/bottomtabs/BottomTabsController.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsController.java b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsController.java index e61df575d94..67271a2763c 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsController.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsController.java @@ -269,10 +269,11 @@ public void selectTab(final int newIndex) { } private void selectTab(int newIndex, boolean enableSelectionHistory) { - saveTabSelection(newIndex, enableSelectionHistory); - tabsAttacher.onTabSelected(tabs.get(newIndex)); + final int nextIndex = Math.max(0, Math.min(newIndex, tabs.size() - 1)); + saveTabSelection(nextIndex, enableSelectionHistory); + tabsAttacher.onTabSelected(tabs.get(nextIndex)); getCurrentView().setVisibility(View.INVISIBLE); - bottomTabs.setCurrentItem(newIndex, false); + bottomTabs.setCurrentItem(nextIndex, false); getCurrentView().setVisibility(View.VISIBLE); getCurrentChild().onViewWillAppear(); getCurrentChild().onViewDidAppear();