Browse Source

Add screenBackgroundColor to Android (#3006)

andresesfm 6 years ago
parent
commit
466e289faf

+ 12
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/Options.java View File

@@ -4,8 +4,11 @@ import android.support.annotation.CheckResult;
4 4
 import android.support.annotation.NonNull;
5 5
 
6 6
 import com.reactnativenavigation.parse.params.Bool;
7
+import com.reactnativenavigation.parse.params.Color;
7 8
 import com.reactnativenavigation.parse.params.NullBool;
9
+import com.reactnativenavigation.parse.params.NullColor;
8 10
 import com.reactnativenavigation.parse.parsers.BoolParser;
11
+import com.reactnativenavigation.parse.parsers.ColorParser;
9 12
 import com.reactnativenavigation.utils.TypefaceLoader;
10 13
 
11 14
 import org.json.JSONObject;
@@ -33,6 +36,7 @@ public class Options {
33 36
         result.sideMenuRootOptions = SideMenuRootOptions.parse(json.optJSONObject("sideMenu"));
34 37
         result.animationsOptions = AnimationsOptions.parse(json.optJSONObject("animations"));
35 38
         result.animated = BoolParser.parse(json, "animated");
39
+        result.screenBackgroundColor = ColorParser.parse(json, "screenBackgroundColor");
36 40
 
37 41
         return result.withDefaultOptions(defaultOptions);
38 42
     }
@@ -48,6 +52,7 @@ public class Options {
48 52
     @NonNull public AnimationsOptions animationsOptions = new AnimationsOptions();
49 53
     @NonNull public SideMenuRootOptions sideMenuRootOptions = new SideMenuRootOptions();
50 54
     @NonNull public Bool animated = new NullBool();
55
+    @NonNull public Color screenBackgroundColor = new NullColor();
51 56
 
52 57
     void setTopTabIndex(int i) {
53 58
         topTabOptions.tabIndex = i;
@@ -67,6 +72,7 @@ public class Options {
67 72
         result.sideMenuRootOptions.mergeWith(sideMenuRootOptions);
68 73
         result.animationsOptions.mergeWith(animationsOptions);
69 74
         result.animated = animated;
75
+        result.screenBackgroundColor = screenBackgroundColor;
70 76
         return result;
71 77
     }
72 78
 
@@ -83,6 +89,9 @@ public class Options {
83 89
         result.animationsOptions.mergeWith(other.animationsOptions);
84 90
         result.sideMenuRootOptions.mergeWith(other.sideMenuRootOptions);
85 91
         if (other.animated.hasValue()) result.animated = other.animated;
92
+        if (other.screenBackgroundColor.hasValue()) {
93
+            result.screenBackgroundColor = other.screenBackgroundColor;
94
+        }
86 95
         return result;
87 96
     }
88 97
 
@@ -97,6 +106,9 @@ public class Options {
97 106
         animationsOptions.mergeWithDefault(defaultOptions.animationsOptions);
98 107
         sideMenuRootOptions.mergeWithDefault(defaultOptions.sideMenuRootOptions);
99 108
         if (!animated.hasValue()) animated = defaultOptions.animated;
109
+        if (!screenBackgroundColor.hasValue()) {
110
+            screenBackgroundColor = defaultOptions.screenBackgroundColor;
111
+        }
100 112
         return this;
101 113
     }
102 114
 

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

@@ -15,9 +15,17 @@ public class ComponentOptionsPresenter {
15 15
 
16 16
     public void present(Options options) {
17 17
         applyOrientation(options.orientationOptions);
18
+        applyOtherOptions(options);
18 19
     }
19 20
 
20 21
     private void applyOrientation(OrientationOptions options) {
21 22
         ((Activity) component.getContext()).setRequestedOrientation(options.getValue());
22 23
     }
24
+
25
+    private void applyOtherOptions(Options options) {
26
+        if (options.screenBackgroundColor.hasValue()) {
27
+            component.setBackgroundColor(options.screenBackgroundColor.get());
28
+        }
29
+    }
30
+
23 31
 }

+ 10
- 3
lib/android/app/src/test/java/com/reactnativenavigation/parse/OptionsTest.java View File

@@ -37,6 +37,7 @@ public class OptionsTest extends BaseTest {
37 37
     private static final String TOP_BAR_FONT_FAMILY = "HelveticaNeue-CondensedBold";
38 38
     private static final int SUBTITLE_FONT_SIZE = 14;
39 39
     private static final int SUBTITLE_TEXT_COLOR = 0xff123457;
40
+    private static final int SCREEN_BACKGROUND_COLOR = 0xff123458;
40 41
     private static final String SUBTITLE_FONT_FAMILY = "HelveticaNeue-Condensed";
41 42
     private static final Typeface SUBTITLE_TYPEFACE = Typeface.create("HelveticaNeue-Condensed", Typeface.NORMAL);
42 43
     private static final String SUBTITLE_ALIGNMENT = "center";
@@ -69,7 +70,8 @@ public class OptionsTest extends BaseTest {
69 70
         JSONObject json = new JSONObject()
70 71
                 .put("topBar", createTopBar(TOP_BAR_VISIBLE.get()))
71 72
                 .put("fab", createFab())
72
-                .put("bottomTabs", createBottomTabs());
73
+                .put("bottomTabs", createBottomTabs())
74
+                .put("screenBackgroundColor",SCREEN_BACKGROUND_COLOR);
73 75
         Options result = Options.parse(mockLoader, json);
74 76
         assertResult(result);
75 77
     }
@@ -99,6 +101,7 @@ public class OptionsTest extends BaseTest {
99 101
         assertThat(result.fabOptions.hideOnScroll.get()).isEqualTo(FAB_HIDE_ON_SCROLL);
100 102
         assertThat(result.fabOptions.alignVertically.get()).isEqualTo(FAB_ALIGN_VERTICALLY);
101 103
         assertThat(result.fabOptions.alignHorizontally.get()).isEqualTo(FAB_ALIGN_HORIZONTALLY);
104
+        assertThat(result.screenBackgroundColor.get()).isEqualTo(SCREEN_BACKGROUND_COLOR);
102 105
     }
103 106
 
104 107
     @NonNull
@@ -211,7 +214,8 @@ public class OptionsTest extends BaseTest {
211 214
         JSONObject json = new JSONObject()
212 215
                 .put("topBar", createTopBar(TOP_BAR_VISIBLE.get()))
213 216
                 .put("fab", createFab())
214
-                .put("bottomTabs", createBottomTabs());
217
+                .put("bottomTabs", createBottomTabs())
218
+                .put("screenBackgroundColor",SCREEN_BACKGROUND_COLOR);
215 219
         Options defaultOptions = Options.parse(mockLoader, json);
216 220
         Options options = new Options();
217 221
 
@@ -223,7 +227,8 @@ public class OptionsTest extends BaseTest {
223 227
         JSONObject defaultJson = new JSONObject()
224 228
                 .put("topBar", createOtherTopBar())
225 229
                 .put("fab", createOtherFab())
226
-                .put("bottomTabs", createOtherBottomTabs());
230
+                .put("bottomTabs", createOtherBottomTabs())
231
+                .put("screenBackgroundColor",SCREEN_BACKGROUND_COLOR);
227 232
         Options defaultOptions = Options.parse(mockLoader, defaultJson);
228 233
 
229 234
         JSONObject json = new JSONObject()
@@ -238,6 +243,8 @@ public class OptionsTest extends BaseTest {
238 243
     public void defaultEmptyOptions() {
239 244
         Options uut = new Options();
240 245
         assertThat(uut.topBarOptions.title.text.get("")).isEmpty();
246
+        assertThat(uut.screenBackgroundColor.hasValue()).isFalse();
247
+
241 248
     }
242 249
 
243 250
     @Test