|
@@ -3,6 +3,7 @@ package com.reactnativenavigation.viewcontrollers.modal;
|
3
|
3
|
import android.animation.Animator;
|
4
|
4
|
import android.animation.AnimatorListenerAdapter;
|
5
|
5
|
import android.support.annotation.NonNull;
|
|
6
|
+import android.support.annotation.Nullable;
|
6
|
7
|
import android.view.ViewGroup;
|
7
|
8
|
|
8
|
9
|
import com.reactnativenavigation.anim.ModalAnimator;
|
|
@@ -14,7 +15,7 @@ import com.reactnativenavigation.viewcontrollers.ViewController;
|
14
|
15
|
|
15
|
16
|
public class ModalPresenter {
|
16
|
17
|
|
17
|
|
- private ViewGroup content;
|
|
18
|
+ @Nullable private ViewGroup content;
|
18
|
19
|
private ModalAnimator animator;
|
19
|
20
|
private Options defaultOptions = new Options();
|
20
|
21
|
private EventEmitter eventEmitter;
|
|
@@ -32,6 +33,10 @@ public class ModalPresenter {
|
32
|
33
|
}
|
33
|
34
|
|
34
|
35
|
public void showModal(ViewController toAdd, ViewController toRemove, CommandListener listener) {
|
|
36
|
+ if (content == null) {
|
|
37
|
+ listener.onError("Could not show modal before setRoot is called");
|
|
38
|
+ return;
|
|
39
|
+ }
|
35
|
40
|
Options options = toAdd.resolveCurrentOptions(defaultOptions);
|
36
|
41
|
toAdd.setWaitForRender(options.animations.showModal.waitForRender);
|
37
|
42
|
content.addView(toAdd.getView());
|
|
@@ -67,11 +72,19 @@ public class ModalPresenter {
|
67
|
72
|
}
|
68
|
73
|
|
69
|
74
|
public void dismissTopModal(ViewController toDismiss, @NonNull ViewController toAdd, CommandListener listener) {
|
|
75
|
+ if (content == null) {
|
|
76
|
+ listener.onError("Could not dismiss modal before setRoot is called");
|
|
77
|
+ return;
|
|
78
|
+ }
|
70
|
79
|
toAdd.attachView(content, 0);
|
71
|
80
|
dismissModal(toDismiss, listener);
|
72
|
81
|
}
|
73
|
82
|
|
74
|
83
|
public void dismissModal(ViewController toDismiss, CommandListener listener) {
|
|
84
|
+ if (content == null) {
|
|
85
|
+ listener.onError("Could not dismiss modal before setRoot is called");
|
|
86
|
+ return;
|
|
87
|
+ }
|
75
|
88
|
if (toDismiss.options.animations.dismissModal.enable.isTrueOrUndefined()) {
|
76
|
89
|
animator.dismiss(toDismiss.getView(), toDismiss.options.animations.dismissModal, new AnimatorListenerAdapter() {
|
77
|
90
|
@Override
|