Procházet zdrojové kódy

[Android] TopTabs font family (#2342)

* Add topTabTextFontFamily style option

* Add topTabTextFontFamily sample usage to example project
Krystof Celba před 7 roky
rodič
revize
119069777d

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java Zobrazit soubor

@@ -125,6 +125,7 @@ public class StyleParams {
125 125
     public Font titleBarButtonFontFamily;
126 126
 
127 127
     public Color topTabTextColor;
128
+    public Font topTabTextFontFamily;
128 129
     public Color topTabIconColor;
129 130
     public Color selectedTopTabTextColor;
130 131
     public Color selectedTopTabIconColor;

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

@@ -71,6 +71,7 @@ public class StyleParamsParser {
71 71
         result.topTabsHidden = getBoolean("topTabsHidden", getDefaultTopTabsHidden());
72 72
 
73 73
         result.topTabTextColor = getColor("topTabTextColor", getDefaultTopTabTextColor());
74
+        result.topTabTextFontFamily = getFont("topTabTextFontFamily", getDefaultTopTabTextFontFamily());
74 75
         result.topTabIconColor = getColor("topTabIconColor", getDefaultTopTabIconColor());
75 76
         result.selectedTopTabIconColor = getColor("selectedTopTabIconColor", getDefaultSelectedTopTabIconColor());
76 77
         result.selectedTopTabTextColor = getColor("selectedTopTabTextColor", getDefaultSelectedTopTabTextColor());
@@ -125,6 +126,7 @@ public class StyleParamsParser {
125 126
         result.titleBarTitleFont = new StyleParams.Font();
126 127
         result.titleBarSubtitleFontFamily = new StyleParams.Font();
127 128
         result.titleBarButtonFontFamily = new StyleParams.Font();
129
+        result.topTabTextFontFamily = new StyleParams.Font();
128 130
         result.titleBarHeight = -1;
129 131
         result.screenAnimationType = "slide-up";
130 132
         return result;
@@ -306,6 +308,10 @@ public class StyleParamsParser {
306 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 315
     private StyleParams.Font getDefaultTitleBarButtonFont() {
310 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 Zobrazit soubor

@@ -213,6 +213,7 @@ public class TopBar extends AppBarLayout {
213 213
         topTabs.setTopTabsTextColor(style);
214 214
         topTabs.setSelectedTabIndicatorStyle(style);
215 215
         topTabs.setScrollable(style);
216
+        topTabs.setTopTabsTextFontFamily(style);
216 217
     }
217 218
 
218 219
     public void showContextualMenu(final ContextualMenuParams params, StyleParams styleParams, Callback onButtonClicked) {

+ 22
- 0
android/app/src/main/java/com/reactnativenavigation/views/TopTabs.java Zobrazit soubor

@@ -2,7 +2,11 @@ package com.reactnativenavigation.views;
2 2
 
3 3
 import android.content.Context;
4 4
 import android.content.res.ColorStateList;
5
+import android.graphics.Typeface;
5 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 11
 import com.reactnativenavigation.params.StyleParams;
8 12
 import com.reactnativenavigation.views.utils.TopTabsIconColorHelper;
@@ -39,6 +43,24 @@ public class TopTabs extends TabLayout {
39 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 64
     void setScrollable(StyleParams style) {
43 65
         if (style.topTabsScrollable) {
44 66
             setTabMode(TabLayout.MODE_SCROLLABLE);

+ 1
- 0
example/src/screens/types/TopTabs.js Zobrazit soubor

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

+ 1
- 0
src/deprecated/platformSpecificDeprecated.android.js Zobrazit soubor

@@ -190,6 +190,7 @@ function convertStyleParams(originalStyleObject) {
190 190
     drawBelowTopBar: !originalStyleObject.drawUnderNavBar,
191 191
 
192 192
     topTabTextColor: processColor(originalStyleObject.topTabTextColor),
193
+    topTabTextFontFamily: originalStyleObject.topTabTextFontFamily,
193 194
     topTabIconColor: processColor(originalStyleObject.topTabIconColor),
194 195
     selectedTopTabIconColor: processColor(originalStyleObject.selectedTopTabIconColor),
195 196
     selectedTopTabTextColor: processColor(originalStyleObject.selectedTopTabTextColor),