Browse Source

[android] Add option for scrollable top tabs (#669)

Jakub Martyčák 7 years ago
parent
commit
a650743086

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

@@ -62,6 +62,7 @@ public class StyleParams {
62 62
     public Color selectedTopTabIconColor;
63 63
     public int selectedTopTabIndicatorHeight;
64 64
     public Color selectedTopTabIndicatorColor;
65
+    public boolean topTabScrollable;
65 66
 
66 67
     public Color screenBackgroundColor;
67 68
 

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

@@ -50,6 +50,7 @@ public class StyleParamsParser {
50 50
         result.selectedTopTabTextColor = getColor("selectedTopTabTextColor", getDefaultSelectedTopTabTextColor());
51 51
         result.selectedTopTabIndicatorHeight = getInt("selectedTopTabIndicatorHeight", getDefaultSelectedTopTabIndicatorHeight());
52 52
         result.selectedTopTabIndicatorColor = getColor("selectedTopTabIndicatorColor", getDefaultSelectedTopTabIndicatorColor());
53
+        result.topTabScrollable = getBoolean("topTabScrollable", getDefaultTopTabScrollable());
53 54
 
54 55
         result.screenBackgroundColor = getColor("screenBackgroundColor", getDefaultScreenBackgroundColor());
55 56
 
@@ -165,6 +166,10 @@ public class StyleParamsParser {
165 166
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.topTabTextColor;
166 167
     }
167 168
 
169
+    private boolean getDefaultTopTabScrollable() {
170
+        return AppStyle.appStyle != null && AppStyle.appStyle.topTabScrollable;
171
+    }
172
+
168 173
     private StyleParams.Color getDefaultTopTabIconColor() {
169 174
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.topTabIconColor;
170 175
     }

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/views/TopBar.java View File

@@ -116,6 +116,7 @@ public class TopBar extends AppBarLayout {
116 116
         }
117 117
         topTabs.setTopTabsTextColor(style);
118 118
         topTabs.setSelectedTabIndicatorStyle(style);
119
+        topTabs.setScrollable(style);
119 120
     }
120 121
 
121 122
     public void showContextualMenu(final ContextualMenuParams params, StyleParams styleParams, Callback onButtonClicked) {

+ 8
- 0
android/app/src/main/java/com/reactnativenavigation/views/TopTabs.java View File

@@ -39,6 +39,14 @@ public class TopTabs extends TabLayout {
39 39
         setTabTextColors(tabTextColor, selectedTabColor);
40 40
     }
41 41
 
42
+    void setScrollable(StyleParams style) {
43
+        if (style.topTabScrollable) {
44
+            setTabMode(TabLayout.MODE_SCROLLABLE);
45
+        } else {
46
+            setTabMode(TabLayout.MODE_FIXED);
47
+        }
48
+    }
49
+
42 50
     public void setTopTabsIconColor(StyleParams style) {
43 51
         new TopTabsIconColorHelper(this, style).colorIcons(getSelectedIconColor(), getUnselectedIconColor());
44 52
     }

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

@@ -151,7 +151,7 @@ function convertStyleParams(originalStyleObject) {
151 151
     selectedTopTabTextColor: processColor(originalStyleObject.selectedTopTabTextColor),
152 152
     selectedTopTabIndicatorHeight: originalStyleObject.selectedTopTabIndicatorHeight,
153 153
     selectedTopTabIndicatorColor: processColor(originalStyleObject.selectedTopTabIndicatorColor),
154
-
154
+    topTabScrollable: originalStyleObject.topTabScollable,
155 155
     screenBackgroundColor: processColor(originalStyleObject.screenBackgroundColor),
156 156
 
157 157
     drawScreenAboveBottomTabs: !originalStyleObject.drawUnderTabBar,