Browse Source

Initial ModalOptions implementation

Guy Carmeli 6 years ago
parent
commit
e85bc9949f

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

1
+package com.reactnativenavigation.parse;
2
+
3
+import org.json.JSONObject;
4
+
5
+public class ModalOptions {
6
+
7
+    public static ModalOptions parse(JSONObject json) {
8
+        ModalOptions options = new ModalOptions();
9
+        if (json == null) return options;
10
+
11
+        options.presentationStyle = ModalPresentationStyle.fromString(json.optString("modalPresentationStyle"));
12
+
13
+        return options;
14
+    }
15
+
16
+    public ModalPresentationStyle presentationStyle = ModalPresentationStyle.Unspecified;
17
+
18
+    public void mergeWith(ModalOptions other) {
19
+        if (other.hasValue()) presentationStyle = other.presentationStyle;
20
+    }
21
+
22
+    private boolean hasValue() {
23
+        return presentationStyle != ModalPresentationStyle.Unspecified;
24
+    }
25
+
26
+    public void mergeWithDefault(ModalOptions defaultOptions) {
27
+        if (!hasValue()) presentationStyle = defaultOptions.presentationStyle;
28
+    }
29
+}

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

1
+package com.reactnativenavigation.parse;
2
+
3
+public enum ModalPresentationStyle {
4
+    Unspecified("unspecified"),
5
+    None("none"),
6
+    OverCurrentContext("overCurrentContext");
7
+
8
+    public String name;
9
+
10
+    ModalPresentationStyle(String name) {
11
+        this.name = name;
12
+    }
13
+
14
+    public static ModalPresentationStyle fromString(String name) {
15
+        switch (name) {
16
+            case "none":
17
+                return None;
18
+            case "overCurrentContext":
19
+                return OverCurrentContext;
20
+            default:
21
+                return Unspecified;
22
+        }
23
+    }
24
+}

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

33
         result.sideMenuRootOptions = SideMenuRootOptions.parse(json.optJSONObject("sideMenu"));
33
         result.sideMenuRootOptions = SideMenuRootOptions.parse(json.optJSONObject("sideMenu"));
34
         result.animations = AnimationsOptions.parse(json.optJSONObject("animations"));
34
         result.animations = AnimationsOptions.parse(json.optJSONObject("animations"));
35
         result.screenBackgroundColor = ColorParser.parse(json, "screenBackgroundColor");
35
         result.screenBackgroundColor = ColorParser.parse(json, "screenBackgroundColor");
36
+        result.modal = ModalOptions.parse(json);
36
 
37
 
37
         return result.withDefaultOptions(defaultOptions);
38
         return result.withDefaultOptions(defaultOptions);
38
     }
39
     }
48
     @NonNull public AnimationsOptions animations = new AnimationsOptions();
49
     @NonNull public AnimationsOptions animations = new AnimationsOptions();
49
     @NonNull public SideMenuRootOptions sideMenuRootOptions = new SideMenuRootOptions();
50
     @NonNull public SideMenuRootOptions sideMenuRootOptions = new SideMenuRootOptions();
50
     @NonNull public Color screenBackgroundColor = new NullColor();
51
     @NonNull public Color screenBackgroundColor = new NullColor();
52
+    @NonNull public ModalOptions modal = new ModalOptions();
51
 
53
 
52
     void setTopTabIndex(int i) {
54
     void setTopTabIndex(int i) {
53
         topTabOptions.tabIndex = i;
55
         topTabOptions.tabIndex = i;
67
         result.sideMenuRootOptions.mergeWith(sideMenuRootOptions);
69
         result.sideMenuRootOptions.mergeWith(sideMenuRootOptions);
68
         result.animations.mergeWith(animations);
70
         result.animations.mergeWith(animations);
69
         result.screenBackgroundColor = screenBackgroundColor;
71
         result.screenBackgroundColor = screenBackgroundColor;
72
+        result.modal.mergeWith(modal);
70
         return result;
73
         return result;
71
     }
74
     }
72
 
75
 
83
         result.animations.mergeWith(other.animations);
86
         result.animations.mergeWith(other.animations);
84
         result.sideMenuRootOptions.mergeWith(other.sideMenuRootOptions);
87
         result.sideMenuRootOptions.mergeWith(other.sideMenuRootOptions);
85
         if (other.screenBackgroundColor.hasValue()) result.screenBackgroundColor = other.screenBackgroundColor;
88
         if (other.screenBackgroundColor.hasValue()) result.screenBackgroundColor = other.screenBackgroundColor;
89
+        result.modal.mergeWith(other.modal);
86
         return result;
90
         return result;
87
     }
91
     }
88
 
92
 
97
         animations.mergeWithDefault(defaultOptions.animations);
101
         animations.mergeWithDefault(defaultOptions.animations);
98
         sideMenuRootOptions.mergeWithDefault(defaultOptions.sideMenuRootOptions);
102
         sideMenuRootOptions.mergeWithDefault(defaultOptions.sideMenuRootOptions);
99
         if (!screenBackgroundColor.hasValue()) screenBackgroundColor = defaultOptions.screenBackgroundColor;
103
         if (!screenBackgroundColor.hasValue()) screenBackgroundColor = defaultOptions.screenBackgroundColor;
104
+        modal.mergeWithDefault(defaultOptions.modal);
100
         return this;
105
         return this;
101
     }
106
     }
102
 
107
 

lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalStackTest2.java → lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalStackTest.java View File

26
 import static org.mockito.Mockito.verify;
26
 import static org.mockito.Mockito.verify;
27
 import static org.mockito.Mockito.verifyZeroInteractions;
27
 import static org.mockito.Mockito.verifyZeroInteractions;
28
 
28
 
29
-public class ModalStackTest2 extends BaseTest {
29
+public class ModalStackTest extends BaseTest {
30
     private static final String MODAL_ID_1 = "modalId1";
30
     private static final String MODAL_ID_1 = "modalId1";
31
     private static final String MODAL_ID_2 = "modalId2";
31
     private static final String MODAL_ID_2 = "modalId2";
32
     private static final String MODAL_ID_3 = "modalId3";
32
     private static final String MODAL_ID_3 = "modalId3";