|
@@ -8,6 +8,7 @@ import com.reactnativenavigation.anim.ModalAnimator;
|
8
|
8
|
import com.reactnativenavigation.parse.Options;
|
9
|
9
|
import com.reactnativenavigation.react.EventEmitter;
|
10
|
10
|
import com.reactnativenavigation.utils.CommandListener;
|
|
11
|
+import com.reactnativenavigation.utils.CommandListenerAdapter;
|
11
|
12
|
import com.reactnativenavigation.viewcontrollers.ViewController;
|
12
|
13
|
|
13
|
14
|
import java.util.ArrayList;
|
|
@@ -19,6 +20,11 @@ import javax.annotation.Nullable;
|
19
|
20
|
public class ModalStack {
|
20
|
21
|
private List<ViewController> modals = new ArrayList<>();
|
21
|
22
|
private final ModalPresenter presenter;
|
|
23
|
+ private EventEmitter eventEmitter;
|
|
24
|
+
|
|
25
|
+ public void setEventEmitter(EventEmitter eventEmitter) {
|
|
26
|
+ this.eventEmitter = eventEmitter;
|
|
27
|
+ }
|
22
|
28
|
|
23
|
29
|
public ModalStack(Activity activity) {
|
24
|
30
|
this.presenter = new ModalPresenter(new ModalAnimator(activity));
|
|
@@ -49,10 +55,17 @@ public class ModalStack {
|
49
|
55
|
boolean isTop = isTop(toDismiss);
|
50
|
56
|
modals.remove(toDismiss);
|
51
|
57
|
ViewController toAdd = isEmpty() ? root : isTop ? get(size() - 1) : null;
|
|
58
|
+ CommandListenerAdapter onDismiss = new CommandListenerAdapter(listener) {
|
|
59
|
+ @Override
|
|
60
|
+ public void onSuccess(String childId) {
|
|
61
|
+ super.onSuccess(childId);
|
|
62
|
+ eventEmitter.emitModalDismissed(toDismiss.getId(), 1);
|
|
63
|
+ }
|
|
64
|
+ };
|
52
|
65
|
if (isTop) {
|
53
|
|
- presenter.dismissTopModal(toDismiss, toAdd, listener);
|
|
66
|
+ presenter.dismissTopModal(toDismiss, toAdd, onDismiss);
|
54
|
67
|
} else {
|
55
|
|
- presenter.dismissModal(toDismiss, listener);
|
|
68
|
+ presenter.dismissModal(toDismiss, onDismiss);
|
56
|
69
|
}
|
57
|
70
|
} else {
|
58
|
71
|
listener.onError("Nothing to dismiss");
|
|
@@ -65,9 +78,18 @@ public class ModalStack {
|
65
|
78
|
return;
|
66
|
79
|
}
|
67
|
80
|
|
|
81
|
+ String topModalId = peek().getId();
|
|
82
|
+ int modalsDismissed = size();
|
|
83
|
+
|
68
|
84
|
while (!modals.isEmpty()) {
|
69
|
85
|
if (modals.size() == 1) {
|
70
|
|
- dismissModal(modals.get(0).getId(), root, listener);
|
|
86
|
+ dismissModal(modals.get(0).getId(), root, new CommandListenerAdapter(listener) {
|
|
87
|
+ @Override
|
|
88
|
+ public void onSuccess(String childId) {
|
|
89
|
+ super.onSuccess(childId);
|
|
90
|
+ eventEmitter.emitModalDismissed(topModalId, modalsDismissed);
|
|
91
|
+ }
|
|
92
|
+ });
|
71
|
93
|
} else {
|
72
|
94
|
modals.get(0).destroy();
|
73
|
95
|
modals.remove(0);
|
|
@@ -126,8 +148,4 @@ public class ModalStack {
|
126
|
148
|
}
|
127
|
149
|
return null;
|
128
|
150
|
}
|
129
|
|
-
|
130
|
|
- public void setEventEmitter(EventEmitter eventEmitter) {
|
131
|
|
- presenter.setEventEmitter(eventEmitter);
|
132
|
|
- }
|
133
|
151
|
}
|