Sfoglia il codice sorgente

Support setting button font family on Android

Until now, buttons would use the same font family used by the title,
this commit introduces navBarButtonFontFamily property which allows to set
a different font family for title and buttons.
Guy Carmeli 7 anni fa
parent
commit
a3b4caf707

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

@@ -115,6 +115,7 @@ public class StyleParams {
115 115
     public boolean titleBarTitleTextCentered;
116 116
     public int titleBarHeight;
117 117
     public boolean backButtonHidden;
118
+    public Font titleBarButtonFontFamily;
118 119
 
119 120
     public Color topTabTextColor;
120 121
     public Color topTabIconColor;

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/params/TitleBarButtonParams.java Vedi File

@@ -7,7 +7,7 @@ public class TitleBarButtonParams extends BaseTitleBarButtonParams {
7 7
     @Override
8 8
     public void setStyleFromScreen(StyleParams styleParams) {
9 9
         super.setStyleFromScreen(styleParams);
10
-        font = styleParams.titleBarTitleFont;
10
+        font = styleParams.titleBarButtonFontFamily.hasFont() ? styleParams.titleBarButtonFontFamily : styleParams.titleBarTitleFont;
11 11
     }
12 12
 
13 13
     public boolean hasFont() {

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

@@ -58,6 +58,7 @@ public class StyleParamsParser {
58 58
         result.titleBarSubtitleFontSize = getInt("titleBarSubtitleFontSize", getDefaultSubtitleTextFontSize());
59 59
         result.titleBarSubtitleFontFamily = getFont("titleBarSubtitleFontFamily", getDefaultSubtitleFontFamily());
60 60
         result.titleBarButtonColor = getColor("titleBarButtonColor", getTitleBarButtonColor());
61
+        result.titleBarButtonFontFamily = getFont("titleBarButtonFontFamily", getDefaultTitleBarButtonFont());
61 62
         result.titleBarDisabledButtonColor = getColor("titleBarDisabledButtonColor", getTitleBarDisabledButtonColor());
62 63
         result.titleBarTitleFont = getFont("titleBarTitleFontFamily", getDefaultTitleTextFontFamily());
63 64
         result.titleBarTitleFontSize = getInt("titleBarTitleFontSize", getDefaultTitleTextFontSize());
@@ -118,6 +119,7 @@ public class StyleParamsParser {
118 119
         result.bottomTabFontFamily = new StyleParams.Font();
119 120
         result.titleBarTitleFont = new StyleParams.Font();
120 121
         result.titleBarSubtitleFontFamily = new StyleParams.Font();
122
+        result.titleBarButtonFontFamily = new StyleParams.Font();
121 123
         result.titleBarHeight = -1;
122 124
         return result;
123 125
     }
@@ -294,6 +296,10 @@ public class StyleParamsParser {
294 296
         return AppStyle.appStyle == null ? new StyleParams.Font() : AppStyle.appStyle.titleBarSubtitleFontFamily;
295 297
     }
296 298
 
299
+    private StyleParams.Font getDefaultTitleBarButtonFont() {
300
+        return AppStyle.appStyle == null ? new StyleParams.Font() : AppStyle.appStyle.titleBarButtonFontFamily;
301
+    }
302
+
297 303
     private boolean getDefaultTitleTextFontBold() {
298 304
         return AppStyle.appStyle != null && AppStyle.appStyle.titleBarTitleFontBold;
299 305
     }

+ 1
- 0
docs/styling-the-navigator.md Vedi File

@@ -98,6 +98,7 @@ this.props.navigator.setStyle({
98 98
   // Android only
99 99
   navigationBarColor: '#000000', // change the background color of the bottom native navigation bar.
100 100
   navBarTitleTextCentered: true, // default: false. centers the title.
101
+  navBarButtonFontFamily: 'sans-serif-thin', // Change the font family of textual buttons
101 102
   topBarElevationShadowEnabled: false, // default: true. Disables TopBar elevation shadow on Lolipop and above
102 103
   statusBarColor: '#000000', // change the color of the status bar.
103 104
   collapsingToolBarImage: "http://lorempixel.com/400/200/", // Collapsing Toolbar image.

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

@@ -165,6 +165,7 @@ function convertStyleParams(originalStyleObject) {
165 165
     titleBarSubtitleFontSize: originalStyleObject.navBarSubtitleFontSize,
166 166
     titleBarSubtitleFontFamily: originalStyleObject.navBarSubtitleFontFamily,
167 167
     titleBarButtonColor: processColor(originalStyleObject.navBarButtonColor),
168
+    titleBarButtonFontFamily: originalStyleObject.navBarButtonFontFamily,
168 169
     titleBarDisabledButtonColor: processColor(originalStyleObject.titleBarDisabledButtonColor),
169 170
     titleBarTitleFontFamily: originalStyleObject.navBarTextFontFamily,
170 171
     titleBarTitleFontSize: originalStyleObject.navBarTextFontSize,