Sfoglia il codice sorgente

Attach root to rootLayout after modal dismiss

When dismissing a modal the root layout was added to modalsLayout instead of rootLayout.
Guy Carmeli 6 anni fa
parent
commit
b944f65c2f

+ 17
- 20
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/modal/ModalPresenter.java Vedi File

@@ -2,7 +2,6 @@ package com.reactnativenavigation.viewcontrollers.modal;
2 2
 
3 3
 import android.animation.Animator;
4 4
 import android.animation.AnimatorListenerAdapter;
5
-import android.support.annotation.NonNull;
6 5
 import android.support.annotation.Nullable;
7 6
 import android.view.ViewGroup;
8 7
 
@@ -14,7 +13,8 @@ import com.reactnativenavigation.viewcontrollers.ViewController;
14 13
 
15 14
 public class ModalPresenter {
16 15
 
17
-    private ViewGroup modalsContainer;
16
+    private ViewGroup rootLayout;
17
+    private ViewGroup modalsLayout;
18 18
     private ModalAnimator animator;
19 19
     private Options defaultOptions = new Options();
20 20
 
@@ -22,22 +22,26 @@ public class ModalPresenter {
22 22
         this.animator = animator;
23 23
     }
24 24
 
25
-    public void setModalsContainer(ViewGroup modalsLayout) {
26
-        this.modalsContainer = modalsLayout;
25
+    public void setRootLayout(ViewGroup rootLayout) {
26
+        this.rootLayout = rootLayout;
27
+    }
28
+
29
+    void setModalsLayout(ViewGroup modalsLayout) {
30
+        this.modalsLayout = modalsLayout;
27 31
     }
28 32
 
29 33
     public void setDefaultOptions(Options defaultOptions) {
30 34
         this.defaultOptions = defaultOptions;
31 35
     }
32 36
 
33
-    public void showModal(ViewController toAdd, ViewController toRemove, CommandListener listener) {
34
-        if (modalsContainer == null) {
37
+    void showModal(ViewController toAdd, ViewController toRemove, CommandListener listener) {
38
+        if (modalsLayout == null) {
35 39
             listener.onError("Can not show modal before activity is created");
36 40
             return;
37 41
         }
38 42
         Options options = toAdd.resolveCurrentOptions(defaultOptions);
39 43
         toAdd.setWaitForRender(options.animations.showModal.waitForRender);
40
-        modalsContainer.addView(toAdd.getView());
44
+        modalsLayout.addView(toAdd.getView());
41 45
         if (options.animations.showModal.enabled.isTrueOrUndefined()) {
42 46
             if (options.animations.showModal.waitForRender.isTrue()) {
43 47
                 toAdd.setOnAppearedListener(() -> animateShow(toAdd, toRemove, listener, options));
@@ -69,22 +73,15 @@ public class ModalPresenter {
69 73
         listener.onSuccess(toAdd.getId());
70 74
     }
71 75
 
72
-    public void dismissTopModal(ViewController toDismiss, @NonNull ViewController toAdd, CommandListener listener) {
73
-        if (modalsContainer == null) {
74
-            listener.onError("Can not dismiss modal before activity is created");
75
-            return;
76
-        }
77
-        toAdd.attachView(modalsContainer, 0);
78
-        dismissModal(toDismiss, listener);
79
-    }
80
-
81
-    public void dismissModal(ViewController toDismiss, CommandListener listener) {
82
-        if (modalsContainer == null) {
76
+    void dismissModal(ViewController toDismiss, @Nullable ViewController toAdd, ViewController root, CommandListener listener) {
77
+        if (modalsLayout == null) {
83 78
             listener.onError("Can not dismiss modal before activity is created");
84 79
             return;
85 80
         }
86
-        if (toDismiss.options.animations.dismissModal.enabled.isTrueOrUndefined()) {
87
-            animator.dismiss(toDismiss.getView(), toDismiss.options.animations.dismissModal, new AnimatorListenerAdapter() {
81
+        if (toAdd != null) toAdd.attachView(toAdd == root ? rootLayout : modalsLayout, 0);
82
+        Options options = toDismiss.resolveCurrentOptions(defaultOptions);
83
+        if (options.animations.dismissModal.enabled.isTrueOrUndefined()) {
84
+            animator.dismiss(toDismiss.getView(), options.animations.dismissModal, new AnimatorListenerAdapter() {
88 85
                 @Override
89 86
                 public void onAnimationEnd(Animator animation) {
90 87
                     onDismissEnd(toDismiss, listener);

+ 11
- 9
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/modal/ModalStack.java Vedi File

@@ -35,8 +35,12 @@ public class ModalStack {
35 35
         this.presenter = presenter;
36 36
     }
37 37
 
38
-    public void setModalsContainer(ViewGroup modalsLayout) {
39
-        presenter.setModalsContainer(modalsLayout);
38
+    public void setModalsLayout(ViewGroup modalsLayout) {
39
+        presenter.setModalsLayout(modalsLayout);
40
+    }
41
+
42
+    public void setRootLayout(ViewGroup rootLayout) {
43
+        presenter.setRootLayout(rootLayout);
40 44
     }
41 45
 
42 46
     public void setDefaultOptions(Options defaultOptions) {
@@ -52,9 +56,9 @@ public class ModalStack {
52 56
     public boolean dismissModal(String componentId, @Nullable ViewController root, CommandListener listener) {
53 57
         ViewController toDismiss = findModalByComponentId(componentId);
54 58
         if (toDismiss != null) {
55
-            boolean isTop = isTop(toDismiss);
59
+            boolean isDismissingTopModal = isTop(toDismiss);
56 60
             modals.remove(toDismiss);
57
-            @Nullable ViewController toAdd = isEmpty() ? root : isTop ? get(size() - 1) : null;
61
+            @Nullable ViewController toAdd = isEmpty() ? root : isDismissingTopModal ? get(size() - 1) : null;
58 62
             CommandListenerAdapter onDismiss = new CommandListenerAdapter(listener) {
59 63
                 @Override
60 64
                 public void onSuccess(String childId) {
@@ -62,15 +66,13 @@ public class ModalStack {
62 66
                     super.onSuccess(childId);
63 67
                 }
64 68
             };
65
-            if (isTop) {
69
+            if (isDismissingTopModal) {
66 70
                 if (toAdd == null) {
67 71
                     listener.onError("Could not dismiss modal");
68 72
                     return false;
69 73
                 }
70
-                presenter.dismissTopModal(toDismiss, toAdd, onDismiss);
71
-            } else {
72
-                presenter.dismissModal(toDismiss, onDismiss);
73 74
             }
75
+            presenter.dismissModal(toDismiss, toAdd, root, onDismiss);
74 76
             return true;
75 77
         } else {
76 78
             listener.onError("Nothing to dismiss");
@@ -113,7 +115,7 @@ public class ModalStack {
113 115
         return dismissModal(peek().getId(), root, listener);
114 116
     }
115 117
 
116
-    public ViewController peek() {
118
+    ViewController peek() {
117 119
         if (modals.isEmpty()) throw new EmptyStackException();
118 120
         return modals.get(modals.size() - 1);
119 121
     }

+ 2
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/navigator/Navigator.java Vedi File

@@ -72,7 +72,8 @@ public class Navigator extends ParentController {
72 72
     }
73 73
 
74 74
     public void bindViews() {
75
-        modalStack.setModalsContainer(modalsLayout);
75
+        modalStack.setModalsLayout(modalsLayout);
76
+        modalStack.setRootLayout(rootLayout);
76 77
         rootPresenter.setRootContainer(rootLayout);
77 78
     }
78 79
 

+ 28
- 26
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalPresenterTest.java Vedi File

@@ -36,9 +36,9 @@ public class ModalPresenterTest extends BaseTest {
36 36
     private ChildController modal1;
37 37
     private ChildController modal2;
38 38
     private ModalPresenter uut;
39
-    private FrameLayout contentLayout;
40 39
     private ModalAnimator animator;
41 40
     private ViewController root;
41
+    private FrameLayout modalsLayout;
42 42
 
43 43
     @Override
44 44
     public void beforeEach() {
@@ -46,13 +46,18 @@ public class ModalPresenterTest extends BaseTest {
46 46
         ChildControllersRegistry childRegistry = new ChildControllersRegistry();
47 47
 
48 48
         root = spy(new SimpleViewController(activity, childRegistry, "root", new Options()));
49
-        contentLayout = new FrameLayout(activity);
50
-        contentLayout.addView(root.getView());
49
+        FrameLayout contentLayout = new FrameLayout(activity);
50
+        FrameLayout rootLayout = new FrameLayout(activity);
51
+        rootLayout.addView(root.getView());
52
+        modalsLayout = new FrameLayout(activity);
53
+        contentLayout.addView(rootLayout);
54
+        contentLayout.addView(modalsLayout);
51 55
         activity.setContentView(contentLayout);
52 56
 
53 57
         animator = spy(new ModalAnimator(activity));
54 58
         uut = new ModalPresenter(animator);
55
-        uut.setModalsContainer(contentLayout);
59
+        uut.setModalsLayout(modalsLayout);
60
+        uut.setRootLayout(rootLayout);
56 61
         modal1 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_1, new Options()));
57 62
         modal2 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_2, new Options()));
58 63
     }
@@ -73,7 +78,7 @@ public class ModalPresenterTest extends BaseTest {
73 78
         CommandListener listener = spy(new CommandListenerAdapter() {
74 79
             @Override
75 80
             public void onSuccess(String childId) {
76
-                assertThat(modal1.getView().getParent()).isEqualTo(contentLayout);
81
+                assertThat(modal1.getView().getParent()).isEqualTo(modalsLayout);
77 82
                 verify(modal1, times(1)).onViewAppeared();
78 83
             }
79 84
         });
@@ -139,7 +144,7 @@ public class ModalPresenterTest extends BaseTest {
139 144
 
140 145
     @Test
141 146
     public void showModal_rejectIfContentIsNull() {
142
-        uut.setModalsContainer(null);
147
+        uut.setModalsLayout(null);
143 148
         CommandListenerAdapter listener = Mockito.mock(CommandListenerAdapter.class);
144 149
         uut.showModal(modal1, modal2, listener);
145 150
         verify(listener).onError(any());
@@ -150,7 +155,7 @@ public class ModalPresenterTest extends BaseTest {
150 155
         disableShowModalAnimation(modal1);
151 156
 
152 157
         uut.showModal(modal1, root, new CommandListenerAdapter());
153
-        uut.dismissTopModal(modal1, root, new CommandListenerAdapter() {
158
+        uut.dismissModal(modal1, root, root, new CommandListenerAdapter() {
154 159
             @Override
155 160
             public void onSuccess(String childId) {
156 161
                 verify(modal1, times(1)).onViewDisappear();
@@ -158,16 +163,19 @@ public class ModalPresenterTest extends BaseTest {
158 163
             }
159 164
         });
160 165
 
161
-        verify(animator, times(1)).dismiss(eq(modal1.getView()), eq(modal1.options.animations.dismissModal), any());
166
+        verify(animator).dismiss(eq(modal1.getView()), any(), any());
162 167
     }
163 168
 
164 169
     @Test
165 170
     public void dismissModal_previousViewIsAddedAtIndex0() {
166
-        modal2.ensureViewIsCreated();
171
+        disableShowModalAnimation(modal1);
167 172
         FrameLayout spy = spy(new FrameLayout(newActivity()));
168
-        uut.setModalsContainer(spy);
169
-        uut.dismissTopModal(modal1, modal2, new CommandListenerAdapter());
170
-        verify(spy, times(1)).addView(modal2.getView(), 0);
173
+        uut.setRootLayout(spy);
174
+
175
+        uut.showModal(modal1, root, new CommandListenerAdapter());
176
+        uut.dismissModal(modal1, root, root, new CommandListenerAdapter());
177
+
178
+        verify(spy).addView(root.getView(), 0);
171 179
     }
172 180
 
173 181
     @Test
@@ -176,7 +184,7 @@ public class ModalPresenterTest extends BaseTest {
176 184
         disableDismissModalAnimation(modal1);
177 185
 
178 186
         uut.showModal(modal1, root, new CommandListenerAdapter());
179
-        uut.dismissTopModal(modal1, root, new CommandListenerAdapter());
187
+        uut.dismissModal(modal1, root, root, new CommandListenerAdapter());
180 188
         verify(modal1, times(1)).onViewDisappear();
181 189
         verify(modal1, times(1)).destroy();
182 190
         verify(animator, times(0)).dismiss(any(), eq(modal1.options.animations.dismissModal), any());
@@ -187,9 +195,11 @@ public class ModalPresenterTest extends BaseTest {
187 195
         disableShowModalAnimation(modal1, modal2);
188 196
 
189 197
         uut.showModal(modal1, root, new CommandListenerAdapter());
198
+        verify(modal1).onViewAppeared();
190 199
         uut.showModal(modal2, modal1, new CommandListenerAdapter());
191 200
         assertThat(modal1.getView().getParent()).isNull();
192
-        uut.dismissTopModal(modal2, modal1, new CommandListenerAdapter());
201
+        uut.dismissModal(modal2, modal1, root, new CommandListenerAdapter());
202
+        assertThat(modal1.getView().getParent()).isNotNull();
193 203
         verify(modal1, times(2)).onViewAppeared();
194 204
     }
195 205
 
@@ -203,10 +213,10 @@ public class ModalPresenterTest extends BaseTest {
203 213
         assertThat(modal1.getView().getParent()).isNull();
204 214
         assertThat(root.getView().getParent()).isNull();
205 215
 
206
-        uut.dismissModal(modal1, new CommandListenerAdapter());
216
+        uut.dismissModal(modal1, null, root, new CommandListenerAdapter());
207 217
         assertThat(root.getView().getParent()).isNull();
208 218
 
209
-        uut.dismissTopModal(modal2, root, new CommandListenerAdapter());
219
+        uut.dismissModal(modal2, root, root, new CommandListenerAdapter());
210 220
         assertThat(root.getView().getParent()).isNotNull();
211 221
     }
212 222
 
@@ -220,19 +230,11 @@ public class ModalPresenterTest extends BaseTest {
220 230
         verify(root, times(0)).onViewDisappear();
221 231
     }
222 232
 
223
-    @Test
224
-    public void dismissTopModal_rejectIfContentIsNull() {
225
-        uut.setModalsContainer(null);
226
-        CommandListenerAdapter listener = Mockito.mock(CommandListenerAdapter.class);
227
-        uut.dismissTopModal(modal1, modal2, listener);
228
-        verify(listener).onError(any());
229
-    }
230
-
231 233
     @Test
232 234
     public void dismissModal_rejectIfContentIsNull() {
233
-        uut.setModalsContainer(null);
235
+        uut.setModalsLayout(null);
234 236
         CommandListenerAdapter listener = Mockito.mock(CommandListenerAdapter.class);
235
-        uut.dismissModal(modal1, listener);
237
+        uut.dismissModal(modal1, root, root, listener);
236 238
         verify(listener).onError(any());
237 239
     }
238 240
 }

+ 65
- 55
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalStackTest.java Vedi File

@@ -28,6 +28,7 @@ import static org.mockito.Mockito.spy;
28 28
 import static org.mockito.Mockito.times;
29 29
 import static org.mockito.Mockito.verify;
30 30
 import static org.mockito.Mockito.verifyZeroInteractions;
31
+import static org.mockito.Mockito.when;
31 32
 
32 33
 public class ModalStackTest extends BaseTest {
33 34
     private static final String MODAL_ID_1 = "modalId1";
@@ -42,22 +43,26 @@ public class ModalStackTest extends BaseTest {
42 43
     private ChildControllersRegistry childRegistry;
43 44
     private ModalPresenter presenter;
44 45
     private ModalAnimator animator;
45
-    private ViewController rootController;
46
+    private ViewController root;
46 47
 
47 48
     @Override
48 49
     public void beforeEach() {
49 50
         activity = newActivity();
50 51
         childRegistry = new ChildControllersRegistry();
52
+        root = new SimpleViewController(activity, childRegistry, "root", new Options());
51 53
 
52
-        this.rootController = new SimpleViewController(activity, childRegistry, "root", new Options());
53
-        FrameLayout activityContentView = new FrameLayout(activity);
54
-        activityContentView.addView(rootController.getView());
55
-        activity.setContentView(activityContentView);
54
+        FrameLayout rootLayout = new FrameLayout(activity);
55
+        FrameLayout modalsLayout = new FrameLayout(activity);
56
+        FrameLayout contentLayout = new FrameLayout(activity);
57
+        contentLayout.addView(rootLayout);
58
+        contentLayout.addView(modalsLayout);
59
+        activity.setContentView(contentLayout);
56 60
 
57 61
         animator = spy(new ModalAnimatorMock(activity));
58 62
         presenter = spy(new ModalPresenter(animator));
59 63
         uut = new ModalStack(presenter);
60
-        uut.setModalsContainer(activityContentView);
64
+        uut.setModalsLayout(modalsLayout);
65
+        uut.setRootLayout(rootLayout);
61 66
         uut.setEventEmitter(Mockito.mock(EventEmitter.class));
62 67
         modal1 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_1, new Options()));
63 68
         modal2 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_2, new Options()));
@@ -68,7 +73,7 @@ public class ModalStackTest extends BaseTest {
68 73
     public void modalRefIsSaved() {
69 74
         disableShowModalAnimation(modal1);
70 75
         CommandListener listener = spy(new CommandListenerAdapter());
71
-        uut.showModal(modal1, rootController, listener);
76
+        uut.showModal(modal1, root, listener);
72 77
         verify(listener, times(1)).onSuccess(modal1.getId());
73 78
         assertThat(findModal(MODAL_ID_1)).isNotNull();
74 79
     }
@@ -76,21 +81,21 @@ public class ModalStackTest extends BaseTest {
76 81
     @Test
77 82
     public void showModal() {
78 83
         CommandListener listener = spy(new CommandListenerAdapter());
79
-        uut.showModal(modal1, rootController, listener);
84
+        uut.showModal(modal1, root, listener);
80 85
         verify(listener, times(1)).onSuccess(modal1.getId());
81 86
         assertThat(uut.size()).isOne();
82
-        verify(presenter, times(1)).showModal(modal1, rootController, listener);
87
+        verify(presenter, times(1)).showModal(modal1, root, listener);
83 88
         assertThat(findModal(MODAL_ID_1)).isNotNull();
84 89
     }
85 90
 
86 91
     @SuppressWarnings("Convert2Lambda")
87 92
     @Test
88 93
     public void dismissModal() {
89
-        uut.showModal(modal1, rootController, new CommandListenerAdapter());
94
+        uut.showModal(modal1, root, new CommandListenerAdapter());
90 95
         CommandListener listener = spy(new CommandListenerAdapter());
91
-        uut.dismissModal(modal1.getId(), rootController, listener);
96
+        uut.dismissModal(modal1.getId(), root, listener);
92 97
         assertThat(findModal(modal1.getId())).isNull();
93
-        verify(presenter, times(1)).dismissTopModal(eq(modal1), eq(rootController), any());
98
+        verify(presenter, times(1)).dismissModal(eq(modal1), eq(root), eq(root), any());
94 99
         verify(listener).onSuccess(modal1.getId());
95 100
     }
96 101
 
@@ -104,7 +109,7 @@ public class ModalStackTest extends BaseTest {
104 109
 
105 110
             }
106 111
         });
107
-        uut.dismissModal(MODAL_ID_1, rootController, listener);
112
+        uut.dismissModal(MODAL_ID_1, root, listener);
108 113
         verify(onModalWillDismiss, times(0)).run();
109 114
         verify(listener, times(1)).onError(anyString());
110 115
         verifyZeroInteractions(listener);
@@ -115,24 +120,24 @@ public class ModalStackTest extends BaseTest {
115 120
         disableShowModalAnimation(modal1, modal2, modal3);
116 121
         disableDismissModalAnimation(modal1, modal2, modal3);
117 122
 
118
-        uut.showModal(modal1, rootController, new CommandListenerAdapter());
119
-        uut.showModal(modal2, rootController, new CommandListenerAdapter());
120
-        uut.showModal(modal3, rootController, new CommandListenerAdapter());
123
+        uut.showModal(modal1, root, new CommandListenerAdapter());
124
+        uut.showModal(modal2, root, new CommandListenerAdapter());
125
+        uut.showModal(modal3, root, new CommandListenerAdapter());
121 126
 
122
-        assertThat(rootController.getView().getParent()).isNull();
123
-        uut.dismissModal(modal1.getId(), rootController, new CommandListenerAdapter());
124
-        assertThat(rootController.getView().getParent()).isNull();
127
+        assertThat(root.getView().getParent()).isNull();
128
+        uut.dismissModal(modal1.getId(), root, new CommandListenerAdapter());
129
+        assertThat(root.getView().getParent()).isNull();
125 130
 
126
-        uut.dismissModal(modal3.getId(), rootController, new CommandListenerAdapter());
127
-        uut.dismissModal(modal2.getId(), rootController, new CommandListenerAdapter());
128
-        assertThat(rootController.getView().getParent()).isNotNull();
129
-        assertThat(rootController.getView().isShown()).isTrue();
131
+        uut.dismissModal(modal3.getId(), root, new CommandListenerAdapter());
132
+        uut.dismissModal(modal2.getId(), root, new CommandListenerAdapter());
133
+        assertThat(root.getView().getParent()).isNotNull();
134
+        assertThat(root.getView().isShown()).isTrue();
130 135
     }
131 136
 
132 137
     @Test
133 138
     public void dismissAllModals() {
134
-        uut.showModal(modal1, rootController, new CommandListenerAdapter());
135
-        uut.showModal(modal2, rootController, new CommandListenerAdapter());
139
+        uut.showModal(modal1, root, new CommandListenerAdapter());
140
+        uut.showModal(modal2, root, new CommandListenerAdapter());
136 141
         CommandListener listener = spy(new CommandListenerAdapter() {
137 142
             @Override
138 143
             public void onSuccess(String childId) {
@@ -141,7 +146,7 @@ public class ModalStackTest extends BaseTest {
141 146
                 assertThat(uut.isEmpty()).isTrue();
142 147
             }
143 148
         });
144
-        uut.dismissAllModals(rootController, Options.EMPTY, listener);
149
+        uut.dismissAllModals(root, Options.EMPTY, listener);
145 150
         verify(listener, times(1)).onSuccess(anyString());
146 151
         verifyZeroInteractions(listener);
147 152
     }
@@ -149,18 +154,18 @@ public class ModalStackTest extends BaseTest {
149 154
     @Test
150 155
     public void dismissAllModals_rejectIfEmpty() {
151 156
         CommandListener spy = spy(new CommandListenerAdapter());
152
-        uut.dismissAllModals(rootController, Options.EMPTY, spy);
157
+        uut.dismissAllModals(root, Options.EMPTY, spy);
153 158
         verify(spy, times(1)).onError(any());
154 159
     }
155 160
 
156 161
     @Test
157 162
     public void dismissAllModals_optionsAreMergedOnTopModal() {
158
-        uut.showModal(modal1, rootController, new CommandListenerAdapter());
159
-        uut.showModal(modal2, rootController, new CommandListenerAdapter());
160
-        uut.showModal(modal3, rootController, new CommandListenerAdapter());
163
+        uut.showModal(modal1, root, new CommandListenerAdapter());
164
+        uut.showModal(modal2, root, new CommandListenerAdapter());
165
+        uut.showModal(modal3, root, new CommandListenerAdapter());
161 166
 
162 167
         Options mergeOptions = new Options();
163
-        uut.dismissAllModals(rootController, mergeOptions, new CommandListenerAdapter());
168
+        uut.dismissAllModals(root, mergeOptions, new CommandListenerAdapter());
164 169
         verify(modal3).mergeOptions(mergeOptions);
165 170
         verify(modal1, times(0)).mergeOptions(mergeOptions);
166 171
         verify(modal2, times(0)).mergeOptions(mergeOptions);
@@ -169,26 +174,31 @@ public class ModalStackTest extends BaseTest {
169 174
     @SuppressWarnings("Convert2Lambda")
170 175
     @Test
171 176
     public void dismissAllModals_onlyTopModalIsAnimated() {
172
-        uut.showModal(modal1, rootController, new CommandListenerAdapter());
173
-        uut.showModal(modal2, rootController, new CommandListenerAdapter());
177
+        modal2 = spy(modal2);
178
+        Options defaultOptions = new Options();
179
+        uut.setDefaultOptions(defaultOptions);
180
+        Options resolvedOptions = new Options();
181
+        when(modal2.resolveCurrentOptions(defaultOptions)).then(invocation -> resolvedOptions);
182
+        uut.showModal(modal1, root, new CommandListenerAdapter());
183
+        uut.showModal(modal2, root, new CommandListenerAdapter());
174 184
 
175 185
         ViewGroup view1 = modal1.getView();
176 186
         ViewGroup view2 = modal2.getView();
177 187
         CommandListener listener = spy(new CommandListenerAdapter());
178
-        uut.dismissAllModals(rootController, Options.EMPTY, listener);
179
-        verify(presenter, times(1)).dismissTopModal(eq(modal2), eq(rootController), any());
188
+        uut.dismissAllModals(root, Options.EMPTY, listener);
189
+        verify(presenter).dismissModal(eq(modal2), eq(root), eq(root), any());
180 190
         verify(listener).onSuccess(modal2.getId());
181 191
         verify(animator, times(0)).dismiss(eq(view1), eq(modal1.options.animations.dismissModal), any());
182
-        verify(animator, times(1)).dismiss(eq(view2), eq(modal2.options.animations.dismissModal), any());
192
+        verify(animator).dismiss(eq(view2), eq(resolvedOptions.animations.dismissModal), any());
183 193
         assertThat(uut.size()).isEqualTo(0);
184 194
     }
185 195
 
186 196
     @Test
187 197
     public void dismissAllModals_bottomModalsAreDestroyed() {
188
-        uut.showModal(modal1, rootController, new CommandListenerAdapter());
189
-        uut.showModal(modal2, rootController, new CommandListenerAdapter());
198
+        uut.showModal(modal1, root, new CommandListenerAdapter());
199
+        uut.showModal(modal2, root, new CommandListenerAdapter());
190 200
 
191
-        uut.dismissAllModals(rootController, Options.EMPTY, new CommandListenerAdapter());
201
+        uut.dismissAllModals(root, Options.EMPTY, new CommandListenerAdapter());
192 202
 
193 203
         verify(modal1, times(1)).destroy();
194 204
         verify(modal1, times(1)).onViewDisappear();
@@ -198,9 +208,9 @@ public class ModalStackTest extends BaseTest {
198 208
     @Test
199 209
     public void isEmpty() {
200 210
         assertThat(uut.isEmpty()).isTrue();
201
-        uut.showModal(modal1, rootController, new CommandListenerAdapter());
211
+        uut.showModal(modal1, root, new CommandListenerAdapter());
202 212
         assertThat(uut.isEmpty()).isFalse();
203
-        uut.dismissAllModals(rootController, Options.EMPTY, new CommandListenerAdapter());
213
+        uut.dismissAllModals(root, Options.EMPTY, new CommandListenerAdapter());
204 214
         assertThat(uut.isEmpty()).isTrue();
205 215
     }
206 216
 
@@ -208,7 +218,7 @@ public class ModalStackTest extends BaseTest {
208 218
     public void peek() {
209 219
         assertThat(uut.isEmpty()).isTrue();
210 220
         assertThatThrownBy(() -> uut.peek()).isInstanceOf(EmptyStackException.class);
211
-        uut.showModal(modal1, rootController, new CommandListenerAdapter() {
221
+        uut.showModal(modal1, root, new CommandListenerAdapter() {
212 222
             @Override
213 223
             public void onSuccess(String childId) {
214 224
                 assertThat(uut.peek()).isEqualTo(modal1);
@@ -220,9 +230,9 @@ public class ModalStackTest extends BaseTest {
220 230
     public void onDismiss_onViewAppearedInvokedOnPreviousModal() {
221 231
         disableShowModalAnimation(modal1, modal2);
222 232
 
223
-        uut.showModal(modal1, rootController, new CommandListenerAdapter());
224
-        uut.showModal(modal2, rootController, new CommandListenerAdapter());
225
-        uut.dismissModal(modal2.getId(), rootController, new CommandListenerAdapter());
233
+        uut.showModal(modal1, root, new CommandListenerAdapter());
234
+        uut.showModal(modal2, root, new CommandListenerAdapter());
235
+        uut.dismissModal(modal2.getId(), root, new CommandListenerAdapter());
226 236
         verify(modal1, times(2)).onViewAppeared();
227 237
     }
228 238
 
@@ -231,11 +241,11 @@ public class ModalStackTest extends BaseTest {
231 241
         disableShowModalAnimation(modal1, modal2, modal3);
232 242
         disableDismissModalAnimation(modal1, modal2, modal3);
233 243
 
234
-        uut.showModal(modal1, rootController, new CommandListenerAdapter());
235
-        uut.showModal(modal2, rootController, new CommandListenerAdapter());
236
-        uut.showModal(modal3, rootController, new CommandListenerAdapter());
244
+        uut.showModal(modal1, root, new CommandListenerAdapter());
245
+        uut.showModal(modal2, root, new CommandListenerAdapter());
246
+        uut.showModal(modal3, root, new CommandListenerAdapter());
237 247
 
238
-        uut.dismissModal(modal2.getId(), rootController, new CommandListenerAdapter());
248
+        uut.dismissModal(modal2.getId(), root, new CommandListenerAdapter());
239 249
         assertThat(uut.size()).isEqualTo(2);
240 250
         verify(modal2, times(1)).onViewDisappear();
241 251
         verify(modal2, times(1)).destroy();
@@ -245,14 +255,14 @@ public class ModalStackTest extends BaseTest {
245 255
     @Test
246 256
     public void handleBack_doesNothingIfModalStackIsEmpty() {
247 257
         assertThat(uut.isEmpty()).isTrue();
248
-        assertThat(uut.handleBack(new CommandListenerAdapter(), rootController)).isFalse();
258
+        assertThat(uut.handleBack(new CommandListenerAdapter(), root)).isFalse();
249 259
     }
250 260
 
251 261
     @Test
252 262
     public void handleBack_dismissModal() {
253 263
         disableDismissModalAnimation(modal1);
254
-        uut.showModal(modal1, rootController, new CommandListenerAdapter());
255
-        assertThat(uut.handleBack(new CommandListenerAdapter(), rootController)).isTrue();
264
+        uut.showModal(modal1, root, new CommandListenerAdapter());
265
+        assertThat(uut.handleBack(new CommandListenerAdapter(), root)).isTrue();
256 266
         verify(modal1, times(1)).onViewDisappear();
257 267
 
258 268
     }
@@ -265,9 +275,9 @@ public class ModalStackTest extends BaseTest {
265 275
                 return true;
266 276
             }
267 277
         });
268
-        uut.showModal(backHandlingModal, rootController, new CommandListenerAdapter());
278
+        uut.showModal(backHandlingModal, root, new CommandListenerAdapter());
269 279
 
270
-        rootController.getView().getViewTreeObserver().dispatchOnGlobalLayout();
280
+        root.getView().getViewTreeObserver().dispatchOnGlobalLayout();
271 281
 
272 282
         assertThat(uut.handleBack(new CommandListenerAdapter(), any())).isTrue();
273 283
         verify(backHandlingModal, times(1)).handleBack(any());
@@ -301,6 +311,6 @@ public class ModalStackTest extends BaseTest {
301 311
 
302 312
     private void showModalWithoutAnimation(ViewController modal) {
303 313
         disableShowModalAnimation(modal);
304
-        uut.showModal(modal, rootController, new CommandListenerAdapter());
314
+        uut.showModal(modal, root, new CommandListenerAdapter());
305 315
     }
306 316
 }

+ 1
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/navigator/NavigatorTest.java Vedi File

@@ -109,7 +109,7 @@ public class NavigatorTest extends BaseTest {
109 109
     @Test
110 110
     public void bindViews() {
111 111
         verify(rootPresenter).setRootContainer(uut.getRootLayout());
112
-        verify(modalStack).setModalsContainer(uut.getModalsLayout());
112
+        verify(modalStack).setModalsLayout(uut.getModalsLayout());
113 113
     }
114 114
 
115 115
     @Test