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
 
344
 
345
     public void selectBottomTabByTabIndex(Integer index) {
345
     public void selectBottomTabByTabIndex(Integer index) {
346
         if (bottomTabs.getCurrentItem() != index) {
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
         }
479
         }
479
 
480
 
480
         final int unselectedTabIndex = currentStackIndex;
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
         sendTabSelectedEventToJs(position, unselectedTabIndex);
483
         sendTabSelectedEventToJs(position, unselectedTabIndex);
485
         return true;
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
     private void sendTabSelectedEventToJs(int selectedTabIndex, int unselectedTabIndex) {
493
     private void sendTabSelectedEventToJs(int selectedTabIndex, int unselectedTabIndex) {
489
         String navigatorEventId = getCurrentScreenStack().peek().getNavigatorEventId();
494
         String navigatorEventId = getCurrentScreenStack().peek().getNavigatorEventId();
490
         WritableMap data = createTabSelectedEventData(selectedTabIndex, unselectedTabIndex);
495
         WritableMap data = createTabSelectedEventData(selectedTabIndex, unselectedTabIndex);

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

4
     Push,
4
     Push,
5
     Pop,
5
     Pop,
6
     BottomTabSelected,
6
     BottomTabSelected,
7
+    SwitchToTab,
7
     TopTabSelected,
8
     TopTabSelected,
8
     InitialScreen,
9
     InitialScreen,
9
     ShowModal,
10
     ShowModal,

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

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