浏览代码

Added ability to specify font size for tab bar labels on Android (#2754)

* Added bottomTabFontSize and bottomTabSelectedFontSize properties for android tab bar

* Added tabFontSize and selectedTabFontSize properties to the doc

* Fix default values of bottomTabFontSize and bottomTabSelectedFontSize properties.
Alexey 6 年前
父节点
当前提交
993992daf7

+ 2
- 0
android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java 查看文件

@@ -152,6 +152,8 @@ public class StyleParams {
152 152
     public Color bottomTabBadgeTextColor;
153 153
     public Color bottomTabBadgeBackgroundColor;
154 154
     public Font bottomTabFontFamily;
155
+    public Integer bottomTabFontSize;
156
+    public Integer bottomTabSelectedFontSize;
155 157
 
156 158
     public Color navigationBarColor;
157 159
 

+ 8
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/StyleParamsParser.java 查看文件

@@ -102,6 +102,8 @@ public class StyleParamsParser {
102 102
         result.forceTitlesDisplay = getBoolean("forceTitlesDisplay", getDefaultForceTitlesDisplay());
103 103
 
104 104
         result.bottomTabFontFamily = getFont("bottomTabFontFamily", getDefaultBottomTabsFontFamily());
105
+        result.bottomTabFontSize = getIntegerOrNull("bottomTabFontSize");
106
+        result.bottomTabSelectedFontSize = getIntegerOrNull("bottomTabSelectedFontSize");
105 107
 
106 108
         return result;
107 109
     }
@@ -125,6 +127,8 @@ public class StyleParamsParser {
125 127
         result.titleBarHideOnScroll = false;
126 128
         result.orientation = Orientation.auto;
127 129
         result.bottomTabFontFamily = new StyleParams.Font();
130
+        result.bottomTabFontSize = 10;
131
+        result.bottomTabSelectedFontSize = 10;
128 132
         result.titleBarTitleFont = new StyleParams.Font();
129 133
         result.titleBarSubtitleFontFamily = new StyleParams.Font();
130 134
         result.titleBarButtonFontFamily = new StyleParams.Font();
@@ -361,6 +365,10 @@ public class StyleParamsParser {
361 365
         return params.containsKey(key) ? params.getInt(key) : defaultValue;
362 366
     }
363 367
 
368
+    private Integer getIntegerOrNull(String key) {
369
+        return params.containsKey(key) ? params.getInt(key) : null;
370
+    }
371
+
364 372
     private Bundle getBundle(String key) {
365 373
         return params.containsKey(key) ? params.getBundle(key) : Bundle.EMPTY;
366 374
     }

+ 7
- 0
android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java 查看文件

@@ -26,6 +26,7 @@ public class BottomTabs extends AHBottomNavigation {
26 26
         createVisibilityAnimator();
27 27
         setStyle();
28 28
         setFontFamily();
29
+        setFontSize();
29 30
     }
30 31
 
31 32
     public void addTabs(List<ScreenParams> params, OnTabSelectedListener onTabSelectedListener) {
@@ -156,4 +157,10 @@ public class BottomTabs extends AHBottomNavigation {
156 157
             setTitleTypeface(AppStyle.appStyle.bottomTabFontFamily.get());
157 158
         }
158 159
     }
160
+
161
+    private void setFontSize() {
162
+        if(AppStyle.appStyle.bottomTabSelectedFontSize != null &&  AppStyle.appStyle.bottomTabFontSize != null) {
163
+            setTitleTextSizeInSp(AppStyle.appStyle.bottomTabSelectedFontSize, AppStyle.appStyle.bottomTabFontSize);
164
+        }
165
+    }
159 166
 }

+ 2
- 2
android/gradle/wrapper/gradle-wrapper.properties 查看文件

@@ -1,6 +1,6 @@
1
-#Mon Sep 12 16:05:44 IDT 2016
1
+#Mon Feb 19 11:46:35 EET 2018
2 2
 distributionBase=GRADLE_USER_HOME
3 3
 distributionPath=wrapper/dists
4 4
 zipStoreBase=GRADLE_USER_HOME
5 5
 zipStorePath=wrapper/dists
6
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip
6
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

+ 3
- 1
docs/styling-the-tab-bar.md 查看文件

@@ -38,7 +38,9 @@ Navigation.startTabBasedApp({
38 38
     tabBarButtonColor: '#ffffff',
39 39
     tabBarSelectedButtonColor: '#63d7cc',
40 40
     tabBarTranslucent: false,
41
-    tabFontFamily: 'Avenir-Medium'  // existing font family name or asset file without extension which can be '.ttf' or '.otf' (searched only if '.ttf' asset not found)
41
+    tabFontFamily: 'Avenir-Medium',  // existing font family name or asset file without extension which can be '.ttf' or '.otf' (searched only if '.ttf' asset not found)
42
+    tabFontSize: 10,
43
+    selectedTabFontSize: 12,
42 44
   },
43 45
 ...
44 46
 }

+ 2
- 0
src/deprecated/platformSpecificDeprecated.android.js 查看文件

@@ -227,6 +227,8 @@ function convertStyleParams(originalStyleObject) {
227 227
     bottomTabBadgeTextColor: processColor(originalStyleObject.bottomTabBadgeTextColor),
228 228
     bottomTabBadgeBackgroundColor: processColor(originalStyleObject.bottomTabBadgeBackgroundColor),
229 229
     bottomTabFontFamily: originalStyleObject.tabFontFamily,
230
+    bottomTabFontSize: originalStyleObject.tabFontSize,
231
+    bottomTabSelectedFontSize: originalStyleObject.selectedTabFontSize,
230 232
 
231 233
     navigationBarColor: processColor(originalStyleObject.navigationBarColor)
232 234
   };