Browse Source

Implement dismissAllModals

Guy Carmeli 8 years ago
parent
commit
829c327d0f

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

7
 
7
 
8
 import java.lang.ref.WeakReference;
8
 import java.lang.ref.WeakReference;
9
 import java.util.HashMap;
9
 import java.util.HashMap;
10
+import java.util.Iterator;
10
 import java.util.Map;
11
 import java.util.Map;
11
 
12
 
12
 /**
13
 /**
33
         mModals.put(navigatorId, new WeakReference<>(modal));
34
         mModals.put(navigatorId, new WeakReference<>(modal));
34
     }
35
     }
35
 
36
 
37
+    public boolean isModalDisplayed() {
38
+        return mModals.size() != 0;
39
+    }
40
+
36
     public boolean isModalDisplayed(String navigatorId) {
41
     public boolean isModalDisplayed(String navigatorId) {
37
         return mModals.size() != 0 && mModals.containsKey(navigatorId);
42
         return mModals.size() != 0 && mModals.containsKey(navigatorId);
38
     }
43
     }
51
             mModals.remove(navigatorId);
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 View File

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 View File

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

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

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