Browse Source

[iOS/Android] Add initialTabIndex support (#1674)

* Add initialTabIndex support to RCCTabBarController

* Add initialTabIndex support to BottomTabsLayout
Eliasz Sawicki 7 years ago
parent
commit
bb584ff341

+ 8
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java View File

76
         addScreenStacks();
76
         addScreenStacks();
77
         createSnackbarContainer();
77
         createSnackbarContainer();
78
         showInitialScreenStack();
78
         showInitialScreenStack();
79
+        setInitialTabIndex();
80
+    }
81
+
82
+    private void setInitialTabIndex() {
83
+        if (params.initialTabIndex == null) {
84
+            return;
85
+        }
86
+        bottomTabs.setCurrentItem(params.initialTabIndex);
79
     }
87
     }
80
 
88
 
81
     private void createSideMenu() {
89
     private void createSideMenu() {

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/ActivityParams.java View File

12
     public List<ScreenParams> tabParams;
12
     public List<ScreenParams> tabParams;
13
     public SideMenuParams leftSideMenuParams;
13
     public SideMenuParams leftSideMenuParams;
14
     public SideMenuParams rightSideMenuParams;
14
     public SideMenuParams rightSideMenuParams;
15
+    public Integer initialTabIndex;
15
     public boolean animateShow;
16
     public boolean animateShow;
16
 }
17
 }

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/ActivityParamsParser.java View File

30
         }
30
         }
31
 
31
 
32
         result.animateShow = params.getBoolean("animateShow", true);
32
         result.animateShow = params.getBoolean("animateShow", true);
33
+        result.initialTabIndex = params.getInt("initialTabIndex");
33
 
34
 
34
         return result;
35
         return result;
35
     }
36
     }

+ 6
- 0
ios/RCCTabBarController.m View File

218
   
218
   
219
   // replace the tabs
219
   // replace the tabs
220
   self.viewControllers = viewControllers;
220
   self.viewControllers = viewControllers;
221
+
222
+  
223
+   NSUInteger *initialTabIndex = [props[@"initialTabIndex"] unsignedIntegerValue];
224
+   if (initialTabIndex && initialTabIndex < viewControllers.count) {
225
+      [self setSelectedIndex:initialTabIndex];
226
+   }
221
   
227
   
222
   [self setRotation:props];
228
   [self setRotation:props];
223
   
229
   

+ 2
- 1
src/deprecated/platformSpecificDeprecated.ios.js View File

68
         <TabBarControllerIOS
68
         <TabBarControllerIOS
69
           id={controllerID + '_tabs'}
69
           id={controllerID + '_tabs'}
70
           style={params.tabsStyle}
70
           style={params.tabsStyle}
71
-          appStyle={params.appStyle}>
71
+          appStyle={params.appStyle}
72
+          initialTabIndex={params.initialTabIndex}>
72
           {
73
           {
73
             params.tabs.map(function(tab, index) {
74
             params.tabs.map(function(tab, index) {
74
               return (
75
               return (