ソースを参照

Animate screen into place after hiding navBar (#2095)

Guy Carmeli 7 年 前
コミット
46fbde8a4c
No account linked to committer's email address

+ 19
- 8
android/app/src/main/java/com/reactnativenavigation/animation/VisibilityAnimator.java ファイルの表示

@@ -1,6 +1,9 @@
1 1
 package com.reactnativenavigation.animation;
2 2
 
3
+import android.animation.Animator;
4
+import android.animation.AnimatorListenerAdapter;
3 5
 import android.animation.ObjectAnimator;
6
+import android.support.annotation.Nullable;
4 7
 import android.support.v4.view.animation.LinearOutSlowInInterpolator;
5 8
 import android.view.View;
6 9
 
@@ -24,12 +27,12 @@ public class VisibilityAnimator {
24 27
         this.hiddenEndValue = hideDirection == HideDirection.Up ? -height : height;
25 28
     }
26 29
 
27
-    public void setVisible(boolean visible, boolean animate) {
30
+    public void setVisible(boolean visible, boolean animate, @Nullable Runnable onAnimationEnd) {
28 31
         cancelAnimator();
29 32
         if (visible) {
30
-            show(animate);
33
+            show(animate, onAnimationEnd);
31 34
         } else {
32
-            hide(animate);
35
+            hide(animate, onAnimationEnd);
33 36
         }
34 37
     }
35 38
 
@@ -40,31 +43,39 @@ public class VisibilityAnimator {
40 43
         }
41 44
     }
42 45
 
43
-    private void show(boolean animate) {
46
+    private void show(boolean animate, @Nullable Runnable onAnimationEnd) {
44 47
         if (animate) {
45
-            animator = createAnimator(true);
48
+            animator = createAnimator(true, onAnimationEnd);
46 49
             animator.start();
47 50
         } else {
48 51
             view.setTranslationY(SHOW_END_VALUE);
49 52
             view.setVisibility(View.VISIBLE);
53
+            if (onAnimationEnd != null) onAnimationEnd.run();
50 54
         }
51 55
     }
52 56
 
53
-    private void hide(boolean animate) {
57
+    private void hide(boolean animate, @Nullable Runnable onAnimationEnd) {
54 58
         if (animate) {
55
-            animator = createAnimator(false);
59
+            animator = createAnimator(false, onAnimationEnd);
56 60
             animator.start();
57 61
         } else {
58 62
             view.setTranslationY(hiddenEndValue);
59 63
             view.setVisibility(View.GONE);
64
+            if (onAnimationEnd != null) onAnimationEnd.run();
60 65
         }
61 66
     }
62 67
 
63
-    private ObjectAnimator createAnimator(final boolean show) {
68
+    private ObjectAnimator createAnimator(final boolean show, @Nullable final Runnable onAnimationEnd) {
64 69
         view.setVisibility(View.VISIBLE);
65 70
         final ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, show ? SHOW_END_VALUE : hiddenEndValue);
66 71
         animator.setDuration(DURATION);
67 72
         animator.setInterpolator(interpolator);
73
+        animator.addListener(new AnimatorListenerAdapter() {
74
+            @Override
75
+            public void onAnimationEnd(Animator animation) {
76
+                if (onAnimationEnd != null) onAnimationEnd.run();
77
+            }
78
+        });
68 79
         return animator;
69 80
     }
70 81
 }

+ 7
- 0
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java ファイルの表示

@@ -1,5 +1,6 @@
1 1
 package com.reactnativenavigation.screens;
2 2
 
3
+import android.animation.LayoutTransition;
3 4
 import android.annotation.TargetApi;
4 5
 import android.content.res.Configuration;
5 6
 import android.graphics.Color;
@@ -239,6 +240,12 @@ public abstract class Screen extends RelativeLayout implements Subscriber {
239 240
 
240 241
     public void setTopBarVisible(boolean visible, boolean animate) {
241 242
         screenParams.styleParams.titleBarHidden = !visible;
243
+        if (animate && styleParams.drawScreenBelowTopBar) {
244
+            setLayoutTransition(new LayoutTransition());
245
+            getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
246
+        } else {
247
+            setLayoutTransition(null);
248
+        }
242 249
         topBar.setVisible(visible, animate);
243 250
     }
244 251
 

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java ファイルの表示

@@ -86,7 +86,7 @@ public class BottomTabs extends AHBottomNavigation {
86 86
 
87 87
     public void setVisibility(boolean hidden, boolean animated) {
88 88
         if (visibilityAnimator != null) {
89
-            visibilityAnimator.setVisible(!hidden, animated);
89
+            visibilityAnimator.setVisible(!hidden, animated, null);
90 90
         } else {
91 91
             setVisibility(hidden);
92 92
         }

+ 11
- 2
android/app/src/main/java/com/reactnativenavigation/views/TopBar.java ファイルの表示

@@ -261,7 +261,16 @@ public class TopBar extends AppBarLayout {
261 261
     }
262 262
 
263 263
     public void setVisible(boolean visible, boolean animate) {
264
-        titleBar.setVisibility(!visible);
265
-        visibilityAnimator.setVisible(visible, animate);
264
+        if (visible) {
265
+            titleBar.setVisibility(false);
266
+            visibilityAnimator.setVisible(true, animate, null);
267
+        } else {
268
+            visibilityAnimator.setVisible(false, animate, new Runnable() {
269
+                @Override
270
+                public void run() {
271
+                    titleBar.setVisibility(true);
272
+                }
273
+            });
274
+        }
266 275
     }
267 276
 }