Browse Source

Handle initialTabIndex in AppStyle and TabStyle

Guy Carmeli 7 years ago
parent
commit
eb36b833f2

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

17
 import com.reactnativenavigation.events.EventBus;
17
 import com.reactnativenavigation.events.EventBus;
18
 import com.reactnativenavigation.events.ScreenChangedEvent;
18
 import com.reactnativenavigation.events.ScreenChangedEvent;
19
 import com.reactnativenavigation.params.ActivityParams;
19
 import com.reactnativenavigation.params.ActivityParams;
20
+import com.reactnativenavigation.params.AppStyle;
20
 import com.reactnativenavigation.params.ContextualMenuParams;
21
 import com.reactnativenavigation.params.ContextualMenuParams;
21
 import com.reactnativenavigation.params.FabParams;
22
 import com.reactnativenavigation.params.FabParams;
22
 import com.reactnativenavigation.params.LightBoxParams;
23
 import com.reactnativenavigation.params.LightBoxParams;
80
     }
81
     }
81
 
82
 
82
     private void setInitialTabIndex() {
83
     private void setInitialTabIndex() {
83
-        if (params.initialTabIndex == null) {
84
-            return;
85
-        }
86
-        bottomTabs.setCurrentItem(params.initialTabIndex);
84
+        bottomTabs.setCurrentItem(AppStyle.appStyle.bottomTabsInitialIndex);
87
     }
85
     }
88
 
86
 
89
     private void createSideMenu() {
87
     private void createSideMenu() {

+ 0
- 1
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;
16
     public boolean animateShow;
15
     public boolean animateShow;
17
 }
16
 }

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

116
 
116
 
117
     public Color snackbarButtonColor;
117
     public Color snackbarButtonColor;
118
 
118
 
119
+    public int bottomTabsInitialIndex;
119
     public boolean bottomTabsHidden;
120
     public boolean bottomTabsHidden;
120
     public boolean bottomTabsHiddenOnScroll;
121
     public boolean bottomTabsHiddenOnScroll;
121
     public Color bottomTabsColor;
122
     public Color bottomTabsColor;

+ 0
- 1
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");
34
 
33
 
35
         return result;
34
         return result;
36
     }
35
     }

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

69
 
69
 
70
         result.screenBackgroundColor = getColor("screenBackgroundColor", getDefaultScreenBackgroundColor());
70
         result.screenBackgroundColor = getColor("screenBackgroundColor", getDefaultScreenBackgroundColor());
71
 
71
 
72
+        result.bottomTabsInitialIndex = getInt("initialTabIndex", 0);
72
         result.bottomTabsHidden = getBoolean("bottomTabsHidden", getDefaultBottomTabsHidden());
73
         result.bottomTabsHidden = getBoolean("bottomTabsHidden", getDefaultBottomTabsHidden());
73
         result.drawScreenAboveBottomTabs = !result.bottomTabsHidden &&
74
         result.drawScreenAboveBottomTabs = !result.bottomTabsHidden &&
74
                                            params.getBoolean("drawScreenAboveBottomTabs", getDefaultDrawScreenAboveBottomTabs());
75
                                            params.getBoolean("drawScreenAboveBottomTabs", getDefaultDrawScreenAboveBottomTabs());

+ 6
- 5
ios/RCCTabBarController.m View File

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

+ 1
- 0
src/deprecated/platformSpecificDeprecated.android.js View File

183
 
183
 
184
     drawScreenAboveBottomTabs: !originalStyleObject.drawUnderTabBar,
184
     drawScreenAboveBottomTabs: !originalStyleObject.drawUnderTabBar,
185
 
185
 
186
+    initialTabIndex: originalStyleObject.initialTabIndex,
186
     bottomTabsColor: processColor(originalStyleObject.tabBarBackgroundColor),
187
     bottomTabsColor: processColor(originalStyleObject.tabBarBackgroundColor),
187
     bottomTabsButtonColor: processColor(originalStyleObject.tabBarButtonColor),
188
     bottomTabsButtonColor: processColor(originalStyleObject.tabBarButtonColor),
188
     bottomTabsSelectedButtonColor: processColor(originalStyleObject.tabBarSelectedButtonColor),
189
     bottomTabsSelectedButtonColor: processColor(originalStyleObject.tabBarSelectedButtonColor),