Преглед на файлове

Emit modalDismissed event before ViewController is destroyed (#5838)

This is required so that a component displayed in a modal can react to the dismiss of the modal it's presented in. This change aligns behaviour with iOS.
closes #5830
Guy Carmeli преди 4 години
родител
ревизия
cf591d9a9c

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/modal/ModalPresenter.java Целия файл

@@ -105,7 +105,7 @@ public class ModalPresenter {
105 105
     }
106 106
 
107 107
     private void onDismissEnd(ViewController toDismiss, CommandListener listener) {
108
-        toDismiss.destroy();
109 108
         listener.onSuccess(toDismiss.getId());
109
+        toDismiss.destroy();
110 110
     }
111 111
 }

+ 19
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalPresenterTest.java Целия файл

@@ -1,7 +1,6 @@
1 1
 package com.reactnativenavigation.viewcontrollers.modal;
2 2
 
3 3
 import android.app.Activity;
4
-import androidx.coordinatorlayout.widget.CoordinatorLayout;
5 4
 import android.widget.FrameLayout;
6 5
 
7 6
 import com.reactnativenavigation.BaseTest;
@@ -20,11 +19,15 @@ import com.reactnativenavigation.viewcontrollers.ViewController;
20 19
 import org.json.JSONException;
21 20
 import org.json.JSONObject;
22 21
 import org.junit.Test;
22
+import org.mockito.InOrder;
23 23
 import org.mockito.Mockito;
24 24
 
25
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
26
+
25 27
 import static org.assertj.core.api.Java6Assertions.assertThat;
26 28
 import static org.mockito.ArgumentMatchers.any;
27 29
 import static org.mockito.ArgumentMatchers.eq;
30
+import static org.mockito.Mockito.inOrder;
28 31
 import static org.mockito.Mockito.spy;
29 32
 import static org.mockito.Mockito.times;
30 33
 import static org.mockito.Mockito.verify;
@@ -239,4 +242,19 @@ public class ModalPresenterTest extends BaseTest {
239 242
         uut.dismissModal(modal1, root, root, listener);
240 243
         verify(listener).onError(any());
241 244
     }
245
+
246
+    @Test
247
+    public void dismissModal_successIsReportedBeforeViewIsDestroyed() {
248
+        disableShowModalAnimation(modal1);
249
+        disableDismissModalAnimation(modal1);
250
+        CommandListenerAdapter listener = Mockito.mock(CommandListenerAdapter.class);
251
+        ViewController modal = spy(modal1);
252
+        InOrder inOrder = inOrder(listener, modal);
253
+
254
+        uut.showModal(modal, root, new CommandListenerAdapter());
255
+
256
+        uut.dismissModal(modal, root, root, listener);
257
+        inOrder.verify(listener).onSuccess(modal.getId());
258
+        inOrder.verify(modal).destroy();
259
+    }
242 260
 }