Sfoglia il codice sorgente

Handle initialTabIndex in AppStyle and TabStyle

Guy Carmeli 7 anni fa
parent
commit
eb36b833f2

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

@@ -17,6 +17,7 @@ import com.reactnativenavigation.NavigationApplication;
17 17
 import com.reactnativenavigation.events.EventBus;
18 18
 import com.reactnativenavigation.events.ScreenChangedEvent;
19 19
 import com.reactnativenavigation.params.ActivityParams;
20
+import com.reactnativenavigation.params.AppStyle;
20 21
 import com.reactnativenavigation.params.ContextualMenuParams;
21 22
 import com.reactnativenavigation.params.FabParams;
22 23
 import com.reactnativenavigation.params.LightBoxParams;
@@ -80,10 +81,7 @@ public class BottomTabsLayout extends BaseLayout implements AHBottomNavigation.O
80 81
     }
81 82
 
82 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 87
     private void createSideMenu() {

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

@@ -12,6 +12,5 @@ public class ActivityParams {
12 12
     public List<ScreenParams> tabParams;
13 13
     public SideMenuParams leftSideMenuParams;
14 14
     public SideMenuParams rightSideMenuParams;
15
-    public Integer initialTabIndex;
16 15
     public boolean animateShow;
17 16
 }

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

@@ -116,6 +116,7 @@ public class StyleParams {
116 116
 
117 117
     public Color snackbarButtonColor;
118 118
 
119
+    public int bottomTabsInitialIndex;
119 120
     public boolean bottomTabsHidden;
120 121
     public boolean bottomTabsHiddenOnScroll;
121 122
     public Color bottomTabsColor;

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

@@ -30,7 +30,6 @@ public class ActivityParamsParser extends Parser {
30 30
         }
31 31
 
32 32
         result.animateShow = params.getBoolean("animateShow", true);
33
-        result.initialTabIndex = params.getInt("initialTabIndex");
34 33
 
35 34
         return result;
36 35
     }

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

@@ -69,6 +69,7 @@ public class StyleParamsParser {
69 69
 
70 70
         result.screenBackgroundColor = getColor("screenBackgroundColor", getDefaultScreenBackgroundColor());
71 71
 
72
+        result.bottomTabsInitialIndex = getInt("initialTabIndex", 0);
72 73
         result.bottomTabsHidden = getBoolean("bottomTabsHidden", getDefaultBottomTabsHidden());
73 74
         result.drawScreenAboveBottomTabs = !result.bottomTabsHidden &&
74 75
                                            params.getBoolean("drawScreenAboveBottomTabs", getDefaultDrawScreenAboveBottomTabs());

+ 6
- 5
ios/RCCTabBarController.m Vedi File

@@ -219,11 +219,12 @@
219 219
   // replace the tabs
220 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 229
   [self setRotation:props];
229 230
   

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

@@ -183,6 +183,7 @@ function convertStyleParams(originalStyleObject) {
183 183
 
184 184
     drawScreenAboveBottomTabs: !originalStyleObject.drawUnderTabBar,
185 185
 
186
+    initialTabIndex: originalStyleObject.initialTabIndex,
186 187
     bottomTabsColor: processColor(originalStyleObject.tabBarBackgroundColor),
187 188
     bottomTabsButtonColor: processColor(originalStyleObject.tabBarButtonColor),
188 189
     bottomTabsSelectedButtonColor: processColor(originalStyleObject.tabBarSelectedButtonColor),