瀏覽代碼

dismissAllModals

Daniel Zlotin 8 年之前
父節點
當前提交
85cf841e5d

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactModule.java 查看文件

@@ -104,7 +104,8 @@ public class NavigationReactModule extends ReactContextBaseJavaModule {
104 104
     }
105 105
 
106 106
     @ReactMethod
107
-    public void dismissAllModals(final ReadableMap params) {
107
+    public void dismissAllModals() {
108
+        NavigationCommandsHandler.dismissAlModals();
108 109
     }
109 110
 
110 111
     @ReactMethod

+ 8
- 1
android/app/src/main/java/com/reactnativenavigation/controllers/ModalController.java 查看文件

@@ -22,12 +22,18 @@ public class ModalController implements ScreenStackContainer, Modal.OnModalDismi
22 22
         stack.add(modal);
23 23
     }
24 24
 
25
-    public void dismissModal() {
25
+    public void dismissTopModal() {
26 26
         if (isShowing()) {
27 27
             stack.pop().dismiss();
28 28
         }
29 29
     }
30 30
 
31
+    public void dismissAllModals() {
32
+        while (isShowing()) {
33
+            dismissTopModal();
34
+        }
35
+    }
36
+
31 37
     public boolean onBackPressed() {
32 38
         Log.d("LOG", "ModalController.onBackPressed ");
33 39
         return false;
@@ -69,4 +75,5 @@ public class ModalController implements ScreenStackContainer, Modal.OnModalDismi
69 75
     public void onModalDismissed(Modal modal) {
70 76
         stack.remove(modal);
71 77
     }
78
+
72 79
 }

+ 5
- 1
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java 查看文件

@@ -150,6 +150,10 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
150 150
     }
151 151
 
152 152
     void dismissTopModal() {
153
-        modalController.dismissModal();
153
+        modalController.dismissTopModal();
154
+    }
155
+
156
+    void dismissAllModals() {
157
+        modalController.dismissAllModals();
154 158
     }
155 159
 }

+ 14
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationCommandsHandler.java 查看文件

@@ -164,4 +164,18 @@ public class NavigationCommandsHandler {
164 164
             }
165 165
         });
166 166
     }
167
+
168
+    public static void dismissAlModals() {
169
+        final NavigationActivity currentActivity = NavigationActivity.currentActivity;
170
+        if (currentActivity == null) {
171
+            return;
172
+        }
173
+
174
+        NavigationApplication.instance.runOnMainThread(new Runnable() {
175
+            @Override
176
+            public void run() {
177
+                currentActivity.dismissAllModals();
178
+            }
179
+        });
180
+    }
167 181
 }

+ 1
- 1
src/deprecated/platformSpecificDeprecated.android.js 查看文件

@@ -215,7 +215,7 @@ function dismissModal() {
215 215
 }
216 216
 
217 217
 function dismissAllModals(params) {
218
-  //RctActivity.dismissAllModals(params.animationType);
218
+  newPlatformSpecific.dismissAllModals();
219 219
 }
220 220
 
221 221
 function addNavigatorParams(screen, navigator = null, idx = '') {

+ 17
- 12
src/platformSpecific.android.js 查看文件

@@ -4,7 +4,7 @@ import _ from 'lodash';
4 4
 
5 5
 import Navigation from './Navigation';
6 6
 
7
-NativeBridge = NativeModules.NavigationReactModule;
7
+const NativeReactModule = NativeModules.NavigationReactModule;
8 8
 
9 9
 const resolveAssetSource = require('react-native/Libraries/Image/resolveAssetSource');
10 10
 
@@ -15,43 +15,47 @@ function startApp(activityParams) {
15 15
     return;
16 16
   }
17 17
 
18
-  NativeBridge.startApp(activityParams);
18
+  NativeReactModule.startApp(activityParams);
19 19
 }
20 20
 
21 21
 function push(screenParams) {
22
-  NativeBridge.push(screenParams);
22
+  NativeReactModule.push(screenParams);
23 23
 }
24 24
 
25 25
 function pop(screenParams) {
26
-  NativeBridge.pop(screenParams);
26
+  NativeReactModule.pop(screenParams);
27 27
 }
28 28
 
29 29
 function popToRoot(screenParams) {
30
-  NativeBridge.popToRoot(screenParams);
30
+  NativeReactModule.popToRoot(screenParams);
31 31
 }
32 32
 
33 33
 function newStack(screenParams) {
34
-  NativeBridge.newStack(screenParams);
34
+  NativeReactModule.newStack(screenParams);
35 35
 }
36 36
 
37 37
 function toggleTopBarVisible(screenInstanceID, visible, animated) {
38
-  NativeBridge.setTopBarVisible(screenInstanceID, visible, animated);
38
+  NativeReactModule.setTopBarVisible(screenInstanceID, visible, animated);
39 39
 }
40 40
 
41 41
 function setScreenTitleBarTitle(screenInstanceID, title) {
42
-  NativeBridge.setScreenTitleBarTitle(screenInstanceID, title);
42
+  NativeReactModule.setScreenTitleBarTitle(screenInstanceID, title);
43 43
 }
44 44
 
45 45
 function setScreenTitleBarButtons(screenInstanceID, navigatorEventID, buttons) {
46
-  NativeBridge.setScreenTitleBarButtons(screenInstanceID, navigatorEventID, buttons);
46
+  NativeReactModule.setScreenTitleBarButtons(screenInstanceID, navigatorEventID, buttons);
47 47
 }
48 48
 
49 49
 function showModal(screenParams) {
50
-  NativeBridge.showModal(screenParams);
50
+  NativeReactModule.showModal(screenParams);
51 51
 }
52 52
 
53 53
 function dismissTopModal() {
54
-  NativeBridge.dismissTopModal();
54
+  NativeReactModule.dismissTopModal();
55
+}
56
+
57
+function dismissAllModals() {
58
+  NativeReactModule.dismissAllModals();
55 59
 }
56 60
 
57 61
 module.exports = {
@@ -64,5 +68,6 @@ module.exports = {
64 68
   setScreenTitleBarTitle,
65 69
   setScreenTitleBarButtons,
66 70
   showModal,
67
-  dismissTopModal
71
+  dismissTopModal,
72
+  dismissAllModals
68 73
 };