Browse Source

[Android] TopTabs font family (#2342)

* Add topTabTextFontFamily style option

* Add topTabTextFontFamily sample usage to example project
Krystof Celba 7 years ago
parent
commit
119069777d

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

125
     public Font titleBarButtonFontFamily;
125
     public Font titleBarButtonFontFamily;
126
 
126
 
127
     public Color topTabTextColor;
127
     public Color topTabTextColor;
128
+    public Font topTabTextFontFamily;
128
     public Color topTabIconColor;
129
     public Color topTabIconColor;
129
     public Color selectedTopTabTextColor;
130
     public Color selectedTopTabTextColor;
130
     public Color selectedTopTabIconColor;
131
     public Color selectedTopTabIconColor;

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

71
         result.topTabsHidden = getBoolean("topTabsHidden", getDefaultTopTabsHidden());
71
         result.topTabsHidden = getBoolean("topTabsHidden", getDefaultTopTabsHidden());
72
 
72
 
73
         result.topTabTextColor = getColor("topTabTextColor", getDefaultTopTabTextColor());
73
         result.topTabTextColor = getColor("topTabTextColor", getDefaultTopTabTextColor());
74
+        result.topTabTextFontFamily = getFont("topTabTextFontFamily", getDefaultTopTabTextFontFamily());
74
         result.topTabIconColor = getColor("topTabIconColor", getDefaultTopTabIconColor());
75
         result.topTabIconColor = getColor("topTabIconColor", getDefaultTopTabIconColor());
75
         result.selectedTopTabIconColor = getColor("selectedTopTabIconColor", getDefaultSelectedTopTabIconColor());
76
         result.selectedTopTabIconColor = getColor("selectedTopTabIconColor", getDefaultSelectedTopTabIconColor());
76
         result.selectedTopTabTextColor = getColor("selectedTopTabTextColor", getDefaultSelectedTopTabTextColor());
77
         result.selectedTopTabTextColor = getColor("selectedTopTabTextColor", getDefaultSelectedTopTabTextColor());
125
         result.titleBarTitleFont = new StyleParams.Font();
126
         result.titleBarTitleFont = new StyleParams.Font();
126
         result.titleBarSubtitleFontFamily = new StyleParams.Font();
127
         result.titleBarSubtitleFontFamily = new StyleParams.Font();
127
         result.titleBarButtonFontFamily = new StyleParams.Font();
128
         result.titleBarButtonFontFamily = new StyleParams.Font();
129
+        result.topTabTextFontFamily = new StyleParams.Font();
128
         result.titleBarHeight = -1;
130
         result.titleBarHeight = -1;
129
         result.screenAnimationType = "slide-up";
131
         result.screenAnimationType = "slide-up";
130
         return result;
132
         return result;
306
         return AppStyle.appStyle == null ? new StyleParams.Font() : AppStyle.appStyle.titleBarSubtitleFontFamily;
308
         return AppStyle.appStyle == null ? new StyleParams.Font() : AppStyle.appStyle.titleBarSubtitleFontFamily;
307
     }
309
     }
308
 
310
 
311
+    private StyleParams.Font getDefaultTopTabTextFontFamily() {
312
+        return AppStyle.appStyle == null ? new StyleParams.Font() : AppStyle.appStyle.topTabTextFontFamily;
313
+    }
314
+
309
     private StyleParams.Font getDefaultTitleBarButtonFont() {
315
     private StyleParams.Font getDefaultTitleBarButtonFont() {
310
         return AppStyle.appStyle == null ? new StyleParams.Font() : AppStyle.appStyle.titleBarButtonFontFamily;
316
         return AppStyle.appStyle == null ? new StyleParams.Font() : AppStyle.appStyle.titleBarButtonFontFamily;
311
     }
317
     }

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

213
         topTabs.setTopTabsTextColor(style);
213
         topTabs.setTopTabsTextColor(style);
214
         topTabs.setSelectedTabIndicatorStyle(style);
214
         topTabs.setSelectedTabIndicatorStyle(style);
215
         topTabs.setScrollable(style);
215
         topTabs.setScrollable(style);
216
+        topTabs.setTopTabsTextFontFamily(style);
216
     }
217
     }
217
 
218
 
218
     public void showContextualMenu(final ContextualMenuParams params, StyleParams styleParams, Callback onButtonClicked) {
219
     public void showContextualMenu(final ContextualMenuParams params, StyleParams styleParams, Callback onButtonClicked) {

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

2
 
2
 
3
 import android.content.Context;
3
 import android.content.Context;
4
 import android.content.res.ColorStateList;
4
 import android.content.res.ColorStateList;
5
+import android.graphics.Typeface;
5
 import android.support.design.widget.TabLayout;
6
 import android.support.design.widget.TabLayout;
7
+import android.view.View;
8
+import android.view.ViewGroup;
9
+import android.widget.TextView;
6
 
10
 
7
 import com.reactnativenavigation.params.StyleParams;
11
 import com.reactnativenavigation.params.StyleParams;
8
 import com.reactnativenavigation.views.utils.TopTabsIconColorHelper;
12
 import com.reactnativenavigation.views.utils.TopTabsIconColorHelper;
39
         setTabTextColors(tabTextColor, selectedTabColor);
43
         setTabTextColors(tabTextColor, selectedTabColor);
40
     }
44
     }
41
 
45
 
46
+    void setTopTabsTextFontFamily(StyleParams style) {
47
+        if (style.topTabTextFontFamily.hasFont()) {
48
+            ViewGroup viewGroup = (ViewGroup) this.getChildAt(0);
49
+
50
+            for (int tab = 0; tab < viewGroup.getChildCount(); tab++) {
51
+                ViewGroup tabViewGroup = (ViewGroup) viewGroup.getChildAt(tab);
52
+
53
+                for (int i = 0; i < tabViewGroup.getChildCount(); i++) {
54
+                    View tabViewChild = tabViewGroup.getChildAt(i);
55
+                    if (tabViewChild instanceof TextView) {
56
+                        ((TextView) tabViewChild).setTypeface(
57
+                                style.topTabTextFontFamily.get(), Typeface.NORMAL);
58
+                    }
59
+                }
60
+            }
61
+        }
62
+    }
63
+
42
     void setScrollable(StyleParams style) {
64
     void setScrollable(StyleParams style) {
43
         if (style.topTabsScrollable) {
65
         if (style.topTabsScrollable) {
44
             setTabMode(TabLayout.MODE_SCROLLABLE);
66
             setTabMode(TabLayout.MODE_SCROLLABLE);

+ 1
- 0
example/src/screens/types/TopTabs.js View File

4
 class TopTabs extends React.Component {
4
 class TopTabs extends React.Component {
5
   static navigatorStyle = {
5
   static navigatorStyle = {
6
     topTabTextColor: '#ffffff',
6
     topTabTextColor: '#ffffff',
7
+    topTabTextFontFamily: 'BioRhyme-Bold',
7
     selectedTopTabTextColor: '#ff505c',
8
     selectedTopTabTextColor: '#ff505c',
8
 
9
 
9
     // Icons
10
     // Icons

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

190
     drawBelowTopBar: !originalStyleObject.drawUnderNavBar,
190
     drawBelowTopBar: !originalStyleObject.drawUnderNavBar,
191
 
191
 
192
     topTabTextColor: processColor(originalStyleObject.topTabTextColor),
192
     topTabTextColor: processColor(originalStyleObject.topTabTextColor),
193
+    topTabTextFontFamily: originalStyleObject.topTabTextFontFamily,
193
     topTabIconColor: processColor(originalStyleObject.topTabIconColor),
194
     topTabIconColor: processColor(originalStyleObject.topTabIconColor),
194
     selectedTopTabIconColor: processColor(originalStyleObject.selectedTopTabIconColor),
195
     selectedTopTabIconColor: processColor(originalStyleObject.selectedTopTabIconColor),
195
     selectedTopTabTextColor: processColor(originalStyleObject.selectedTopTabTextColor),
196
     selectedTopTabTextColor: processColor(originalStyleObject.selectedTopTabTextColor),