Browse Source

Send visibility events for TopTabs screens

Guy Carmeli 7 years ago
parent
commit
76fcaa1ab7

+ 17
- 0
android/app/src/main/java/com/reactnativenavigation/screens/ContentViewPagerAdapter.java View File

@@ -55,11 +55,14 @@ class ContentViewPagerAdapter extends PagerAdapter implements ViewPager.OnPageCh
55 55
     @Override
56 56
     public void onPageSelected(int position) {
57 57
         EventBus.instance.post(new ViewPagerScreenChangedEvent());
58
+        sendDisappearEvents(currentPosition);
58 59
         currentPosition = position;
59 60
         EventBus.instance.post(new ScreenChangedEvent(pageParams.get(currentPosition)));
60 61
         sendTabSelectedEventToJs();
62
+        sendAppearEvents(position);
61 63
     }
62 64
 
65
+
63 66
     @Override
64 67
     public void onPageScrollStateChanged(int state) {
65 68
         if (state == ViewPager.SCROLL_STATE_DRAGGING) {
@@ -67,6 +70,20 @@ class ContentViewPagerAdapter extends PagerAdapter implements ViewPager.OnPageCh
67 70
         }
68 71
     }
69 72
 
73
+    private void sendAppearEvents(int position) {
74
+        PageParams pageParams = this.pageParams.get(position);
75
+        pageParams.timestamp = System.currentTimeMillis();
76
+        NavigationApplication.instance.getEventEmitter().sendWillAppearEvent(pageParams, NavigationType.TopTabSelected);
77
+        NavigationApplication.instance.getEventEmitter().sendDidAppearEvent(pageParams, NavigationType.TopTabSelected);
78
+    }
79
+
80
+    private void sendDisappearEvents(int position) {
81
+        PageParams pageParams = this.pageParams.get(position);
82
+        pageParams.timestamp = System.currentTimeMillis();
83
+        NavigationApplication.instance.getEventEmitter().sendWillDisappearEvent(pageParams, NavigationType.TopTabSelected);
84
+        NavigationApplication.instance.getEventEmitter().sendDidDisappearEvent(pageParams, NavigationType.TopTabSelected);
85
+    }
86
+
70 87
     private void sendTabSelectedEventToJs() {
71 88
         WritableMap data = Arguments.createMap();
72 89
         String navigatorEventId = contentViews.get(currentPosition).getNavigatorEventId();

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/screens/NavigationType.java View File

@@ -4,6 +4,7 @@ public enum NavigationType {
4 4
     Push,
5 5
     Pop,
6 6
     BottomTabSelected,
7
+    TopTabSelected,
7 8
     InitialScreen,
8 9
     ShowModal,
9 10
     DismissModal,

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

@@ -252,28 +252,28 @@ public abstract class Screen extends RelativeLayout implements Subscriber {
252 252
     public abstract void setOnDisplayListener(OnDisplayListener onContentViewDisplayedListener);
253 253
 
254 254
     public void show(NavigationType type) {
255
-        NavigationApplication.instance.getEventEmitter().sendWillAppearEvent(screenParams, type);
256
-        NavigationApplication.instance.getEventEmitter().sendDidAppearEvent(screenParams, type);
255
+        NavigationApplication.instance.getEventEmitter().sendWillAppearEvent(getScreenParams(), type);
256
+        NavigationApplication.instance.getEventEmitter().sendDidAppearEvent(getScreenParams(), type);
257 257
         screenAnimator.show(screenParams.animateScreenTransitions);
258 258
     }
259 259
 
260 260
     public void show(boolean animated, final NavigationType type) {
261
-        NavigationApplication.instance.getEventEmitter().sendWillAppearEvent(screenParams, type);
261
+        NavigationApplication.instance.getEventEmitter().sendWillAppearEvent(getScreenParams(), type);
262 262
         screenAnimator.show(animated, new Runnable() {
263 263
             @Override
264 264
             public void run() {
265
-                NavigationApplication.instance.getEventEmitter().sendDidAppearEvent(screenParams, type);
265
+                NavigationApplication.instance.getEventEmitter().sendDidAppearEvent(getScreenParams(), type);
266 266
             }
267 267
         });
268 268
     }
269 269
 
270 270
     public void show(boolean animated, final Runnable onAnimationEnd, final NavigationType type) {
271
-        NavigationApplication.instance.getEventEmitter().sendWillAppearEvent(screenParams, type);
271
+        NavigationApplication.instance.getEventEmitter().sendWillAppearEvent(getScreenParams(), type);
272 272
         setStyle();
273 273
         screenAnimator.show(animated, new Runnable() {
274 274
             @Override
275 275
             public void run() {
276
-                NavigationApplication.instance.getEventEmitter().sendDidAppearEvent(screenParams, type);
276
+                NavigationApplication.instance.getEventEmitter().sendDidAppearEvent(getScreenParams(), type);
277 277
                 if (onAnimationEnd != null) onAnimationEnd.run();
278 278
             }
279 279
         });
@@ -322,11 +322,11 @@ public abstract class Screen extends RelativeLayout implements Subscriber {
322 322
     }
323 323
 
324 324
     private void hide(boolean animated, final Runnable onAnimatedEnd, final NavigationType type) {
325
-        NavigationApplication.instance.getEventEmitter().sendWillDisappearEvent(screenParams, type);
325
+        NavigationApplication.instance.getEventEmitter().sendWillDisappearEvent(getScreenParams(), type);
326 326
         screenAnimator.hide(animated, new Runnable() {
327 327
             @Override
328 328
             public void run() {
329
-                NavigationApplication.instance.getEventEmitter().sendDidDisappearEvent(screenParams, type);
329
+                NavigationApplication.instance.getEventEmitter().sendDidDisappearEvent(getScreenParams(), type);
330 330
                 if (onAnimatedEnd != null) onAnimatedEnd.run();
331 331
             }
332 332
         });

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

@@ -417,14 +417,14 @@ public class ScreenStack {
417 417
         isStackVisible = true;
418 418
         stack.peek().setStyle();
419 419
         stack.peek().setVisibility(View.VISIBLE);
420
-        stack.peek().screenParams.timestamp = System.currentTimeMillis();
421
-        NavigationApplication.instance.getEventEmitter().sendWillAppearEvent(stack.peek().screenParams, type);
422
-        NavigationApplication.instance.getEventEmitter().sendDidAppearEvent(stack.peek().screenParams, type);
420
+        stack.peek().getScreenParams().timestamp = System.currentTimeMillis();
421
+        NavigationApplication.instance.getEventEmitter().sendWillAppearEvent(stack.peek().getScreenParams(), type);
422
+        NavigationApplication.instance.getEventEmitter().sendDidAppearEvent(stack.peek().getScreenParams(), type);
423 423
     }
424 424
 
425 425
     public void hide(NavigationType type) {
426
-        NavigationApplication.instance.getEventEmitter().sendWillDisappearEvent(stack.peek().screenParams, type);
427
-        NavigationApplication.instance.getEventEmitter().sendDidDisappearEvent(stack.peek().screenParams, type);
426
+        NavigationApplication.instance.getEventEmitter().sendWillDisappearEvent(stack.peek().getScreenParams(), type);
427
+        NavigationApplication.instance.getEventEmitter().sendDidDisappearEvent(stack.peek().getScreenParams(), type);
428 428
         isStackVisible = false;
429 429
         stack.peek().setVisibility(View.INVISIBLE);
430 430
     }