Преглед изворни кода

[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 година
родитељ
комит
f249a1ea40

+ 3
- 0
android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java Прегледај датотеку

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

+ 15
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/StyleParamsParser.java Прегледај датотеку

55
         result.titleBarDisabledButtonColor = getColor("titleBarDisabledButtonColor", getTitleBarDisabledButtonColor());
55
         result.titleBarDisabledButtonColor = getColor("titleBarDisabledButtonColor", getTitleBarDisabledButtonColor());
56
         result.titleBarTitleFont = getFont("titleBarTitleFontFamily", getDefaultTitleTextFontFamily());
56
         result.titleBarTitleFont = getFont("titleBarTitleFontFamily", getDefaultTitleTextFontFamily());
57
         result.titleBarTitleFontSize = getInt("titleBarTitleFontSize", getDefaultTitleTextFontSize());
57
         result.titleBarTitleFontSize = getInt("titleBarTitleFontSize", getDefaultTitleTextFontSize());
58
+        result.titleBarTitleFontBold = getBoolean("titleBarTitleFontBold", getDefaultTitleTextFontBold());
58
         result.titleBarTitleTextCentered = getBoolean("titleBarTitleTextCentered", getDefaultTitleBarTextCentered());
59
         result.titleBarTitleTextCentered = getBoolean("titleBarTitleTextCentered", getDefaultTitleBarTextCentered());
60
+        result.titleBarHeight = getInt("titleBarHeight", getDefaultTitleBarHeight());
59
         result.backButtonHidden = getBoolean("backButtonHidden", getDefaultBackButtonHidden());
61
         result.backButtonHidden = getBoolean("backButtonHidden", getDefaultBackButtonHidden());
60
         result.topTabsHidden = getBoolean("topTabsHidden", getDefaultTopTabsHidden());
62
         result.topTabsHidden = getBoolean("topTabsHidden", getDefaultTopTabsHidden());
61
 
63
 
66
         result.selectedTopTabIndicatorHeight = getInt("selectedTopTabIndicatorHeight", getDefaultSelectedTopTabIndicatorHeight());
68
         result.selectedTopTabIndicatorHeight = getInt("selectedTopTabIndicatorHeight", getDefaultSelectedTopTabIndicatorHeight());
67
         result.selectedTopTabIndicatorColor = getColor("selectedTopTabIndicatorColor", getDefaultSelectedTopTabIndicatorColor());
69
         result.selectedTopTabIndicatorColor = getColor("selectedTopTabIndicatorColor", getDefaultSelectedTopTabIndicatorColor());
68
         result.topTabsScrollable = getBoolean("topTabsScrollable", getDefaultTopTabsScrollable());
70
         result.topTabsScrollable = getBoolean("topTabsScrollable", getDefaultTopTabsScrollable());
71
+        result.topTabsHeight = getInt("topTabsHeight", getDefaultTopTabsHeight());
69
 
72
 
70
         result.screenBackgroundColor = getColor("screenBackgroundColor", getDefaultScreenBackgroundColor());
73
         result.screenBackgroundColor = getColor("screenBackgroundColor", getDefaultScreenBackgroundColor());
71
 
74
 
194
         return AppStyle.appStyle != null && AppStyle.appStyle.topTabsScrollable;
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
     private StyleParams.Color getDefaultTopTabIconColor() {
204
     private StyleParams.Color getDefaultTopTabIconColor() {
198
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.topTabIconColor;
205
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.topTabIconColor;
199
     }
206
     }
254
         return AppStyle.appStyle == null ? -1 : AppStyle.appStyle.titleBarTitleFontSize;
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
     private boolean getDefaultTitleBarTextCentered() {
268
     private boolean getDefaultTitleBarTextCentered() {
258
         return AppStyle.appStyle != null && AppStyle.appStyle.titleBarTitleTextCentered;
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
     private boolean getBoolean(String key, boolean defaultValue) {
276
     private boolean getBoolean(String key, boolean defaultValue) {
262
         return params.containsKey(key) ? params.getBoolean(key) : defaultValue;
277
         return params.containsKey(key) ? params.getBoolean(key) : defaultValue;
263
     }
278
     }

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java Прегледај датотеку

146
                 screenParams.leftButton,
146
                 screenParams.leftButton,
147
                 leftButtonOnClickListener,
147
                 leftButtonOnClickListener,
148
                 getNavigatorEventId(),
148
                 getNavigatorEventId(),
149
-                screenParams.overrideBackPressInJs);
149
+                screenParams.overrideBackPressInJs,
150
+                styleParams);
150
     }
151
     }
151
 
152
 
152
     private void createAndAddTopBar() {
153
     private void createAndAddTopBar() {

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/screens/ViewPagerScreen.java Прегледај датотеку

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

+ 11
- 0
android/app/src/main/java/com/reactnativenavigation/views/TitleBar.java Прегледај датотеку

5
 import android.app.Activity;
5
 import android.app.Activity;
6
 import android.content.Context;
6
 import android.content.Context;
7
 import android.graphics.drawable.Drawable;
7
 import android.graphics.drawable.Drawable;
8
+import android.graphics.Typeface;
8
 import android.support.annotation.Nullable;
9
 import android.support.annotation.Nullable;
9
 import android.support.v7.widget.ActionMenuView;
10
 import android.support.v7.widget.ActionMenuView;
10
 import android.support.v7.widget.Toolbar;
11
 import android.support.v7.widget.Toolbar;
76
         setTitleTextColor(params);
77
         setTitleTextColor(params);
77
         setTitleTextFont(params);
78
         setTitleTextFont(params);
78
         setTitleTextFontSize(params);
79
         setTitleTextFontSize(params);
80
+        setTitleTextFontWeight(params);
79
         setSubtitleTextColor(params);
81
         setSubtitleTextColor(params);
80
         colorOverflowButton(params);
82
         colorOverflowButton(params);
81
         setBackground(params);
83
         setBackground(params);
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
     protected void setSubtitleTextColor(StyleParams params) {
166
     protected void setSubtitleTextColor(StyleParams params) {
156
         if (params.titleBarSubtitleColor.hasColor()) {
167
         if (params.titleBarSubtitleColor.hasColor()) {
157
             setSubtitleTextColor(params.titleBarSubtitleColor.getColor());
168
             setSubtitleTextColor(params.titleBarSubtitleColor.getColor());

+ 18
- 6
android/app/src/main/java/com/reactnativenavigation/views/TopBar.java Прегледај датотеку

63
     public void addTitleBarAndSetButtons(List<TitleBarButtonParams> rightButtons,
63
     public void addTitleBarAndSetButtons(List<TitleBarButtonParams> rightButtons,
64
                                          TitleBarLeftButtonParams leftButton,
64
                                          TitleBarLeftButtonParams leftButton,
65
                                          LeftButtonOnClickListener leftButtonOnClickListener,
65
                                          LeftButtonOnClickListener leftButtonOnClickListener,
66
-                                         String navigatorEventId, boolean overrideBackPressInJs) {
66
+                                         String navigatorEventId, boolean overrideBackPressInJs,
67
+                                         StyleParams styleParams) {
67
         titleBar = createTitleBar();
68
         titleBar = createTitleBar();
68
-        addTitleBar();
69
+        addTitleBar(styleParams);
69
         addButtons(rightButtons, leftButton, leftButtonOnClickListener, navigatorEventId, overrideBackPressInJs);
70
         addButtons(rightButtons, leftButton, leftButtonOnClickListener, navigatorEventId, overrideBackPressInJs);
70
     }
71
     }
71
 
72
 
73
         return new TitleBar(getContext());
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
     private void addButtons(List<TitleBarButtonParams> rightButtons, TitleBarLeftButtonParams leftButton, LeftButtonOnClickListener leftButtonOnClickListener, String navigatorEventId, boolean overrideBackPressInJs) {
87
     private void addButtons(List<TitleBarButtonParams> rightButtons, TitleBarLeftButtonParams leftButton, LeftButtonOnClickListener leftButtonOnClickListener, String navigatorEventId, boolean overrideBackPressInJs) {
177
         titleBar.setRightButtons(titleBarButtons, navigatorEventId);
184
         titleBar.setRightButtons(titleBarButtons, navigatorEventId);
178
     }
185
     }
179
 
186
 
180
-    public TopTabs initTabs() {
187
+    public TopTabs initTabs(StyleParams styleParams) {
181
         topTabs = new TopTabs(getContext());
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
         return topTabs;
195
         return topTabs;
184
     }
196
     }
185
 
197
 

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/CollapsingTopBar.java Прегледај датотеку

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

+ 3
- 0
src/deprecated/platformSpecificDeprecated.android.js Прегледај датотеку

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