|
@@ -1,28 +1,19 @@
|
1
|
1
|
package com.reactnativenavigation.viewcontrollers;
|
2
|
2
|
|
3
|
3
|
import android.app.Activity;
|
4
|
|
-import android.app.Dialog;
|
5
|
4
|
import android.support.annotation.NonNull;
|
6
|
|
-import android.support.annotation.Nullable;
|
7
|
|
-import android.support.v4.util.Pair;
|
8
|
5
|
import android.view.ViewGroup;
|
9
|
6
|
import android.widget.FrameLayout;
|
10
|
7
|
|
11
|
|
-import com.reactnativenavigation.R;
|
12
|
8
|
import com.reactnativenavigation.utils.CompatUtils;
|
13
|
9
|
|
14
|
10
|
import java.util.Collection;
|
15
|
11
|
import java.util.Collections;
|
16
|
|
-import java.util.HashMap;
|
17
|
|
-import java.util.Map;
|
18
|
|
-
|
19
|
|
-import static android.view.View.MeasureSpec.EXACTLY;
|
20
|
|
-import static android.view.View.MeasureSpec.makeMeasureSpec;
|
21
|
12
|
|
22
|
13
|
public class Navigator extends ParentController {
|
23
|
14
|
|
|
15
|
+ private final ModalStack modalStack = new ModalStack();
|
24
|
16
|
private ViewController root;
|
25
|
|
- private HashMap<ViewController, Dialog> modals = new HashMap<>();
|
26
|
17
|
|
27
|
18
|
public Navigator(final Activity activity) {
|
28
|
19
|
super(activity, "navigator" + CompatUtils.generateViewId());
|
|
@@ -108,29 +99,14 @@ public class Navigator extends ParentController {
|
108
|
99
|
}
|
109
|
100
|
|
110
|
101
|
public void showModal(final ViewController viewController) {
|
111
|
|
- viewController.getView().measure(makeMeasureSpec(getView().getWidth(), EXACTLY), makeMeasureSpec(getView().getHeight(), EXACTLY));
|
112
|
|
- Dialog dialog = new Dialog(getActivity(), R.style.Modal);
|
113
|
|
- dialog.setContentView(viewController.getView());
|
114
|
|
- dialog.show();
|
115
|
|
- modals.put(viewController, dialog);
|
|
102
|
+ modalStack.showModal(viewController);
|
116
|
103
|
}
|
117
|
104
|
|
118
|
105
|
public void dismissModal(final String containerId) {
|
119
|
|
- Pair<ViewController, Dialog> pair = findModalByContainerId(containerId);
|
120
|
|
- if (pair != null) {
|
121
|
|
- pair.second.dismiss();
|
122
|
|
- modals.remove(pair.first);
|
123
|
|
- }
|
|
106
|
+ modalStack.dismissModal(containerId);
|
124
|
107
|
}
|
125
|
108
|
|
126
|
|
- @Nullable
|
127
|
|
- private Pair<ViewController, Dialog> findModalByContainerId(String containerId) {
|
128
|
|
- for (Map.Entry<ViewController, Dialog> entry : modals.entrySet()) {
|
129
|
|
- ViewController vc = entry.getKey().findControllerById(containerId);
|
130
|
|
- if (vc != null) {
|
131
|
|
- return Pair.create(entry.getKey(), entry.getValue());
|
132
|
|
- }
|
133
|
|
- }
|
134
|
|
- return null;
|
|
109
|
+ public void dismissAllModals() {
|
|
110
|
+ modalStack.dismissAll();
|
135
|
111
|
}
|
136
|
112
|
}
|