Browse Source

Send willDisappear and didDisappear on modal dismiss (#1150)

also report type as ScreenChangedEvent instead of navBarButtonPress.
closes #1144
Guy Carmeli 7 years ago
parent
commit
763b26da6c

+ 6
- 0
android/app/src/main/java/com/reactnativenavigation/bridge/EventEmitter.java View File

@@ -12,6 +12,12 @@ public class EventEmitter {
12 12
         this.reactGateway = reactGateway;
13 13
     }
14 14
 
15
+    public void sendScreenChangedEvent(String eventId, String navigatorEventId) {
16
+        WritableMap map = Arguments.createMap();
17
+        map.putString("type", "ScreenChangedEvent");
18
+        sendNavigatorEvent(eventId, navigatorEventId, map);
19
+    }
20
+
15 21
     public void sendNavigatorEvent(String eventId, String navigatorEventId) {
16 22
         if (!NavigationApplication.instance.isReactContextInitialized()) {
17 23
             return;

+ 8
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/Modal.java View File

@@ -8,6 +8,7 @@ import android.view.Window;
8 8
 import android.view.WindowManager;
9 9
 
10 10
 import com.facebook.react.bridge.Callback;
11
+import com.reactnativenavigation.NavigationApplication;
11 12
 import com.reactnativenavigation.R;
12 13
 import com.reactnativenavigation.layouts.Layout;
13 14
 import com.reactnativenavigation.layouts.ModalScreenLayout;
@@ -169,6 +170,13 @@ public class Modal extends Dialog implements DialogInterface.OnDismissListener,
169 170
         }
170 171
     }
171 172
 
173
+    @Override
174
+    public void dismiss() {
175
+        NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("willDisappear", layout.getCurrentScreen().getNavigatorEventId());
176
+        NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("didDisappear", layout.getCurrentScreen().getNavigatorEventId());
177
+        super.dismiss();
178
+    }
179
+
172 180
     @Override
173 181
     public void onDismiss(DialogInterface dialog) {
174 182
         if (isDestroyed) {

+ 8
- 8
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java View File

@@ -240,20 +240,20 @@ public abstract class Screen extends RelativeLayout implements Subscriber {
240 240
     public abstract void setOnDisplayListener(OnDisplayListener onContentViewDisplayedListener);
241 241
 
242 242
     public void show() {
243
-        NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("willAppear", screenParams.getNavigatorEventId());
244
-        NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("didAppear", screenParams.getNavigatorEventId());
243
+        NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("willAppear", screenParams.getNavigatorEventId());
244
+        NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("didAppear", screenParams.getNavigatorEventId());
245 245
         screenAnimator.show(screenParams.animateScreenTransitions);
246 246
     }
247 247
 
248 248
     public void show(boolean animated) {
249
-        NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("willAppear", screenParams.getNavigatorEventId());
250
-        NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("didAppear", screenParams.getNavigatorEventId());
249
+        NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("willAppear", screenParams.getNavigatorEventId());
250
+        NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("didAppear", screenParams.getNavigatorEventId());
251 251
         screenAnimator.show(animated);
252 252
     }
253 253
 
254 254
     public void show(boolean animated, Runnable onAnimationEnd) {
255
-        NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("willAppear", screenParams.getNavigatorEventId());
256
-        NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("didAppear", screenParams.getNavigatorEventId());
255
+        NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("willAppear", screenParams.getNavigatorEventId());
256
+        NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("didAppear", screenParams.getNavigatorEventId());
257 257
         setStyle();
258 258
         screenAnimator.show(animated, onAnimationEnd);
259 259
     }
@@ -300,8 +300,8 @@ public abstract class Screen extends RelativeLayout implements Subscriber {
300 300
     }
301 301
 
302 302
     private void hide(boolean animated, Runnable onAnimatedEnd) {
303
-        NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("willDisappear", screenParams.getNavigatorEventId());
304
-        NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("didDisappear", screenParams.getNavigatorEventId());
303
+        NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("willDisappear", screenParams.getNavigatorEventId());
304
+        NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("didDisappear", screenParams.getNavigatorEventId());
305 305
         screenAnimator.hide(animated, onAnimatedEnd);
306 306
     }
307 307
 

+ 10
- 10
android/app/src/main/java/com/reactnativenavigation/screens/ScreenStack.java View File

@@ -97,8 +97,8 @@ public class ScreenStack {
97 97
             @Override
98 98
             public void onDisplay() {
99 99
                 if (isStackVisible) {
100
-                    NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("willAppear", stack.peek().getNavigatorEventId());
101
-                    NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("didAppear", stack.peek().getNavigatorEventId());
100
+                    NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("willAppear", stack.peek().getNavigatorEventId());
101
+                    NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("didAppear", stack.peek().getNavigatorEventId());
102 102
                 }
103 103
             }
104 104
         });
@@ -130,7 +130,7 @@ public class ScreenStack {
130 130
                                           @Nullable final Screen.OnDisplayListener onDisplay) {
131 131
         nextScreen.setVisibility(View.INVISIBLE);
132 132
         addScreen(nextScreen, layoutParams);
133
-        NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("willDisappear", previousScreen.getNavigatorEventId());
133
+        NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("willDisappear", previousScreen.getNavigatorEventId());
134 134
         nextScreen.setOnDisplayListener(new Screen.OnDisplayListener() {
135 135
             @Override
136 136
             public void onDisplay() {
@@ -138,7 +138,7 @@ public class ScreenStack {
138 138
                     @Override
139 139
                     public void run() {
140 140
                         if (onDisplay != null) onDisplay.onDisplay();
141
-                        NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("didDisappear", previousScreen.getNavigatorEventId());
141
+                        NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("didDisappear", previousScreen.getNavigatorEventId());
142 142
                         parent.removeView(previousScreen);
143 143
                     }
144 144
                 });
@@ -235,8 +235,8 @@ public class ScreenStack {
235 235
 
236 236
     private void readdPrevious(Screen previous) {
237 237
         previous.setVisibility(View.VISIBLE);
238
-        NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("willAppear", previous.getNavigatorEventId());
239
-        NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("didAppear", previous.getNavigatorEventId());
238
+        NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("willAppear", previous.getNavigatorEventId());
239
+        NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("didAppear", previous.getNavigatorEventId());
240 240
         parent.addView(previous, 0);
241 241
     }
242 242
 
@@ -407,13 +407,13 @@ public class ScreenStack {
407 407
         isStackVisible = true;
408 408
         stack.peek().setStyle();
409 409
         stack.peek().setVisibility(View.VISIBLE);
410
-        NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("willAppear", stack.peek().getNavigatorEventId());
411
-        NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("didAppear", stack.peek().getNavigatorEventId());
410
+        NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("willAppear", stack.peek().getNavigatorEventId());
411
+        NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("didAppear", stack.peek().getNavigatorEventId());
412 412
     }
413 413
 
414 414
     public void hide() {
415
-        NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("willDisappear", stack.peek().getNavigatorEventId());
416
-        NavigationApplication.instance.getEventEmitter().sendNavigatorEvent("didDisappear", stack.peek().getNavigatorEventId());
415
+        NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("willDisappear", stack.peek().getNavigatorEventId());
416
+        NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("didDisappear", stack.peek().getNavigatorEventId());
417 417
         isStackVisible = false;
418 418
         stack.peek().setVisibility(View.INVISIBLE);
419 419
     }