Guy Carmeli 6 лет назад
Родитель
Сommit
b02d97e156

+ 8
- 4
lib/android/app/src/main/java/com/reactnativenavigation/presentation/OptionsPresenter.java Просмотреть файл

@@ -38,12 +38,15 @@ public class OptionsPresenter {
38 38
 
39 39
     private void applyTopBarOptions(TopBarOptions options, AnimationsOptions animationOptions, Component component) {
40 40
         if (options.title.text.hasValue()) topBar.setTitle(options.title.text.get());
41
-        if (options.subtitle.text.hasValue()) topBar.setSubtitle(options.subtitle.text.get());
42 41
         if (options.title.component.hasValue()) topBar.setTitleComponent(options.title.component.get(), options.title.alignment);
42
+        if (options.title.color.hasValue()) topBar.setTitleTextColor(options.title.color.get());
43
+        topBar.setTitleFontSize(options.title.fontSize);
44
+
45
+        if (options.subtitle.text.hasValue()) topBar.setSubtitle(options.subtitle.text.get());
46
+        if (options.subtitle.color.hasValue()) topBar.setSubtitleColor(options.subtitle.color.get());
47
+
43 48
         topBar.setBackgroundColor(options.background.color);
44 49
         topBar.setBackgroundComponent(options.background.component);
45
-        topBar.setTitleTextColor(options.title.color);
46
-        topBar.setTitleFontSize(options.title.fontSize);
47 50
         if (options.testId.hasValue()) topBar.setTestId(options.testId.get());
48 51
 
49 52
         topBar.setTitleTypeface(options.title.fontFamily);
@@ -123,10 +126,11 @@ public class OptionsPresenter {
123 126
     private void mergeTopBarOptions(TopBarOptions options, AnimationsOptions animationsOptions, Component component) {
124 127
         if (options.title.text.hasValue()) topBar.setTitle(options.title.text.get());
125 128
         if (options.title.component.hasValue()) topBar.setTitleComponent(options.title.component.get(), options.title.alignment);
126
-        if (options.title.color.hasValue()) topBar.setTitleTextColor(options.title.color);
129
+        if (options.title.color.hasValue()) topBar.setTitleTextColor(options.title.color.get());
127 130
         if (options.title.fontSize.hasValue()) topBar.setTitleFontSize(options.title.fontSize);
128 131
 
129 132
         if (options.subtitle.text.hasValue()) topBar.setSubtitle(options.subtitle.text.get());
133
+        if (options.subtitle.color.hasValue()) topBar.setSubtitleColor(options.subtitle.color.get());
130 134
 
131 135
         if (options.background.color.hasValue()) topBar.setBackgroundColor(options.background.color);
132 136
 

+ 6
- 1
lib/android/app/src/main/java/com/reactnativenavigation/views/topbar/TopBar.java Просмотреть файл

@@ -3,6 +3,7 @@ package com.reactnativenavigation.views.topbar;
3 3
 import android.annotation.SuppressLint;
4 4
 import android.content.Context;
5 5
 import android.graphics.Typeface;
6
+import android.support.annotation.ColorInt;
6 7
 import android.support.annotation.RestrictTo;
7 8
 import android.support.annotation.VisibleForTesting;
8 9
 import android.support.design.widget.AppBarLayout;
@@ -83,11 +84,15 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
83 84
         titleBar.setSubtitle(subtitle);
84 85
     }
85 86
 
87
+    public void setSubtitleColor(@ColorInt int color) {
88
+        titleBar.setSubtitleTextColor(color);
89
+    }
90
+
86 91
     public void setTestId(String testId) {
87 92
         setTag(testId);
88 93
     }
89 94
 
90
-    public void setTitleTextColor(Color color) {
95
+    public void setTitleTextColor(@ColorInt int color) {
91 96
         titleBar.setTitleTextColor(color);
92 97
     }
93 98
 

+ 8
- 6
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsMergingTest.java Просмотреть файл

@@ -60,7 +60,7 @@ public class OptionsMergingTest extends BaseTest {
60 60
     }
61 61
 
62 62
     @Test
63
-    public void mergeButtons() throws Exception {
63
+    public void mergeButtons() {
64 64
         Options options = new Options();
65 65
         uut.mergeChildOptions(options, child);
66 66
         verify(topBar, times(0)).setRightButtons(any());
@@ -76,7 +76,7 @@ public class OptionsMergingTest extends BaseTest {
76 76
     }
77 77
 
78 78
     @Test
79
-    public void mergeTopBarOptions() throws Exception {
79
+    public void mergeTopBarOptions() {
80 80
         Options options = new Options();
81 81
         uut.mergeChildOptions(options, child);
82 82
         assertTopBarOptions(0);
@@ -90,6 +90,7 @@ public class OptionsMergingTest extends BaseTest {
90 90
         options.topBarOptions.title = titleOptions;
91 91
         SubtitleOptions subtitleOptions = new SubtitleOptions();
92 92
         subtitleOptions.text = new Text("Sub");
93
+        subtitleOptions.color = new Color(1);
93 94
         options.topBarOptions.subtitle = subtitleOptions;
94 95
         options.topBarOptions.background.color = new Color(0);
95 96
         options.topBarOptions.testId = new Text("test123");
@@ -107,7 +108,7 @@ public class OptionsMergingTest extends BaseTest {
107 108
     }
108 109
 
109 110
     @Test
110
-    public void mergeTopTabsOptions() throws Exception {
111
+    public void mergeTopTabsOptions() {
111 112
         Options options = new Options();
112 113
         uut.mergeChildOptions(options, child);
113 114
         verify(topBar, times(0)).applyTopTabsColors(any(), any());
@@ -125,7 +126,7 @@ public class OptionsMergingTest extends BaseTest {
125 126
     }
126 127
 
127 128
     @Test
128
-    public void mergeTopTabOptions() throws Exception {
129
+    public void mergeTopTabOptions() {
129 130
         Options options = new Options();
130 131
         uut.mergeChildOptions(options, child);
131 132
 
@@ -144,10 +145,11 @@ public class OptionsMergingTest extends BaseTest {
144 145
         verify(topBar, times(t)).setSubtitle(any());
145 146
         verify(topBar, times(t)).setTitleComponent(any(), any());
146 147
         verify(topBar, times(t)).setBackgroundColor(any());
147
-        verify(topBar, times(t)).setTitleTextColor(any());
148
+        verify(topBar, times(t)).setTitleTextColor(anyInt());
148 149
         verify(topBar, times(t)).setTitleFontSize(any());
149
-        verify(topBar, times(t)).setTestId(any());
150 150
         verify(topBar, times(t)).setTitleTypeface(any());
151
+        verify(topBar, times(t)).setSubtitleColor(anyInt());
152
+        verify(topBar, times(t)).setTestId(any());
151 153
         verify(topBar, times(t)).hide();
152 154
         verify(child, times(t)).drawBelowTopBar(topBar);
153 155
         verify(child, times(0)).drawBehindTopBar();

+ 2
- 1
playground/src/screens/OptionsScreen.js Просмотреть файл

@@ -25,7 +25,8 @@ class OptionsScreen extends Component {
25 25
           largeTitle: false
26 26
         },
27 27
         subtitle: {
28
-          text: 'Static'
28
+          text: 'Static Subtitle',
29
+          color: 'red'
29 30
         },
30 31
         background: {
31 32
           component: 'TopBarBackground'