Browse Source

Subtitle color

Guy Carmeli 6 years ago
parent
commit
b02d97e156

+ 8
- 4
lib/android/app/src/main/java/com/reactnativenavigation/presentation/OptionsPresenter.java View File

38
 
38
 
39
     private void applyTopBarOptions(TopBarOptions options, AnimationsOptions animationOptions, Component component) {
39
     private void applyTopBarOptions(TopBarOptions options, AnimationsOptions animationOptions, Component component) {
40
         if (options.title.text.hasValue()) topBar.setTitle(options.title.text.get());
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
         if (options.title.component.hasValue()) topBar.setTitleComponent(options.title.component.get(), options.title.alignment);
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
         topBar.setBackgroundColor(options.background.color);
48
         topBar.setBackgroundColor(options.background.color);
44
         topBar.setBackgroundComponent(options.background.component);
49
         topBar.setBackgroundComponent(options.background.component);
45
-        topBar.setTitleTextColor(options.title.color);
46
-        topBar.setTitleFontSize(options.title.fontSize);
47
         if (options.testId.hasValue()) topBar.setTestId(options.testId.get());
50
         if (options.testId.hasValue()) topBar.setTestId(options.testId.get());
48
 
51
 
49
         topBar.setTitleTypeface(options.title.fontFamily);
52
         topBar.setTitleTypeface(options.title.fontFamily);
123
     private void mergeTopBarOptions(TopBarOptions options, AnimationsOptions animationsOptions, Component component) {
126
     private void mergeTopBarOptions(TopBarOptions options, AnimationsOptions animationsOptions, Component component) {
124
         if (options.title.text.hasValue()) topBar.setTitle(options.title.text.get());
127
         if (options.title.text.hasValue()) topBar.setTitle(options.title.text.get());
125
         if (options.title.component.hasValue()) topBar.setTitleComponent(options.title.component.get(), options.title.alignment);
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
         if (options.title.fontSize.hasValue()) topBar.setTitleFontSize(options.title.fontSize);
130
         if (options.title.fontSize.hasValue()) topBar.setTitleFontSize(options.title.fontSize);
128
 
131
 
129
         if (options.subtitle.text.hasValue()) topBar.setSubtitle(options.subtitle.text.get());
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
         if (options.background.color.hasValue()) topBar.setBackgroundColor(options.background.color);
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 View File

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

+ 8
- 6
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsMergingTest.java View File

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

+ 2
- 1
playground/src/screens/OptionsScreen.js View File

25
           largeTitle: false
25
           largeTitle: false
26
         },
26
         },
27
         subtitle: {
27
         subtitle: {
28
-          text: 'Static'
28
+          text: 'Static Subtitle',
29
+          color: 'red'
29
         },
30
         },
30
         background: {
31
         background: {
31
           component: 'TopBarBackground'
32
           component: 'TopBarBackground'