Browse Source

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

Jakub Martyčák 8 years ago
parent
commit
a650743086

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

62
     public Color selectedTopTabIconColor;
62
     public Color selectedTopTabIconColor;
63
     public int selectedTopTabIndicatorHeight;
63
     public int selectedTopTabIndicatorHeight;
64
     public Color selectedTopTabIndicatorColor;
64
     public Color selectedTopTabIndicatorColor;
65
+    public boolean topTabScrollable;
65
 
66
 
66
     public Color screenBackgroundColor;
67
     public Color screenBackgroundColor;
67
 
68
 

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

50
         result.selectedTopTabTextColor = getColor("selectedTopTabTextColor", getDefaultSelectedTopTabTextColor());
50
         result.selectedTopTabTextColor = getColor("selectedTopTabTextColor", getDefaultSelectedTopTabTextColor());
51
         result.selectedTopTabIndicatorHeight = getInt("selectedTopTabIndicatorHeight", getDefaultSelectedTopTabIndicatorHeight());
51
         result.selectedTopTabIndicatorHeight = getInt("selectedTopTabIndicatorHeight", getDefaultSelectedTopTabIndicatorHeight());
52
         result.selectedTopTabIndicatorColor = getColor("selectedTopTabIndicatorColor", getDefaultSelectedTopTabIndicatorColor());
52
         result.selectedTopTabIndicatorColor = getColor("selectedTopTabIndicatorColor", getDefaultSelectedTopTabIndicatorColor());
53
+        result.topTabScrollable = getBoolean("topTabScrollable", getDefaultTopTabScrollable());
53
 
54
 
54
         result.screenBackgroundColor = getColor("screenBackgroundColor", getDefaultScreenBackgroundColor());
55
         result.screenBackgroundColor = getColor("screenBackgroundColor", getDefaultScreenBackgroundColor());
55
 
56
 
165
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.topTabTextColor;
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
     private StyleParams.Color getDefaultTopTabIconColor() {
173
     private StyleParams.Color getDefaultTopTabIconColor() {
169
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.topTabIconColor;
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
         }
116
         }
117
         topTabs.setTopTabsTextColor(style);
117
         topTabs.setTopTabsTextColor(style);
118
         topTabs.setSelectedTabIndicatorStyle(style);
118
         topTabs.setSelectedTabIndicatorStyle(style);
119
+        topTabs.setScrollable(style);
119
     }
120
     }
120
 
121
 
121
     public void showContextualMenu(final ContextualMenuParams params, StyleParams styleParams, Callback onButtonClicked) {
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
         setTabTextColors(tabTextColor, selectedTabColor);
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
     public void setTopTabsIconColor(StyleParams style) {
50
     public void setTopTabsIconColor(StyleParams style) {
43
         new TopTabsIconColorHelper(this, style).colorIcons(getSelectedIconColor(), getUnselectedIconColor());
51
         new TopTabsIconColorHelper(this, style).colorIcons(getSelectedIconColor(), getUnselectedIconColor());
44
     }
52
     }

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

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