Quellcode durchsuchen

Top bar text color for Android (#1813)

* android oreo overdraw fix

* apply top bar title color

* update readme

* update formatting

* merge v2

* navigation oprtions formatting

* update test

* ci fix

* rm global variable

* remove obsolete method
Roman Kozlov vor 7 Jahren
Ursprung
Commit
f431b368af

+ 1
- 1
README.md Datei anzeigen

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

+ 5
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/NavigationOptions.java Datei anzeigen

@@ -1,5 +1,6 @@
1 1
 package com.reactnativenavigation.parse;
2 2
 
3
+import android.support.annotation.ColorInt;
3 4
 import android.support.annotation.NonNull;
4 5
 
5 6
 import org.json.JSONObject;
@@ -13,15 +14,19 @@ public class NavigationOptions {
13 14
 
14 15
 		result.title = json.optString("title");
15 16
 		result.topBarBackgroundColor = json.optInt("topBarBackgroundColor");
17
+		result.topBarTextColor = json.optInt("topBarTextColor");
16 18
 
17 19
 		return result;
18 20
 	}
19 21
 
20 22
 	public String title = "";
21 23
 	public int topBarBackgroundColor = 0;
24
+	@ColorInt
25
+	public int topBarTextColor;
22 26
 
23 27
 	public void mergeWith(final NavigationOptions other) {
24 28
 		title = other.title;
25 29
 		topBarBackgroundColor = other.topBarBackgroundColor;
30
+		topBarTextColor = other.topBarTextColor;
26 31
 	}
27 32
 }

+ 1
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ContainerViewController.java Datei anzeigen

@@ -86,6 +86,7 @@ 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 90
 		}
90 91
 	}
91 92
 

+ 27
- 0
lib/android/app/src/main/java/com/reactnativenavigation/views/TopBar.java Datei anzeigen

@@ -1,8 +1,13 @@
1 1
 package com.reactnativenavigation.views;
2 2
 
3 3
 import android.app.Activity;
4
+import android.support.annotation.Nullable;
4 5
 import android.support.design.widget.AppBarLayout;
5 6
 import android.support.v7.widget.Toolbar;
7
+import android.support.annotation.ColorInt;
8
+import android.view.View;
9
+import android.view.ViewGroup;
10
+import android.widget.TextView;
6 11
 
7 12
 public class TopBar extends AppBarLayout {
8 13
 	private final Toolbar titleBar;
@@ -20,4 +25,26 @@ public class TopBar extends AppBarLayout {
20 25
 	public String getTitle() {
21 26
 		return titleBar.getTitle() != null ? titleBar.getTitle().toString() : "";
22 27
 	}
28
+
29
+	public void setTitleTextColor(@ColorInt int color) {
30
+		titleBar.setTitleTextColor(color);
31
+	}
32
+
33
+	public TextView getTitleTextView() {
34
+		return findTextView(titleBar);
35
+	}
36
+
37
+	@Nullable
38
+	public TextView findTextView(ViewGroup root) {
39
+		for (int i = 0; i < root.getChildCount(); i++) {
40
+			View view = root.getChildAt(i);
41
+			if (view instanceof TextView) {
42
+				return (TextView) view;
43
+			}
44
+			if (view instanceof ViewGroup) {
45
+				return findTextView((ViewGroup) view);
46
+			}
47
+		}
48
+		return null;
49
+	}
23 50
 }

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

@@ -19,10 +19,12 @@ public class NavigationOptionsTest extends BaseTest {
19 19
 		JSONObject json = new JSONObject();
20 20
 		json.put("title", "the title");
21 21
 		json.put("topBarBackgroundColor", 0xff123456);
22
+		json.put("topBarTextColor", 0xff123456);
22 23
 
23 24
 		NavigationOptions result = NavigationOptions.parse(json);
24 25
 		assertThat(result.title).isEqualTo("the title");
25 26
 		assertThat(result.topBarBackgroundColor).isEqualTo(0xff123456);
27
+		assertThat(result.topBarTextColor).isEqualTo(0xff123456);
26 28
 	}
27 29
 
28 30
 	@Test

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

@@ -126,4 +126,22 @@ public class ContainerViewControllerTest extends BaseTest {
126 126
 
127 127
 		assertThat(((ColorDrawable) stackController.getTopBar().getBackground()).getColor()).isEqualTo(0xffff0000);
128 128
 	}
129
+
130
+	@Test
131
+	public void appliesTopBarTextColor() throws Exception {
132
+		assertThat(uut.getNavigationOptions()).isSameAs(initialNavigationOptions);
133
+		initialNavigationOptions.title = "the title";
134
+		StackController stackController = new StackController(activity, "stackId");
135
+		stackController.push(uut);
136
+		uut.onViewAppeared();
137
+		assertThat(stackController.getTopBar().getTitleTextView().getCurrentTextColor()).isNotEqualTo(Color.RED);
138
+
139
+		NavigationOptions opts = new NavigationOptions();
140
+		opts.title = "the title";
141
+		opts.topBarTextColor = Color.RED;
142
+		uut.mergeNavigationOptions(opts);
143
+
144
+		assertThat(stackController.getTopBar().getTitleTextView()).isNotEqualTo(null);
145
+		assertThat(stackController.getTopBar().getTitleTextView().getCurrentTextColor()).isEqualTo(Color.RED);
146
+	}
129 147
 }

+ 1
- 1
scripts/env/installFbSimCtl.sh Datei anzeigen

@@ -1,4 +1,4 @@
1 1
 #!/bin/bash -e
2 2
 
3 3
 brew tap facebook/fb
4
-brew install fbsimctl
4
+brew install fbsimctl --HEAD