ソースを参照

[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 年 前
コミット
a249f5880e

+ 1
- 1
README.md ファイルの表示

71
 |                       | v1  | v2 iOS | v2 Android | Contributors |
71
 |                       | v1  | v2 iOS | v2 Android | Contributors |
72
 |-----------------------|-----|--------|------------|------------|
72
 |-----------------------|-----|--------|------------|------------|
73
 | topBarTextColor |   ✅    |    ✅     |     ✅        | Wix|
73
 | topBarTextColor |   ✅    |    ✅     |     ✅        | Wix|
74
-| topBarTextFontSize    |   ✅    |    ✅      |     [Contribute](/docs/docs/CONTRIBUTING.md)        | Wix|
74
+| topBarTextFontSize    |   ✅    |    ✅      |             | Wix|
75
 | topBarTextFontFamily  |  ✅     |      ✅     |     [Contribute](/docs/docs/CONTRIBUTING.md)        | Wix |
75
 | topBarTextFontFamily  |  ✅     |      ✅     |     [Contribute](/docs/docs/CONTRIBUTING.md)        | Wix |
76
 | topBarBackgroundColor |  ✅     |  ✅       |     ✅         | Wix|
76
 | topBarBackgroundColor |  ✅     |  ✅       |     ✅         | Wix|
77
 | topBarButtonColor     |  ✅     |    ✅      |     [Contribute](/docs/docs/CONTRIBUTING.md)        | Wix|
77
 | topBarButtonColor     |  ✅     |    ✅      |     [Contribute](/docs/docs/CONTRIBUTING.md)        | Wix|

+ 3
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/NavigationOptions.java ファイルの表示

15
 		result.title = json.optString("title");
15
 		result.title = json.optString("title");
16
 		result.topBarBackgroundColor = json.optInt("topBarBackgroundColor");
16
 		result.topBarBackgroundColor = json.optInt("topBarBackgroundColor");
17
 		result.topBarTextColor = json.optInt("topBarTextColor");
17
 		result.topBarTextColor = json.optInt("topBarTextColor");
18
+		result.topBarTextFontSize = (float) json.optDouble("topBarTextFontSize");
18
 
19
 
19
 		return result;
20
 		return result;
20
 	}
21
 	}
23
 	public int topBarBackgroundColor = 0;
24
 	public int topBarBackgroundColor = 0;
24
 	@ColorInt
25
 	@ColorInt
25
 	public int topBarTextColor;
26
 	public int topBarTextColor;
27
+	public float topBarTextFontSize;
26
 
28
 
27
 	public void mergeWith(final NavigationOptions other) {
29
 	public void mergeWith(final NavigationOptions other) {
28
 		title = other.title;
30
 		title = other.title;
29
 		topBarBackgroundColor = other.topBarBackgroundColor;
31
 		topBarBackgroundColor = other.topBarBackgroundColor;
30
 		topBarTextColor = other.topBarTextColor;
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 ファイルの表示

86
 		if (getParentStackController() != null) {
86
 		if (getParentStackController() != null) {
87
 			getParentStackController().getTopBar().setTitle(navigationOptions.title);
87
 			getParentStackController().getTopBar().setTitle(navigationOptions.title);
88
 			getParentStackController().getTopBar().setBackgroundColor(navigationOptions.topBarBackgroundColor);
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 ファイルの表示

1
 package com.reactnativenavigation.views;
1
 package com.reactnativenavigation.views;
2
 
2
 
3
 import android.app.Activity;
3
 import android.app.Activity;
4
+import android.support.annotation.ColorInt;
4
 import android.support.annotation.Nullable;
5
 import android.support.annotation.Nullable;
5
 import android.support.design.widget.AppBarLayout;
6
 import android.support.design.widget.AppBarLayout;
6
 import android.support.v7.widget.Toolbar;
7
 import android.support.v7.widget.Toolbar;
7
-import android.support.annotation.ColorInt;
8
 import android.view.View;
8
 import android.view.View;
9
 import android.view.ViewGroup;
9
 import android.view.ViewGroup;
10
 import android.widget.TextView;
10
 import android.widget.TextView;
30
 		titleBar.setTitleTextColor(color);
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
 	public TextView getTitleTextView() {
40
 	public TextView getTitleTextView() {
34
 		return findTextView(titleBar);
41
 		return findTextView(titleBar);
35
 	}
42
 	}

+ 2
- 0
lib/android/app/src/test/java/com/reactnativenavigation/parse/NavigationOptionsTest.java ファイルの表示

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

+ 18
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ContainerViewControllerTest.java ファイルの表示

144
 		assertThat(stackController.getTopBar().getTitleTextView()).isNotEqualTo(null);
144
 		assertThat(stackController.getTopBar().getTitleTextView()).isNotEqualTo(null);
145
 		assertThat(stackController.getTopBar().getTitleTextView().getCurrentTextColor()).isEqualTo(Color.RED);
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 ファイルの表示

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