Selaa lähdekoodia

[Android] Add navBarTextFontBold, navBarHeight and topTabsHeight (#1691)

* testing

* test

* try fix props on topTabs

* Test xml menu

* Add titleBarHeight

* Remove test

* Add to StyleParams

* Add topTabsHeight

* Fix styleParams type

* Add navBarFontBold

* Add typeface package

* Remove unused debugging
Luciano Di Pasquale 7 vuotta sitten
vanhempi
commit
f249a1ea40

+ 3
- 0
android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java Näytä tiedosto

@@ -99,7 +99,9 @@ public class StyleParams {
99 99
     public Color titleBarDisabledButtonColor;
100 100
     public Font titleBarTitleFont;
101 101
     public int titleBarTitleFontSize;
102
+    public boolean titleBarTitleFontBold;
102 103
     public boolean titleBarTitleTextCentered;
104
+    public int titleBarHeight;
103 105
     public boolean backButtonHidden;
104 106
 
105 107
     public Color topTabTextColor;
@@ -109,6 +111,7 @@ public class StyleParams {
109 111
     public int selectedTopTabIndicatorHeight;
110 112
     public Color selectedTopTabIndicatorColor;
111 113
     public boolean topTabsScrollable;
114
+    public int topTabsHeight;
112 115
 
113 116
     public Color screenBackgroundColor;
114 117
 

+ 15
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/StyleParamsParser.java Näytä tiedosto

@@ -55,7 +55,9 @@ public class StyleParamsParser {
55 55
         result.titleBarDisabledButtonColor = getColor("titleBarDisabledButtonColor", getTitleBarDisabledButtonColor());
56 56
         result.titleBarTitleFont = getFont("titleBarTitleFontFamily", getDefaultTitleTextFontFamily());
57 57
         result.titleBarTitleFontSize = getInt("titleBarTitleFontSize", getDefaultTitleTextFontSize());
58
+        result.titleBarTitleFontBold = getBoolean("titleBarTitleFontBold", getDefaultTitleTextFontBold());
58 59
         result.titleBarTitleTextCentered = getBoolean("titleBarTitleTextCentered", getDefaultTitleBarTextCentered());
60
+        result.titleBarHeight = getInt("titleBarHeight", getDefaultTitleBarHeight());
59 61
         result.backButtonHidden = getBoolean("backButtonHidden", getDefaultBackButtonHidden());
60 62
         result.topTabsHidden = getBoolean("topTabsHidden", getDefaultTopTabsHidden());
61 63
 
@@ -66,6 +68,7 @@ public class StyleParamsParser {
66 68
         result.selectedTopTabIndicatorHeight = getInt("selectedTopTabIndicatorHeight", getDefaultSelectedTopTabIndicatorHeight());
67 69
         result.selectedTopTabIndicatorColor = getColor("selectedTopTabIndicatorColor", getDefaultSelectedTopTabIndicatorColor());
68 70
         result.topTabsScrollable = getBoolean("topTabsScrollable", getDefaultTopTabsScrollable());
71
+        result.topTabsHeight = getInt("topTabsHeight", getDefaultTopTabsHeight());
69 72
 
70 73
         result.screenBackgroundColor = getColor("screenBackgroundColor", getDefaultScreenBackgroundColor());
71 74
 
@@ -194,6 +197,10 @@ public class StyleParamsParser {
194 197
         return AppStyle.appStyle != null && AppStyle.appStyle.topTabsScrollable;
195 198
     }
196 199
 
200
+    private int getDefaultTopTabsHeight() {
201
+        return AppStyle.appStyle == null ? -1 : AppStyle.appStyle.topTabsHeight;
202
+    }
203
+
197 204
     private StyleParams.Color getDefaultTopTabIconColor() {
198 205
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.topTabIconColor;
199 206
     }
@@ -254,10 +261,18 @@ public class StyleParamsParser {
254 261
         return AppStyle.appStyle == null ? -1 : AppStyle.appStyle.titleBarTitleFontSize;
255 262
     }
256 263
 
264
+    private boolean getDefaultTitleTextFontBold() {
265
+        return AppStyle.appStyle != null && AppStyle.appStyle.titleBarTitleFontBold;
266
+    }
267
+
257 268
     private boolean getDefaultTitleBarTextCentered() {
258 269
         return AppStyle.appStyle != null && AppStyle.appStyle.titleBarTitleTextCentered;
259 270
     }
260 271
 
272
+    private int getDefaultTitleBarHeight() {
273
+        return AppStyle.appStyle == null ? -1 : AppStyle.appStyle.titleBarHeight;
274
+    }
275
+
261 276
     private boolean getBoolean(String key, boolean defaultValue) {
262 277
         return params.containsKey(key) ? params.getBoolean(key) : defaultValue;
263 278
     }

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java Näytä tiedosto

@@ -146,7 +146,8 @@ public abstract class Screen extends RelativeLayout implements Subscriber {
146 146
                 screenParams.leftButton,
147 147
                 leftButtonOnClickListener,
148 148
                 getNavigatorEventId(),
149
-                screenParams.overrideBackPressInJs);
149
+                screenParams.overrideBackPressInJs,
150
+                styleParams);
150 151
     }
151 152
 
152 153
     private void createAndAddTopBar() {

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/screens/ViewPagerScreen.java Näytä tiedosto

@@ -52,7 +52,7 @@ public class ViewPagerScreen extends Screen {
52 52
 
53 53
     @Override
54 54
     protected void createContent() {
55
-        TopTabs topTabs = topBar.initTabs();
55
+        TopTabs topTabs = topBar.initTabs(screenParams.styleParams);
56 56
         createViewPager();
57 57
         addPages();
58 58
         setupViewPager(topTabs);

+ 11
- 0
android/app/src/main/java/com/reactnativenavigation/views/TitleBar.java Näytä tiedosto

@@ -5,6 +5,7 @@ import android.animation.AnimatorListenerAdapter;
5 5
 import android.app.Activity;
6 6
 import android.content.Context;
7 7
 import android.graphics.drawable.Drawable;
8
+import android.graphics.Typeface;
8 9
 import android.support.annotation.Nullable;
9 10
 import android.support.v7.widget.ActionMenuView;
10 11
 import android.support.v7.widget.Toolbar;
@@ -76,6 +77,7 @@ public class TitleBar extends Toolbar {
76 77
         setTitleTextColor(params);
77 78
         setTitleTextFont(params);
78 79
         setTitleTextFontSize(params);
80
+        setTitleTextFontWeight(params);
79 81
         setSubtitleTextColor(params);
80 82
         colorOverflowButton(params);
81 83
         setBackground(params);
@@ -152,6 +154,15 @@ public class TitleBar extends Toolbar {
152 154
         }
153 155
     }
154 156
 
157
+    protected void setTitleTextFontWeight(StyleParams params) {
158
+        if (params.titleBarTitleFontBold) {
159
+            View titleView = getTitleView();
160
+            if (titleView instanceof TextView) {
161
+                ((TextView) titleView).setTypeface(((TextView) titleView).getTypeface(), Typeface.BOLD);
162
+            }
163
+        }
164
+    }
165
+
155 166
     protected void setSubtitleTextColor(StyleParams params) {
156 167
         if (params.titleBarSubtitleColor.hasColor()) {
157 168
             setSubtitleTextColor(params.titleBarSubtitleColor.getColor());

+ 18
- 6
android/app/src/main/java/com/reactnativenavigation/views/TopBar.java Näytä tiedosto

@@ -63,9 +63,10 @@ public class TopBar extends AppBarLayout {
63 63
     public void addTitleBarAndSetButtons(List<TitleBarButtonParams> rightButtons,
64 64
                                          TitleBarLeftButtonParams leftButton,
65 65
                                          LeftButtonOnClickListener leftButtonOnClickListener,
66
-                                         String navigatorEventId, boolean overrideBackPressInJs) {
66
+                                         String navigatorEventId, boolean overrideBackPressInJs,
67
+                                         StyleParams styleParams) {
67 68
         titleBar = createTitleBar();
68
-        addTitleBar();
69
+        addTitleBar(styleParams);
69 70
         addButtons(rightButtons, leftButton, leftButtonOnClickListener, navigatorEventId, overrideBackPressInJs);
70 71
     }
71 72
 
@@ -73,8 +74,14 @@ public class TopBar extends AppBarLayout {
73 74
         return new TitleBar(getContext());
74 75
     }
75 76
 
76
-    protected void addTitleBar() {
77
-        titleBarAndContextualMenuContainer.addView(titleBar, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));
77
+    protected void addTitleBar(StyleParams styleParams) {
78
+        final int titleBarHeight = styleParams.titleBarHeight > 0
79
+            ? (int) ViewUtils.convertDpToPixel(styleParams.titleBarHeight)
80
+            : MATCH_PARENT;
81
+
82
+        ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(MATCH_PARENT, titleBarHeight);
83
+
84
+        titleBarAndContextualMenuContainer.addView(titleBar, lp);
78 85
     }
79 86
 
80 87
     private void addButtons(List<TitleBarButtonParams> rightButtons, TitleBarLeftButtonParams leftButton, LeftButtonOnClickListener leftButtonOnClickListener, String navigatorEventId, boolean overrideBackPressInJs) {
@@ -177,9 +184,14 @@ public class TopBar extends AppBarLayout {
177 184
         titleBar.setRightButtons(titleBarButtons, navigatorEventId);
178 185
     }
179 186
 
180
-    public TopTabs initTabs() {
187
+    public TopTabs initTabs(StyleParams styleParams) {
181 188
         topTabs = new TopTabs(getContext());
182
-        addView(topTabs, new ViewGroup.LayoutParams(MATCH_PARENT, (int) ViewUtils.convertDpToPixel(48)));
189
+
190
+        final int topTabsHeight = styleParams.topTabsHeight > 0
191
+            ? (int) ViewUtils.convertDpToPixel(styleParams.topTabsHeight)
192
+            : MATCH_PARENT;
193
+
194
+        addView(topTabs, new ViewGroup.LayoutParams(MATCH_PARENT, topTabsHeight));
183 195
         return topTabs;
184 196
     }
185 197
 

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/CollapsingTopBar.java Näytä tiedosto

@@ -119,11 +119,11 @@ public class CollapsingTopBar extends TopBar implements CollapsingView {
119 119
     }
120 120
 
121 121
     @Override
122
-    protected void addTitleBar() {
122
+    protected void addTitleBar(StyleParams styleParams) {
123 123
         if (params.hasReactView()) {
124 124
             titleBarAndContextualMenuContainer.addView(titleBar, new ViewGroup.LayoutParams(MATCH_PARENT, WRAP_CONTENT));
125 125
         } else {
126
-            super.addTitleBar();
126
+            super.addTitleBar(styleParams);
127 127
         }
128 128
     }
129 129
 

+ 3
- 0
src/deprecated/platformSpecificDeprecated.android.js Näytä tiedosto

@@ -163,7 +163,9 @@ function convertStyleParams(originalStyleObject) {
163 163
     titleBarDisabledButtonColor: processColor(originalStyleObject.titleBarDisabledButtonColor),
164 164
     titleBarTitleFontFamily: originalStyleObject.navBarTextFontFamily,
165 165
     titleBarTitleFontSize: originalStyleObject.navBarTextFontSize,
166
+    titleBarTitleFontBold: originalStyleObject.navBarTextFontBold,
166 167
     titleBarTitleTextCentered: originalStyleObject.navBarTitleTextCentered,
168
+    titleBarHeight: originalStyleObject.navBarHeight,
167 169
     backButtonHidden: originalStyleObject.backButtonHidden,
168 170
     topTabsHidden: originalStyleObject.topTabsHidden,
169 171
     contextualMenuStatusBarColor: processColor(originalStyleObject.contextualMenuStatusBarColor),
@@ -179,6 +181,7 @@ function convertStyleParams(originalStyleObject) {
179 181
     selectedTopTabIndicatorHeight: originalStyleObject.selectedTopTabIndicatorHeight,
180 182
     selectedTopTabIndicatorColor: processColor(originalStyleObject.selectedTopTabIndicatorColor),
181 183
     topTabsScrollable: originalStyleObject.topTabsScrollable,
184
+    topTabsHeight: originalStyleObject.topTabsHeight,
182 185
     screenBackgroundColor: processColor(originalStyleObject.screenBackgroundColor),
183 186
 
184 187
     drawScreenAboveBottomTabs: !originalStyleObject.drawUnderTabBar,