Browse Source

Attach root to rootLayout after modal dismiss

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

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

2
 
2
 
3
 import android.animation.Animator;
3
 import android.animation.Animator;
4
 import android.animation.AnimatorListenerAdapter;
4
 import android.animation.AnimatorListenerAdapter;
5
-import android.support.annotation.NonNull;
6
 import android.support.annotation.Nullable;
5
 import android.support.annotation.Nullable;
7
 import android.view.ViewGroup;
6
 import android.view.ViewGroup;
8
 
7
 
14
 
13
 
15
 public class ModalPresenter {
14
 public class ModalPresenter {
16
 
15
 
17
-    private ViewGroup modalsContainer;
16
+    private ViewGroup rootLayout;
17
+    private ViewGroup modalsLayout;
18
     private ModalAnimator animator;
18
     private ModalAnimator animator;
19
     private Options defaultOptions = new Options();
19
     private Options defaultOptions = new Options();
20
 
20
 
22
         this.animator = animator;
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
     public void setDefaultOptions(Options defaultOptions) {
33
     public void setDefaultOptions(Options defaultOptions) {
30
         this.defaultOptions = defaultOptions;
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
             listener.onError("Can not show modal before activity is created");
39
             listener.onError("Can not show modal before activity is created");
36
             return;
40
             return;
37
         }
41
         }
38
         Options options = toAdd.resolveCurrentOptions(defaultOptions);
42
         Options options = toAdd.resolveCurrentOptions(defaultOptions);
39
         toAdd.setWaitForRender(options.animations.showModal.waitForRender);
43
         toAdd.setWaitForRender(options.animations.showModal.waitForRender);
40
-        modalsContainer.addView(toAdd.getView());
44
+        modalsLayout.addView(toAdd.getView());
41
         if (options.animations.showModal.enabled.isTrueOrUndefined()) {
45
         if (options.animations.showModal.enabled.isTrueOrUndefined()) {
42
             if (options.animations.showModal.waitForRender.isTrue()) {
46
             if (options.animations.showModal.waitForRender.isTrue()) {
43
                 toAdd.setOnAppearedListener(() -> animateShow(toAdd, toRemove, listener, options));
47
                 toAdd.setOnAppearedListener(() -> animateShow(toAdd, toRemove, listener, options));
69
         listener.onSuccess(toAdd.getId());
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
             listener.onError("Can not dismiss modal before activity is created");
78
             listener.onError("Can not dismiss modal before activity is created");
84
             return;
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
                 @Override
85
                 @Override
89
                 public void onAnimationEnd(Animator animation) {
86
                 public void onAnimationEnd(Animator animation) {
90
                     onDismissEnd(toDismiss, listener);
87
                     onDismissEnd(toDismiss, listener);

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

35
         this.presenter = presenter;
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
     public void setDefaultOptions(Options defaultOptions) {
46
     public void setDefaultOptions(Options defaultOptions) {
52
     public boolean dismissModal(String componentId, @Nullable ViewController root, CommandListener listener) {
56
     public boolean dismissModal(String componentId, @Nullable ViewController root, CommandListener listener) {
53
         ViewController toDismiss = findModalByComponentId(componentId);
57
         ViewController toDismiss = findModalByComponentId(componentId);
54
         if (toDismiss != null) {
58
         if (toDismiss != null) {
55
-            boolean isTop = isTop(toDismiss);
59
+            boolean isDismissingTopModal = isTop(toDismiss);
56
             modals.remove(toDismiss);
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
             CommandListenerAdapter onDismiss = new CommandListenerAdapter(listener) {
62
             CommandListenerAdapter onDismiss = new CommandListenerAdapter(listener) {
59
                 @Override
63
                 @Override
60
                 public void onSuccess(String childId) {
64
                 public void onSuccess(String childId) {
62
                     super.onSuccess(childId);
66
                     super.onSuccess(childId);
63
                 }
67
                 }
64
             };
68
             };
65
-            if (isTop) {
69
+            if (isDismissingTopModal) {
66
                 if (toAdd == null) {
70
                 if (toAdd == null) {
67
                     listener.onError("Could not dismiss modal");
71
                     listener.onError("Could not dismiss modal");
68
                     return false;
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
             return true;
76
             return true;
75
         } else {
77
         } else {
76
             listener.onError("Nothing to dismiss");
78
             listener.onError("Nothing to dismiss");
113
         return dismissModal(peek().getId(), root, listener);
115
         return dismissModal(peek().getId(), root, listener);
114
     }
116
     }
115
 
117
 
116
-    public ViewController peek() {
118
+    ViewController peek() {
117
         if (modals.isEmpty()) throw new EmptyStackException();
119
         if (modals.isEmpty()) throw new EmptyStackException();
118
         return modals.get(modals.size() - 1);
120
         return modals.get(modals.size() - 1);
119
     }
121
     }

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

72
     }
72
     }
73
 
73
 
74
     public void bindViews() {
74
     public void bindViews() {
75
-        modalStack.setModalsContainer(modalsLayout);
75
+        modalStack.setModalsLayout(modalsLayout);
76
+        modalStack.setRootLayout(rootLayout);
76
         rootPresenter.setRootContainer(rootLayout);
77
         rootPresenter.setRootContainer(rootLayout);
77
     }
78
     }
78
 
79
 

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

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

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

28
 import static org.mockito.Mockito.times;
28
 import static org.mockito.Mockito.times;
29
 import static org.mockito.Mockito.verify;
29
 import static org.mockito.Mockito.verify;
30
 import static org.mockito.Mockito.verifyZeroInteractions;
30
 import static org.mockito.Mockito.verifyZeroInteractions;
31
+import static org.mockito.Mockito.when;
31
 
32
 
32
 public class ModalStackTest extends BaseTest {
33
 public class ModalStackTest extends BaseTest {
33
     private static final String MODAL_ID_1 = "modalId1";
34
     private static final String MODAL_ID_1 = "modalId1";
42
     private ChildControllersRegistry childRegistry;
43
     private ChildControllersRegistry childRegistry;
43
     private ModalPresenter presenter;
44
     private ModalPresenter presenter;
44
     private ModalAnimator animator;
45
     private ModalAnimator animator;
45
-    private ViewController rootController;
46
+    private ViewController root;
46
 
47
 
47
     @Override
48
     @Override
48
     public void beforeEach() {
49
     public void beforeEach() {
49
         activity = newActivity();
50
         activity = newActivity();
50
         childRegistry = new ChildControllersRegistry();
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
         animator = spy(new ModalAnimatorMock(activity));
61
         animator = spy(new ModalAnimatorMock(activity));
58
         presenter = spy(new ModalPresenter(animator));
62
         presenter = spy(new ModalPresenter(animator));
59
         uut = new ModalStack(presenter);
63
         uut = new ModalStack(presenter);
60
-        uut.setModalsContainer(activityContentView);
64
+        uut.setModalsLayout(modalsLayout);
65
+        uut.setRootLayout(rootLayout);
61
         uut.setEventEmitter(Mockito.mock(EventEmitter.class));
66
         uut.setEventEmitter(Mockito.mock(EventEmitter.class));
62
         modal1 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_1, new Options()));
67
         modal1 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_1, new Options()));
63
         modal2 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_2, new Options()));
68
         modal2 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_2, new Options()));
68
     public void modalRefIsSaved() {
73
     public void modalRefIsSaved() {
69
         disableShowModalAnimation(modal1);
74
         disableShowModalAnimation(modal1);
70
         CommandListener listener = spy(new CommandListenerAdapter());
75
         CommandListener listener = spy(new CommandListenerAdapter());
71
-        uut.showModal(modal1, rootController, listener);
76
+        uut.showModal(modal1, root, listener);
72
         verify(listener, times(1)).onSuccess(modal1.getId());
77
         verify(listener, times(1)).onSuccess(modal1.getId());
73
         assertThat(findModal(MODAL_ID_1)).isNotNull();
78
         assertThat(findModal(MODAL_ID_1)).isNotNull();
74
     }
79
     }
76
     @Test
81
     @Test
77
     public void showModal() {
82
     public void showModal() {
78
         CommandListener listener = spy(new CommandListenerAdapter());
83
         CommandListener listener = spy(new CommandListenerAdapter());
79
-        uut.showModal(modal1, rootController, listener);
84
+        uut.showModal(modal1, root, listener);
80
         verify(listener, times(1)).onSuccess(modal1.getId());
85
         verify(listener, times(1)).onSuccess(modal1.getId());
81
         assertThat(uut.size()).isOne();
86
         assertThat(uut.size()).isOne();
82
-        verify(presenter, times(1)).showModal(modal1, rootController, listener);
87
+        verify(presenter, times(1)).showModal(modal1, root, listener);
83
         assertThat(findModal(MODAL_ID_1)).isNotNull();
88
         assertThat(findModal(MODAL_ID_1)).isNotNull();
84
     }
89
     }
85
 
90
 
86
     @SuppressWarnings("Convert2Lambda")
91
     @SuppressWarnings("Convert2Lambda")
87
     @Test
92
     @Test
88
     public void dismissModal() {
93
     public void dismissModal() {
89
-        uut.showModal(modal1, rootController, new CommandListenerAdapter());
94
+        uut.showModal(modal1, root, new CommandListenerAdapter());
90
         CommandListener listener = spy(new CommandListenerAdapter());
95
         CommandListener listener = spy(new CommandListenerAdapter());
91
-        uut.dismissModal(modal1.getId(), rootController, listener);
96
+        uut.dismissModal(modal1.getId(), root, listener);
92
         assertThat(findModal(modal1.getId())).isNull();
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
         verify(listener).onSuccess(modal1.getId());
99
         verify(listener).onSuccess(modal1.getId());
95
     }
100
     }
96
 
101
 
104
 
109
 
105
             }
110
             }
106
         });
111
         });
107
-        uut.dismissModal(MODAL_ID_1, rootController, listener);
112
+        uut.dismissModal(MODAL_ID_1, root, listener);
108
         verify(onModalWillDismiss, times(0)).run();
113
         verify(onModalWillDismiss, times(0)).run();
109
         verify(listener, times(1)).onError(anyString());
114
         verify(listener, times(1)).onError(anyString());
110
         verifyZeroInteractions(listener);
115
         verifyZeroInteractions(listener);
115
         disableShowModalAnimation(modal1, modal2, modal3);
120
         disableShowModalAnimation(modal1, modal2, modal3);
116
         disableDismissModalAnimation(modal1, modal2, modal3);
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
     @Test
137
     @Test
133
     public void dismissAllModals() {
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
         CommandListener listener = spy(new CommandListenerAdapter() {
141
         CommandListener listener = spy(new CommandListenerAdapter() {
137
             @Override
142
             @Override
138
             public void onSuccess(String childId) {
143
             public void onSuccess(String childId) {
141
                 assertThat(uut.isEmpty()).isTrue();
146
                 assertThat(uut.isEmpty()).isTrue();
142
             }
147
             }
143
         });
148
         });
144
-        uut.dismissAllModals(rootController, Options.EMPTY, listener);
149
+        uut.dismissAllModals(root, Options.EMPTY, listener);
145
         verify(listener, times(1)).onSuccess(anyString());
150
         verify(listener, times(1)).onSuccess(anyString());
146
         verifyZeroInteractions(listener);
151
         verifyZeroInteractions(listener);
147
     }
152
     }
149
     @Test
154
     @Test
150
     public void dismissAllModals_rejectIfEmpty() {
155
     public void dismissAllModals_rejectIfEmpty() {
151
         CommandListener spy = spy(new CommandListenerAdapter());
156
         CommandListener spy = spy(new CommandListenerAdapter());
152
-        uut.dismissAllModals(rootController, Options.EMPTY, spy);
157
+        uut.dismissAllModals(root, Options.EMPTY, spy);
153
         verify(spy, times(1)).onError(any());
158
         verify(spy, times(1)).onError(any());
154
     }
159
     }
155
 
160
 
156
     @Test
161
     @Test
157
     public void dismissAllModals_optionsAreMergedOnTopModal() {
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
         Options mergeOptions = new Options();
167
         Options mergeOptions = new Options();
163
-        uut.dismissAllModals(rootController, mergeOptions, new CommandListenerAdapter());
168
+        uut.dismissAllModals(root, mergeOptions, new CommandListenerAdapter());
164
         verify(modal3).mergeOptions(mergeOptions);
169
         verify(modal3).mergeOptions(mergeOptions);
165
         verify(modal1, times(0)).mergeOptions(mergeOptions);
170
         verify(modal1, times(0)).mergeOptions(mergeOptions);
166
         verify(modal2, times(0)).mergeOptions(mergeOptions);
171
         verify(modal2, times(0)).mergeOptions(mergeOptions);
169
     @SuppressWarnings("Convert2Lambda")
174
     @SuppressWarnings("Convert2Lambda")
170
     @Test
175
     @Test
171
     public void dismissAllModals_onlyTopModalIsAnimated() {
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
         ViewGroup view1 = modal1.getView();
185
         ViewGroup view1 = modal1.getView();
176
         ViewGroup view2 = modal2.getView();
186
         ViewGroup view2 = modal2.getView();
177
         CommandListener listener = spy(new CommandListenerAdapter());
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
         verify(listener).onSuccess(modal2.getId());
190
         verify(listener).onSuccess(modal2.getId());
181
         verify(animator, times(0)).dismiss(eq(view1), eq(modal1.options.animations.dismissModal), any());
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
         assertThat(uut.size()).isEqualTo(0);
193
         assertThat(uut.size()).isEqualTo(0);
184
     }
194
     }
185
 
195
 
186
     @Test
196
     @Test
187
     public void dismissAllModals_bottomModalsAreDestroyed() {
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
         verify(modal1, times(1)).destroy();
203
         verify(modal1, times(1)).destroy();
194
         verify(modal1, times(1)).onViewDisappear();
204
         verify(modal1, times(1)).onViewDisappear();
198
     @Test
208
     @Test
199
     public void isEmpty() {
209
     public void isEmpty() {
200
         assertThat(uut.isEmpty()).isTrue();
210
         assertThat(uut.isEmpty()).isTrue();
201
-        uut.showModal(modal1, rootController, new CommandListenerAdapter());
211
+        uut.showModal(modal1, root, new CommandListenerAdapter());
202
         assertThat(uut.isEmpty()).isFalse();
212
         assertThat(uut.isEmpty()).isFalse();
203
-        uut.dismissAllModals(rootController, Options.EMPTY, new CommandListenerAdapter());
213
+        uut.dismissAllModals(root, Options.EMPTY, new CommandListenerAdapter());
204
         assertThat(uut.isEmpty()).isTrue();
214
         assertThat(uut.isEmpty()).isTrue();
205
     }
215
     }
206
 
216
 
208
     public void peek() {
218
     public void peek() {
209
         assertThat(uut.isEmpty()).isTrue();
219
         assertThat(uut.isEmpty()).isTrue();
210
         assertThatThrownBy(() -> uut.peek()).isInstanceOf(EmptyStackException.class);
220
         assertThatThrownBy(() -> uut.peek()).isInstanceOf(EmptyStackException.class);
211
-        uut.showModal(modal1, rootController, new CommandListenerAdapter() {
221
+        uut.showModal(modal1, root, new CommandListenerAdapter() {
212
             @Override
222
             @Override
213
             public void onSuccess(String childId) {
223
             public void onSuccess(String childId) {
214
                 assertThat(uut.peek()).isEqualTo(modal1);
224
                 assertThat(uut.peek()).isEqualTo(modal1);
220
     public void onDismiss_onViewAppearedInvokedOnPreviousModal() {
230
     public void onDismiss_onViewAppearedInvokedOnPreviousModal() {
221
         disableShowModalAnimation(modal1, modal2);
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
         verify(modal1, times(2)).onViewAppeared();
236
         verify(modal1, times(2)).onViewAppeared();
227
     }
237
     }
228
 
238
 
231
         disableShowModalAnimation(modal1, modal2, modal3);
241
         disableShowModalAnimation(modal1, modal2, modal3);
232
         disableDismissModalAnimation(modal1, modal2, modal3);
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
         assertThat(uut.size()).isEqualTo(2);
249
         assertThat(uut.size()).isEqualTo(2);
240
         verify(modal2, times(1)).onViewDisappear();
250
         verify(modal2, times(1)).onViewDisappear();
241
         verify(modal2, times(1)).destroy();
251
         verify(modal2, times(1)).destroy();
245
     @Test
255
     @Test
246
     public void handleBack_doesNothingIfModalStackIsEmpty() {
256
     public void handleBack_doesNothingIfModalStackIsEmpty() {
247
         assertThat(uut.isEmpty()).isTrue();
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
     @Test
261
     @Test
252
     public void handleBack_dismissModal() {
262
     public void handleBack_dismissModal() {
253
         disableDismissModalAnimation(modal1);
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
         verify(modal1, times(1)).onViewDisappear();
266
         verify(modal1, times(1)).onViewDisappear();
257
 
267
 
258
     }
268
     }
265
                 return true;
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
         assertThat(uut.handleBack(new CommandListenerAdapter(), any())).isTrue();
282
         assertThat(uut.handleBack(new CommandListenerAdapter(), any())).isTrue();
273
         verify(backHandlingModal, times(1)).handleBack(any());
283
         verify(backHandlingModal, times(1)).handleBack(any());
301
 
311
 
302
     private void showModalWithoutAnimation(ViewController modal) {
312
     private void showModalWithoutAnimation(ViewController modal) {
303
         disableShowModalAnimation(modal);
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 View File

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