Browse Source

[V2] Top bar text size (#1849)

* android oreo overdraw fix

* apply top bar title color

* update readme

* update formatting

* merge v2

* navigation oprtions formatting

* font size props

* update test

* ci fix

* rm global variable

* font size

* update readme

* playground

* after merge fix
Roman Kozlov 6 years ago
parent
commit
a249f5880e

+ 1
- 1
README.md View File

@@ -71,7 +71,7 @@ Note:  v1 properties with names beginning with 'navBar' are replaced in v2 with
71 71
 |                       | v1  | v2 iOS | v2 Android | Contributors |
72 72
 |-----------------------|-----|--------|------------|------------|
73 73
 | topBarTextColor |   ✅    |    ✅     |     ✅        | Wix|
74
-| topBarTextFontSize    |   ✅    |    ✅      |     [Contribute](/docs/docs/CONTRIBUTING.md)        | Wix|
74
+| topBarTextFontSize    |   ✅    |    ✅      |             | Wix|
75 75
 | topBarTextFontFamily  |  ✅     |      ✅     |     [Contribute](/docs/docs/CONTRIBUTING.md)        | Wix |
76 76
 | topBarBackgroundColor |  ✅     |  ✅       |     ✅         | Wix|
77 77
 | topBarButtonColor     |  ✅     |    ✅      |     [Contribute](/docs/docs/CONTRIBUTING.md)        | Wix|

+ 3
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/NavigationOptions.java View File

@@ -15,6 +15,7 @@ public class NavigationOptions {
15 15
 		result.title = json.optString("title");
16 16
 		result.topBarBackgroundColor = json.optInt("topBarBackgroundColor");
17 17
 		result.topBarTextColor = json.optInt("topBarTextColor");
18
+		result.topBarTextFontSize = (float) json.optDouble("topBarTextFontSize");
18 19
 
19 20
 		return result;
20 21
 	}
@@ -23,10 +24,12 @@ public class NavigationOptions {
23 24
 	public int topBarBackgroundColor = 0;
24 25
 	@ColorInt
25 26
 	public int topBarTextColor;
27
+	public float topBarTextFontSize;
26 28
 
27 29
 	public void mergeWith(final NavigationOptions other) {
28 30
 		title = other.title;
29 31
 		topBarBackgroundColor = other.topBarBackgroundColor;
30 32
 		topBarTextColor = other.topBarTextColor;
33
+		topBarTextFontSize = other.topBarTextFontSize;
31 34
 	}
32 35
 }

+ 2
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ContainerViewController.java View File

@@ -86,7 +86,8 @@ public class ContainerViewController extends ViewController {
86 86
 		if (getParentStackController() != null) {
87 87
 			getParentStackController().getTopBar().setTitle(navigationOptions.title);
88 88
 			getParentStackController().getTopBar().setBackgroundColor(navigationOptions.topBarBackgroundColor);
89
-      		getParentStackController().getTopBar().setTitleTextColor(navigationOptions.topBarTextColor);
89
+			getParentStackController().getTopBar().setTitleTextColor(navigationOptions.topBarTextColor);
90
+			getParentStackController().getTopBar().setTitleFontSize(navigationOptions.topBarTextFontSize);
90 91
 		}
91 92
 	}
92 93
 

+ 8
- 1
lib/android/app/src/main/java/com/reactnativenavigation/views/TopBar.java View File

@@ -1,10 +1,10 @@
1 1
 package com.reactnativenavigation.views;
2 2
 
3 3
 import android.app.Activity;
4
+import android.support.annotation.ColorInt;
4 5
 import android.support.annotation.Nullable;
5 6
 import android.support.design.widget.AppBarLayout;
6 7
 import android.support.v7.widget.Toolbar;
7
-import android.support.annotation.ColorInt;
8 8
 import android.view.View;
9 9
 import android.view.ViewGroup;
10 10
 import android.widget.TextView;
@@ -30,6 +30,13 @@ public class TopBar extends AppBarLayout {
30 30
 		titleBar.setTitleTextColor(color);
31 31
 	}
32 32
 
33
+	public void setTitleFontSize(float size) {
34
+		TextView titleTextView = getTitleTextView();
35
+		if (titleTextView != null) {
36
+			titleTextView.setTextSize(size);
37
+		}
38
+	}
39
+
33 40
 	public TextView getTitleTextView() {
34 41
 		return findTextView(titleBar);
35 42
 	}

+ 2
- 0
lib/android/app/src/test/java/com/reactnativenavigation/parse/NavigationOptionsTest.java View File

@@ -20,11 +20,13 @@ public class NavigationOptionsTest extends BaseTest {
20 20
 		json.put("title", "the title");
21 21
 		json.put("topBarBackgroundColor", 0xff123456);
22 22
 		json.put("topBarTextColor", 0xff123456);
23
+		json.put("topBarTextFontSize", 18);
23 24
 
24 25
 		NavigationOptions result = NavigationOptions.parse(json);
25 26
 		assertThat(result.title).isEqualTo("the title");
26 27
 		assertThat(result.topBarBackgroundColor).isEqualTo(0xff123456);
27 28
 		assertThat(result.topBarTextColor).isEqualTo(0xff123456);
29
+		assertThat(result.topBarTextFontSize).isEqualTo(18);
28 30
 	}
29 31
 
30 32
 	@Test

+ 18
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ContainerViewControllerTest.java View File

@@ -144,4 +144,22 @@ public class ContainerViewControllerTest extends BaseTest {
144 144
 		assertThat(stackController.getTopBar().getTitleTextView()).isNotEqualTo(null);
145 145
 		assertThat(stackController.getTopBar().getTitleTextView().getCurrentTextColor()).isEqualTo(Color.RED);
146 146
 	}
147
+
148
+	@Test
149
+	public void appliesTopBarTextSize() throws Exception {
150
+		assertThat(uut.getNavigationOptions()).isSameAs(initialNavigationOptions);
151
+		initialNavigationOptions.title = "the title";
152
+		StackController stackController = new StackController(activity, "stackId");
153
+		stackController.push(uut);
154
+		uut.onViewAppeared();
155
+		assertThat(stackController.getTopBar().getTitleTextView().getTextSize()).isNotEqualTo(18);
156
+
157
+		NavigationOptions opts = new NavigationOptions();
158
+		opts.title = "the title";
159
+		opts.topBarTextFontSize = 18;
160
+		uut.mergeNavigationOptions(opts);
161
+
162
+		assertThat(stackController.getTopBar().getTitleTextView()).isNotEqualTo(null);
163
+		assertThat(stackController.getTopBar().getTitleTextView().getTextSize()).isEqualTo(18);
164
+	}
147 165
 }

+ 2
- 0
playground/src/containers/OptionsScreen.js View File

@@ -14,6 +14,8 @@ class OptionsScreen extends Component {
14 14
   static get navigationOptions() {
15 15
     return {
16 16
       title: 'Static Title',
17
+      topBarTextColor: 'black',
18
+      topBarTextFontSize: 16,
17 19
       topBarTextFontFamily: 'HelveticaNeue-Italic',
18 20
       rightButtons: [{
19 21
         id: BUTTON_ONE,