Browse Source

Send tabSelected events to Js only if tab was selected by user (#2158)

Guy Carmeli 7 years ago
parent
commit
2065899601
No account linked to committer's email address

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

@@ -344,7 +344,8 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
344 344
 
345 345
     public void selectBottomTabByTabIndex(Integer index) {
346 346
         if (bottomTabs.getCurrentItem() != index) {
347
-            bottomTabs.setCurrentItem(index);
347
+            bottomTabs.setCurrentItemWithoutInvokingTabSelectedListener(index);
348
+            switchTab(index, NavigationType.SwitchToTab);
348 349
         }
349 350
     }
350 351
 
@@ -478,13 +479,17 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
478 479
         }
479 480
 
480 481
         final int unselectedTabIndex = currentStackIndex;
481
-        hideCurrentStack();
482
-        showNewStack(position, NavigationType.BottomTabSelected);
483
-        EventBus.instance.post(new ScreenChangedEvent(getCurrentScreenStack().peek().getScreenParams()));
482
+        switchTab(position, NavigationType.BottomTabSelected);
484 483
         sendTabSelectedEventToJs(position, unselectedTabIndex);
485 484
         return true;
486 485
     }
487 486
 
487
+    private void switchTab(int position, NavigationType navigationType) {
488
+        hideCurrentStack();
489
+        showNewStack(position, navigationType);
490
+        EventBus.instance.post(new ScreenChangedEvent(getCurrentScreenStack().peek().getScreenParams()));
491
+    }
492
+
488 493
     private void sendTabSelectedEventToJs(int selectedTabIndex, int unselectedTabIndex) {
489 494
         String navigatorEventId = getCurrentScreenStack().peek().getNavigatorEventId();
490 495
         WritableMap data = createTabSelectedEventData(selectedTabIndex, unselectedTabIndex);

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/screens/NavigationType.java View File

@@ -4,6 +4,7 @@ public enum NavigationType {
4 4
     Push,
5 5
     Pop,
6 6
     BottomTabSelected,
7
+    SwitchToTab,
7 8
     TopTabSelected,
8 9
     InitialScreen,
9 10
     ShowModal,

+ 4
- 0
android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java View File

@@ -96,6 +96,10 @@ public class BottomTabs extends AHBottomNavigation {
96 96
         }
97 97
     }
98 98
 
99
+    public void setCurrentItemWithoutInvokingTabSelectedListener(Integer index) {
100
+        setCurrentItem(index, false);
101
+    }
102
+
99 103
     private void setBackgroundColor(StyleParams.Color bottomTabsColor) {
100 104
         if (bottomTabsColor.hasColor()) {
101 105
             if (bottomTabsColor.getColor() != getDefaultBackgroundColor()) {