Procházet zdrojové kódy

Subtitle options merge

Guy Carmeli před 6 roky
rodič
revize
a9098c9c31

+ 4
- 2
lib/android/app/src/main/java/com/reactnativenavigation/presentation/OptionsPresenter.java Zobrazit soubor

@@ -40,10 +40,12 @@ public class OptionsPresenter {
40 40
         if (options.title.text.hasValue()) topBar.setTitle(options.title.text.get());
41 41
         if (options.title.component.hasValue()) topBar.setTitleComponent(options.title.component.get(), options.title.alignment);
42 42
         if (options.title.color.hasValue()) topBar.setTitleTextColor(options.title.color.get());
43
-        topBar.setTitleFontSize(options.title.fontSize);
43
+        if (options.title.fontSize.hasValue()) topBar.setTitleFontSize(options.title.fontSize.get());
44 44
 
45 45
         if (options.subtitle.text.hasValue()) topBar.setSubtitle(options.subtitle.text.get());
46 46
         if (options.subtitle.color.hasValue()) topBar.setSubtitleColor(options.subtitle.color.get());
47
+        if (options.subtitle.fontFamily != null) topBar.setSubtitleFontFamily(options.subtitle.fontFamily);
48
+        if (options.subtitle.fontSize.hasValue()) topBar.setTitleFontSize(options.subtitle.fontSize.get());
47 49
 
48 50
         topBar.setBackgroundColor(options.background.color);
49 51
         topBar.setBackgroundComponent(options.background.component);
@@ -127,7 +129,7 @@ public class OptionsPresenter {
127 129
         if (options.title.text.hasValue()) topBar.setTitle(options.title.text.get());
128 130
         if (options.title.component.hasValue()) topBar.setTitleComponent(options.title.component.get(), options.title.alignment);
129 131
         if (options.title.color.hasValue()) topBar.setTitleTextColor(options.title.color.get());
130
-        if (options.title.fontSize.hasValue()) topBar.setTitleFontSize(options.title.fontSize);
132
+        if (options.title.fontSize.hasValue()) topBar.setTitleFontSize(options.title.fontSize.get());
131 133
 
132 134
         if (options.subtitle.text.hasValue()) topBar.setSubtitle(options.subtitle.text.get());
133 135
         if (options.subtitle.color.hasValue()) topBar.setSubtitleColor(options.subtitle.color.get());

+ 7
- 5
lib/android/app/src/main/java/com/reactnativenavigation/views/titlebar/TitleBar.java Zobrazit soubor

@@ -15,7 +15,6 @@ import android.widget.TextView;
15 15
 import com.reactnativenavigation.parse.Alignment;
16 16
 import com.reactnativenavigation.parse.params.Button;
17 17
 import com.reactnativenavigation.parse.params.Color;
18
-import com.reactnativenavigation.parse.params.Fraction;
19 18
 import com.reactnativenavigation.viewcontrollers.ReactViewCreator;
20 19
 import com.reactnativenavigation.viewcontrollers.TitleBarReactViewController;
21 20
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
@@ -68,11 +67,9 @@ public class TitleBar extends Toolbar {
68 67
         if (color.hasValue()) setBackgroundColor(color.get());
69 68
     }
70 69
 
71
-    public void setTitleFontSize(Fraction size) {
70
+    public void setTitleFontSize(float size) {
72 71
         TextView titleTextView = getTitleTextView();
73
-        if (titleTextView != null && size.hasValue()) {
74
-            titleTextView.setTextSize(size.get());
75
-        }
72
+        if (titleTextView != null) titleTextView.setTextSize(size);
76 73
     }
77 74
 
78 75
     public void setTitleTypeface(Typeface typeface) {
@@ -88,6 +85,7 @@ public class TitleBar extends Toolbar {
88 85
 
89 86
     public void clear() {
90 87
         clearTitle();
88
+        clearSubtitle();
91 89
         clearRightButtons();
92 90
         clearLeftButton();
93 91
         clearComponent();
@@ -97,6 +95,10 @@ public class TitleBar extends Toolbar {
97 95
         setTitle(null);
98 96
     }
99 97
 
98
+    private void clearSubtitle() {
99
+        setSubtitle(null);
100
+    }
101
+
100 102
     private void clearComponent() {
101 103
         reactViewController.destroy();
102 104
         reactViewController = new TitleBarReactViewController((Activity) getContext(), reactViewCreator);

+ 5
- 1
lib/android/app/src/main/java/com/reactnativenavigation/views/topbar/TopBar.java Zobrazit soubor

@@ -88,6 +88,10 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
88 88
         titleBar.setSubtitleTextColor(color);
89 89
     }
90 90
 
91
+    public void setSubtitleFontFamily(Typeface fontFamily) {
92
+
93
+    }
94
+
91 95
     public void setTestId(String testId) {
92 96
         setTag(testId);
93 97
     }
@@ -96,7 +100,7 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
96 100
         titleBar.setTitleTextColor(color);
97 101
     }
98 102
 
99
-    public void setTitleFontSize(Fraction size) {
103
+    public void setTitleFontSize(float size) {
100 104
         titleBar.setTitleFontSize(size);
101 105
     }
102 106
 

+ 44
- 17
lib/android/app/src/test/java/com/reactnativenavigation/parse/OptionsTest.java Zobrazit soubor

@@ -1,19 +1,24 @@
1 1
 package com.reactnativenavigation.parse;
2 2
 
3
-import android.graphics.*;
4
-import android.support.annotation.*;
3
+import android.graphics.Typeface;
4
+import android.support.annotation.NonNull;
5 5
 
6
-import com.reactnativenavigation.*;
7
-import com.reactnativenavigation.mocks.*;
8
-import com.reactnativenavigation.parse.params.*;
6
+import com.reactnativenavigation.BaseTest;
7
+import com.reactnativenavigation.mocks.TypefaceLoaderMock;
8
+import com.reactnativenavigation.parse.params.Bool;
9
+import com.reactnativenavigation.parse.params.NullText;
9 10
 import com.reactnativenavigation.parse.params.Number;
10
-import com.reactnativenavigation.utils.*;
11
+import com.reactnativenavigation.parse.params.Text;
12
+import com.reactnativenavigation.utils.TypefaceLoader;
11 13
 
12
-import org.json.*;
13
-import org.junit.*;
14
-import org.mockito.*;
14
+import org.json.JSONException;
15
+import org.json.JSONObject;
16
+import org.junit.Test;
17
+import org.mockito.Mockito;
18
+import org.mockito.stubbing.Answer;
15 19
 
16
-import static org.assertj.core.api.Java6Assertions.*;
20
+import static org.assertj.core.api.Java6Assertions.assertThat;
21
+import static org.mockito.Mockito.when;
17 22
 
18 23
 public class OptionsTest extends BaseTest {
19 24
 
@@ -30,6 +35,11 @@ public class OptionsTest extends BaseTest {
30 35
     private static final int TOP_BAR_TEXT_COLOR = 0xff123456;
31 36
     private static final int TOP_BAR_FONT_SIZE = 18;
32 37
     private static final String TOP_BAR_FONT_FAMILY = "HelveticaNeue-CondensedBold";
38
+    private static final int SUBTITLE_FONT_SIZE = 14;
39
+    private static final int SUBTITLE_TEXT_COLOR = 0xff123457;
40
+    private static final String SUBTITLE_FONT_FAMILY = "HelveticaNeue-Condensed";
41
+    private static final Typeface SUBTITLE_TYPEFACE = Typeface.create("HelveticaNeue-Condensed", Typeface.NORMAL);
42
+    private static final String SUBTITLE_ALIGNMENT = "center";
33 43
     private static final Typeface TOP_BAR_TYPEFACE = Typeface.create("HelveticaNeue-CondensedBold", Typeface.BOLD);
34 44
     private static final String TITLE_ALIGNMENT = "center";
35 45
     private static final Bool TOP_BAR_VISIBLE = new Bool(true);
@@ -45,11 +55,13 @@ public class OptionsTest extends BaseTest {
45 55
     @Override
46 56
     public void beforeEach() {
47 57
         mockLoader = Mockito.mock(TypefaceLoaderMock.class);
58
+        when(mockLoader.getTypeFace("HelveticaNeue-Condensed")).then((Answer<Typeface>) invocation -> SUBTITLE_TYPEFACE);
59
+        when(mockLoader.getTypeFace("HelveticaNeue-CondensedBold")).then((Answer<Typeface>) invocation -> TOP_BAR_TYPEFACE);
48 60
         Mockito.doReturn(TOP_BAR_TYPEFACE).when(mockLoader).getTypeFace(TOP_BAR_FONT_FAMILY);
49 61
     }
50 62
 
51 63
     @Test
52
-    public void parsesNullAsDefaultEmptyOptions() throws Exception {
64
+    public void parsesNullAsDefaultEmptyOptions() {
53 65
         assertThat(Options.parse(mockLoader, null)).isNotNull();
54 66
     }
55 67
 
@@ -69,6 +81,10 @@ public class OptionsTest extends BaseTest {
69 81
         assertThat(result.topBarOptions.title.color.get()).isEqualTo(TOP_BAR_TEXT_COLOR);
70 82
         assertThat(result.topBarOptions.title.fontSize.get()).isEqualTo(TOP_BAR_FONT_SIZE);
71 83
         assertThat(result.topBarOptions.title.fontFamily).isEqualTo(TOP_BAR_TYPEFACE);
84
+        assertThat(result.topBarOptions.subtitle.color.get()).isEqualTo(SUBTITLE_TEXT_COLOR);
85
+        assertThat(result.topBarOptions.subtitle.fontSize.get()).isEqualTo(SUBTITLE_FONT_SIZE);
86
+        assertThat(result.topBarOptions.subtitle.alignment).isEqualTo(Alignment.fromString(SUBTITLE_ALIGNMENT));
87
+        assertThat(result.topBarOptions.subtitle.fontFamily).isEqualTo(SUBTITLE_TYPEFACE);
72 88
         assertThat(result.topBarOptions.visible.get()).isEqualTo(TOP_BAR_VISIBLE.get());
73 89
         assertThat(result.topBarOptions.drawBehind.get()).isEqualTo(TOP_BAR_DRAW_BEHIND.get());
74 90
         assertThat(result.topBarOptions.hideOnScroll.get()).isEqualTo(TOP_BAR_HIDE_ON_SCROLL.get());
@@ -100,6 +116,7 @@ public class OptionsTest extends BaseTest {
100 116
     private JSONObject createTopBar(boolean visible) throws JSONException {
101 117
         return new JSONObject()
102 118
                 .put("title", createTitle())
119
+                .put("subtitle", createSubtitle())
103 120
                 .put("background", createBackground())
104 121
                 .put("visible", visible)
105 122
                 .put("drawBehind", TOP_BAR_DRAW_BEHIND.get())
@@ -120,6 +137,15 @@ public class OptionsTest extends BaseTest {
120 137
                 .put("alignment", TITLE_ALIGNMENT);
121 138
     }
122 139
 
140
+    private JSONObject createSubtitle() throws JSONException {
141
+        return new JSONObject()
142
+                .put("text", "the subtitle")
143
+                .put("color", SUBTITLE_TEXT_COLOR)
144
+                .put("fontSize", SUBTITLE_FONT_SIZE)
145
+                .put("fontFamily", SUBTITLE_FONT_FAMILY)
146
+                .put("alignment", SUBTITLE_ALIGNMENT);
147
+    }
148
+
123 149
     @NonNull
124 150
     private JSONObject createFab() throws JSONException {
125 151
         return new JSONObject()
@@ -150,6 +176,7 @@ public class OptionsTest extends BaseTest {
150 176
     private JSONObject createOtherTopBar() throws JSONException {
151 177
         return new JSONObject()
152 178
                 .put("title", createTitle())
179
+                .put("subtitle", createSubtitle())
153 180
                 .put("background", createBackground())
154 181
                 .put("visible", TOP_BAR_VISIBLE);
155 182
     }
@@ -211,20 +238,20 @@ public class OptionsTest extends BaseTest {
211 238
     }
212 239
 
213 240
     @Test
214
-    public void defaultEmptyOptions() throws Exception {
241
+    public void defaultEmptyOptions() {
215 242
         Options uut = new Options();
216 243
         assertThat(uut.topBarOptions.title.text.get("")).isEmpty();
217 244
     }
218 245
 
219 246
     @Test
220
-    public void topBar_defaultOptions() throws Exception {
247
+    public void topBar_defaultOptions() {
221 248
         Options uut = new Options();
222 249
         assertThat(uut.topBarOptions.visible.isFalseOrUndefined()).isTrue();
223 250
         assertThat(uut.topBarOptions.animate.isTrueOrUndefined()).isTrue();
224 251
     }
225 252
 
226 253
     @Test
227
-    public void clear_topBarOptions() throws Exception {
254
+    public void clear_topBarOptions() {
228 255
         Options uut = new Options();
229 256
         uut.topBarOptions.title.text = new Text("some title");
230 257
         uut.clearTopBarOptions();
@@ -232,7 +259,7 @@ public class OptionsTest extends BaseTest {
232 259
     }
233 260
 
234 261
     @Test
235
-    public void clear_bottomTabsOptions() throws Exception {
262
+    public void clear_bottomTabsOptions() {
236 263
         Options uut = new Options();
237 264
         uut.bottomTabsOptions.tabColor = new com.reactnativenavigation.parse.params.Color(android.graphics.Color.RED);
238 265
         uut.clearBottomTabsOptions();
@@ -240,7 +267,7 @@ public class OptionsTest extends BaseTest {
240 267
     }
241 268
 
242 269
     @Test
243
-    public void clear_topTabsOptions() throws Exception {
270
+    public void clear_topTabsOptions() {
244 271
         Options uut = new Options();
245 272
         uut.topTabsOptions.fontSize = new Number(666);
246 273
         uut.clearTopTabsOptions();
@@ -248,7 +275,7 @@ public class OptionsTest extends BaseTest {
248 275
     }
249 276
 
250 277
     @Test
251
-    public void clear_topTabOptions() throws Exception {
278
+    public void clear_topTabOptions() {
252 279
         Options uut = new Options();
253 280
         uut.topTabOptions.title = new Text("some title");
254 281
         uut.clearTopTabOptions();

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsMergingTest.java Zobrazit soubor

@@ -25,6 +25,7 @@ import java.util.ArrayList;
25 25
 
26 26
 import static org.mockito.ArgumentMatchers.any;
27 27
 import static org.mockito.ArgumentMatchers.anyBoolean;
28
+import static org.mockito.ArgumentMatchers.anyFloat;
28 29
 import static org.mockito.ArgumentMatchers.anyInt;
29 30
 import static org.mockito.Mockito.mock;
30 31
 import static org.mockito.Mockito.spy;
@@ -146,7 +147,7 @@ public class OptionsMergingTest extends BaseTest {
146 147
         verify(topBar, times(t)).setTitleComponent(any(), any());
147 148
         verify(topBar, times(t)).setBackgroundColor(any());
148 149
         verify(topBar, times(t)).setTitleTextColor(anyInt());
149
-        verify(topBar, times(t)).setTitleFontSize(any());
150
+        verify(topBar, times(t)).setTitleFontSize(anyFloat());
150 151
         verify(topBar, times(t)).setTitleTypeface(any());
151 152
         verify(topBar, times(t)).setSubtitleColor(anyInt());
152 153
         verify(topBar, times(t)).setTestId(any());