Kaynağa Gözat

Initial ModalOptions implementation

Guy Carmeli 6 yıl önce
ebeveyn
işleme
e85bc9949f

+ 29
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/ModalOptions.java Dosyayı Görüntüle

@@ -0,0 +1,29 @@
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 Dosyayı Görüntüle

@@ -0,0 +1,24 @@
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 Dosyayı Görüntüle

@@ -33,6 +33,7 @@ public class Options {
33 33
         result.sideMenuRootOptions = SideMenuRootOptions.parse(json.optJSONObject("sideMenu"));
34 34
         result.animations = AnimationsOptions.parse(json.optJSONObject("animations"));
35 35
         result.screenBackgroundColor = ColorParser.parse(json, "screenBackgroundColor");
36
+        result.modal = ModalOptions.parse(json);
36 37
 
37 38
         return result.withDefaultOptions(defaultOptions);
38 39
     }
@@ -48,6 +49,7 @@ public class Options {
48 49
     @NonNull public AnimationsOptions animations = new AnimationsOptions();
49 50
     @NonNull public SideMenuRootOptions sideMenuRootOptions = new SideMenuRootOptions();
50 51
     @NonNull public Color screenBackgroundColor = new NullColor();
52
+    @NonNull public ModalOptions modal = new ModalOptions();
51 53
 
52 54
     void setTopTabIndex(int i) {
53 55
         topTabOptions.tabIndex = i;
@@ -67,6 +69,7 @@ public class Options {
67 69
         result.sideMenuRootOptions.mergeWith(sideMenuRootOptions);
68 70
         result.animations.mergeWith(animations);
69 71
         result.screenBackgroundColor = screenBackgroundColor;
72
+        result.modal.mergeWith(modal);
70 73
         return result;
71 74
     }
72 75
 
@@ -83,6 +86,7 @@ public class Options {
83 86
         result.animations.mergeWith(other.animations);
84 87
         result.sideMenuRootOptions.mergeWith(other.sideMenuRootOptions);
85 88
         if (other.screenBackgroundColor.hasValue()) result.screenBackgroundColor = other.screenBackgroundColor;
89
+        result.modal.mergeWith(other.modal);
86 90
         return result;
87 91
     }
88 92
 
@@ -97,6 +101,7 @@ public class Options {
97 101
         animations.mergeWithDefault(defaultOptions.animations);
98 102
         sideMenuRootOptions.mergeWithDefault(defaultOptions.sideMenuRootOptions);
99 103
         if (!screenBackgroundColor.hasValue()) screenBackgroundColor = defaultOptions.screenBackgroundColor;
104
+        modal.mergeWithDefault(defaultOptions.modal);
100 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 Dosyayı Görüntüle

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