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

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

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