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
     @Override
55
     @Override
56
     public void onPageSelected(int position) {
56
     public void onPageSelected(int position) {
57
         EventBus.instance.post(new ViewPagerScreenChangedEvent());
57
         EventBus.instance.post(new ViewPagerScreenChangedEvent());
58
+        sendDisappearEvents(currentPosition);
58
         currentPosition = position;
59
         currentPosition = position;
59
         EventBus.instance.post(new ScreenChangedEvent(pageParams.get(currentPosition)));
60
         EventBus.instance.post(new ScreenChangedEvent(pageParams.get(currentPosition)));
60
         sendTabSelectedEventToJs();
61
         sendTabSelectedEventToJs();
62
+        sendAppearEvents(position);
61
     }
63
     }
62
 
64
 
65
+
63
     @Override
66
     @Override
64
     public void onPageScrollStateChanged(int state) {
67
     public void onPageScrollStateChanged(int state) {
65
         if (state == ViewPager.SCROLL_STATE_DRAGGING) {
68
         if (state == ViewPager.SCROLL_STATE_DRAGGING) {
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
     private void sendTabSelectedEventToJs() {
87
     private void sendTabSelectedEventToJs() {
71
         WritableMap data = Arguments.createMap();
88
         WritableMap data = Arguments.createMap();
72
         String navigatorEventId = contentViews.get(currentPosition).getNavigatorEventId();
89
         String navigatorEventId = contentViews.get(currentPosition).getNavigatorEventId();

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

4
     Push,
4
     Push,
5
     Pop,
5
     Pop,
6
     BottomTabSelected,
6
     BottomTabSelected,
7
+    TopTabSelected,
7
     InitialScreen,
8
     InitialScreen,
8
     ShowModal,
9
     ShowModal,
9
     DismissModal,
10
     DismissModal,

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

252
     public abstract void setOnDisplayListener(OnDisplayListener onContentViewDisplayedListener);
252
     public abstract void setOnDisplayListener(OnDisplayListener onContentViewDisplayedListener);
253
 
253
 
254
     public void show(NavigationType type) {
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
         screenAnimator.show(screenParams.animateScreenTransitions);
257
         screenAnimator.show(screenParams.animateScreenTransitions);
258
     }
258
     }
259
 
259
 
260
     public void show(boolean animated, final NavigationType type) {
260
     public void show(boolean animated, final NavigationType type) {
261
-        NavigationApplication.instance.getEventEmitter().sendWillAppearEvent(screenParams, type);
261
+        NavigationApplication.instance.getEventEmitter().sendWillAppearEvent(getScreenParams(), type);
262
         screenAnimator.show(animated, new Runnable() {
262
         screenAnimator.show(animated, new Runnable() {
263
             @Override
263
             @Override
264
             public void run() {
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
     public void show(boolean animated, final Runnable onAnimationEnd, final NavigationType type) {
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
         setStyle();
272
         setStyle();
273
         screenAnimator.show(animated, new Runnable() {
273
         screenAnimator.show(animated, new Runnable() {
274
             @Override
274
             @Override
275
             public void run() {
275
             public void run() {
276
-                NavigationApplication.instance.getEventEmitter().sendDidAppearEvent(screenParams, type);
276
+                NavigationApplication.instance.getEventEmitter().sendDidAppearEvent(getScreenParams(), type);
277
                 if (onAnimationEnd != null) onAnimationEnd.run();
277
                 if (onAnimationEnd != null) onAnimationEnd.run();
278
             }
278
             }
279
         });
279
         });
322
     }
322
     }
323
 
323
 
324
     private void hide(boolean animated, final Runnable onAnimatedEnd, final NavigationType type) {
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
         screenAnimator.hide(animated, new Runnable() {
326
         screenAnimator.hide(animated, new Runnable() {
327
             @Override
327
             @Override
328
             public void run() {
328
             public void run() {
329
-                NavigationApplication.instance.getEventEmitter().sendDidDisappearEvent(screenParams, type);
329
+                NavigationApplication.instance.getEventEmitter().sendDidDisappearEvent(getScreenParams(), type);
330
                 if (onAnimatedEnd != null) onAnimatedEnd.run();
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
         isStackVisible = true;
417
         isStackVisible = true;
418
         stack.peek().setStyle();
418
         stack.peek().setStyle();
419
         stack.peek().setVisibility(View.VISIBLE);
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
     public void hide(NavigationType type) {
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
         isStackVisible = false;
428
         isStackVisible = false;
429
         stack.peek().setVisibility(View.INVISIBLE);
429
         stack.peek().setVisibility(View.INVISIBLE);
430
     }
430
     }