|
@@ -3,47 +3,33 @@ package com.reactnativenavigation.controllers;
|
3
|
3
|
import android.support.annotation.Nullable;
|
4
|
4
|
|
5
|
5
|
import com.reactnativenavigation.modal.RnnModal;
|
6
|
|
-import com.reactnativenavigation.utils.RefUtils;
|
7
|
6
|
|
8
|
|
-import java.lang.ref.WeakReference;
|
9
|
7
|
import java.util.Stack;
|
10
|
8
|
|
11
|
|
-/**
|
12
|
|
- * Created by guyc on 06/05/16.
|
13
|
|
- */
|
14
|
9
|
public class ModalController {
|
15
|
|
- private static ModalController sInstance;
|
16
|
10
|
|
17
|
|
- private final Stack<WeakReference<RnnModal>> mModals;
|
|
11
|
+ private final Stack<RnnModal> modals;
|
18
|
12
|
|
19
|
|
- private ModalController() {
|
20
|
|
- mModals = new Stack<>();
|
21
|
|
- }
|
22
|
|
-
|
23
|
|
- public static synchronized ModalController getInstance() {
|
24
|
|
- if (sInstance == null) {
|
25
|
|
- sInstance = new ModalController();
|
26
|
|
- }
|
27
|
|
-
|
28
|
|
- return sInstance;
|
|
13
|
+ public ModalController() {
|
|
14
|
+ modals = new Stack<>();
|
29
|
15
|
}
|
30
|
16
|
|
31
|
17
|
public void add(RnnModal modal) {
|
32
|
|
- mModals.add(new WeakReference<>(modal));
|
|
18
|
+ modals.add(modal);
|
33
|
19
|
}
|
34
|
20
|
|
35
|
21
|
public boolean isModalDisplayed() {
|
36
|
|
- return mModals.size() != 0;
|
|
22
|
+ return !modals.isEmpty();
|
37
|
23
|
}
|
38
|
24
|
|
39
|
25
|
@Nullable
|
40
|
26
|
public RnnModal get() {
|
41
|
|
- return isModalDisplayed() ? RefUtils.get(mModals.peek()) : null;
|
|
27
|
+ return isModalDisplayed() ? modals.peek() : null;
|
42
|
28
|
}
|
43
|
29
|
|
44
|
30
|
public void remove() {
|
45
|
31
|
if (isModalDisplayed()) {
|
46
|
|
- mModals.pop();
|
|
32
|
+ modals.pop();
|
47
|
33
|
}
|
48
|
34
|
}
|
49
|
35
|
|
|
@@ -54,10 +40,16 @@ public class ModalController {
|
54
|
40
|
}
|
55
|
41
|
|
56
|
42
|
public void dismissModal() {
|
57
|
|
- WeakReference<RnnModal> ref = mModals.pop();
|
58
|
|
- RnnModal modal = RefUtils.get(ref);
|
59
|
|
- if (modal != null) {
|
60
|
|
- modal.dismiss();
|
|
43
|
+ if (isModalDisplayed()) {
|
|
44
|
+ modals.pop().dismiss();
|
61
|
45
|
}
|
62
|
46
|
}
|
|
47
|
+
|
|
48
|
+ public void onDestroy() {
|
|
49
|
+
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ public boolean onBackPressed() {
|
|
53
|
+ return false;
|
|
54
|
+ }
|
63
|
55
|
}
|