Sfoglia il codice sorgente

Implement dismissAllModals

Guy Carmeli 8 anni fa
parent
commit
829c327d0f

+ 16
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/ModalController.java Vedi File

@@ -7,6 +7,7 @@ import com.reactnativenavigation.utils.RefUtils;
7 7
 
8 8
 import java.lang.ref.WeakReference;
9 9
 import java.util.HashMap;
10
+import java.util.Iterator;
10 11
 import java.util.Map;
11 12
 
12 13
 /**
@@ -33,6 +34,10 @@ public class ModalController {
33 34
         mModals.put(navigatorId, new WeakReference<>(modal));
34 35
     }
35 36
 
37
+    public boolean isModalDisplayed() {
38
+        return mModals.size() != 0;
39
+    }
40
+
36 41
     public boolean isModalDisplayed(String navigatorId) {
37 42
         return mModals.size() != 0 && mModals.containsKey(navigatorId);
38 43
     }
@@ -51,4 +56,15 @@ public class ModalController {
51 56
             mModals.remove(navigatorId);
52 57
         }
53 58
     }
59
+
60
+    public void dismissAllModals() {
61
+        Iterator<String> iterator = mModals.keySet().iterator();
62
+        while (iterator.hasNext()) {
63
+            WeakReference<RnnModal> ref = mModals.get(iterator.next());
64
+            RnnModal modal = RefUtils.get(ref);
65
+            if (modal != null) {
66
+                modal.dismiss();
67
+            }
68
+        }
69
+    }
54 70
 }

+ 16
- 0
android/app/src/main/java/com/reactnativenavigation/modules/RctActivityModule.java Vedi File

@@ -147,4 +147,20 @@ public class RctActivityModule extends ReactContextBaseJavaModule {
147 147
             });
148 148
         }
149 149
     }
150
+
151
+    @ReactMethod
152
+    public void dismissAllModals(final ReadableMap params) {
153
+        final BaseReactActivity context = ContextProvider.getActivityContext();
154
+        if (context != null && !context.isFinishing()) {
155
+        context.runOnUiThread(new Runnable() {
156
+            @Override
157
+            public void run() {
158
+                ModalController modalController = ModalController.getInstance();
159
+                if (modalController.isModalDisplayed()) {
160
+                    modalController.dismissAllModals();
161
+                }
162
+            }
163
+        });
164
+        }
165
+    }
150 166
 }

+ 1
- 1
android/app/src/main/res/anim/slide_up.xml Vedi File

@@ -5,5 +5,5 @@
5 5
     <translate
6 6
         android:fromYDelta="100%"
7 7
         android:toYDelta="0"
8
-        android:duration="350"/>
8
+        android:duration="250"/>
9 9
 </set>

+ 6
- 1
src/platformSpecific.android.js Vedi File

@@ -58,6 +58,10 @@ function showModal(params) {
58 58
   RctActivity.showModal(params);
59 59
 }
60 60
 
61
+function dismissAllModals(params) {
62
+  RctActivity.dismissAllModals(params.animationType);
63
+}
64
+
61 65
 function addNavigatorParams(screen, navigator = null, idx = '') {
62 66
   screen.navigatorID = navigator ? navigator.navigatorID : utils.getRandomId() + '_nav' + idx;
63 67
   screen.screenInstanceID = utils.getRandomId();
@@ -91,5 +95,6 @@ export default {
91 95
   startSingleScreenApp,
92 96
   navigatorPush,
93 97
   navigatorPop,
94
-  showModal
98
+  showModal,
99
+  dismissAllModals
95 100
 }