Browse Source

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 years ago
parent
commit
cf591d9a9c

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

105
     }
105
     }
106
 
106
 
107
     private void onDismissEnd(ViewController toDismiss, CommandListener listener) {
107
     private void onDismissEnd(ViewController toDismiss, CommandListener listener) {
108
-        toDismiss.destroy();
109
         listener.onSuccess(toDismiss.getId());
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 View File

1
 package com.reactnativenavigation.viewcontrollers.modal;
1
 package com.reactnativenavigation.viewcontrollers.modal;
2
 
2
 
3
 import android.app.Activity;
3
 import android.app.Activity;
4
-import androidx.coordinatorlayout.widget.CoordinatorLayout;
5
 import android.widget.FrameLayout;
4
 import android.widget.FrameLayout;
6
 
5
 
7
 import com.reactnativenavigation.BaseTest;
6
 import com.reactnativenavigation.BaseTest;
20
 import org.json.JSONException;
19
 import org.json.JSONException;
21
 import org.json.JSONObject;
20
 import org.json.JSONObject;
22
 import org.junit.Test;
21
 import org.junit.Test;
22
+import org.mockito.InOrder;
23
 import org.mockito.Mockito;
23
 import org.mockito.Mockito;
24
 
24
 
25
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
26
+
25
 import static org.assertj.core.api.Java6Assertions.assertThat;
27
 import static org.assertj.core.api.Java6Assertions.assertThat;
26
 import static org.mockito.ArgumentMatchers.any;
28
 import static org.mockito.ArgumentMatchers.any;
27
 import static org.mockito.ArgumentMatchers.eq;
29
 import static org.mockito.ArgumentMatchers.eq;
30
+import static org.mockito.Mockito.inOrder;
28
 import static org.mockito.Mockito.spy;
31
 import static org.mockito.Mockito.spy;
29
 import static org.mockito.Mockito.times;
32
 import static org.mockito.Mockito.times;
30
 import static org.mockito.Mockito.verify;
33
 import static org.mockito.Mockito.verify;
239
         uut.dismissModal(modal1, root, root, listener);
242
         uut.dismissModal(modal1, root, root, listener);
240
         verify(listener).onError(any());
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
 }