Browse Source

Revert "Fix title bar not displayed if it was initially hidden (#1341)" (#1342)

This reverts commit 7919e65932.
Guy Carmeli 7 years ago
parent
commit
8fd1a231ad

+ 36
- 21
android/app/src/main/java/com/reactnativenavigation/animation/VisibilityAnimator.java View File

1
 package com.reactnativenavigation.animation;
1
 package com.reactnativenavigation.animation;
2
 
2
 
3
+import android.animation.Animator;
4
+import android.animation.AnimatorListenerAdapter;
3
 import android.animation.ObjectAnimator;
5
 import android.animation.ObjectAnimator;
4
 import android.support.v4.view.animation.LinearOutSlowInInterpolator;
6
 import android.support.v4.view.animation.LinearOutSlowInInterpolator;
5
 import android.view.View;
7
 import android.view.View;
6
 
8
 
7
 public class VisibilityAnimator {
9
 public class VisibilityAnimator {
8
 
10
 
9
-    private final LinearOutSlowInInterpolator interpolator = new LinearOutSlowInInterpolator();
10
-    private ObjectAnimator animator;
11
-
12
     public enum HideDirection {
11
     public enum HideDirection {
13
         Up, Down
12
         Up, Down
14
     }
13
     }
15
 
14
 
15
+    private enum VisibilityState {
16
+        Hidden, AnimateHide, Shown, AnimateShow
17
+    }
18
+
16
     private static final int SHOW_END_VALUE = 0;
19
     private static final int SHOW_END_VALUE = 0;
17
     private static final int DURATION = 300;
20
     private static final int DURATION = 300;
18
 
21
 
19
     private final View view;
22
     private final View view;
20
     private final int hiddenEndValue;
23
     private final int hiddenEndValue;
24
+    private VisibilityState visibilityState = VisibilityState.Shown;
21
 
25
 
22
     public VisibilityAnimator(View view, HideDirection hideDirection, int height) {
26
     public VisibilityAnimator(View view, HideDirection hideDirection, int height) {
23
         this.view = view;
27
         this.view = view;
25
     }
29
     }
26
 
30
 
27
     public void setVisible(boolean visible, boolean animate) {
31
     public void setVisible(boolean visible, boolean animate) {
28
-        cancelAnimator();
29
-        if (visible) {
32
+        if (visible && isHiding()) {
30
             show(animate);
33
             show(animate);
31
-        } else {
34
+        } else if (!visible && isShowing()) {
32
             hide(animate);
35
             hide(animate);
33
         }
36
         }
34
     }
37
     }
35
 
38
 
36
-    private void cancelAnimator() {
37
-        if (animator != null && animator.isRunning()) {
38
-            view.clearAnimation();
39
-            animator.cancel();
40
-        }
41
-    }
42
-
43
     private void show(boolean animate) {
39
     private void show(boolean animate) {
44
         if (animate) {
40
         if (animate) {
45
-            animator = createAnimator(true);
41
+            ObjectAnimator animator = createAnimator(true);
46
             animator.start();
42
             animator.start();
47
         } else {
43
         } else {
48
-            view.setTranslationY(SHOW_END_VALUE);
49
-            view.setY(SHOW_END_VALUE);
44
+            visibilityState = VisibilityState.Shown;
45
+            view.setVisibility(View.VISIBLE);
50
         }
46
         }
51
     }
47
     }
52
 
48
 
53
     private void hide(boolean animate) {
49
     private void hide(boolean animate) {
54
         if (animate) {
50
         if (animate) {
55
-            animator = createAnimator(false);
51
+            ObjectAnimator animator = createAnimator(false);
56
             animator.start();
52
             animator.start();
57
         } else {
53
         } else {
58
-            view.setTranslationY(hiddenEndValue);
59
-            view.setY(hiddenEndValue);
54
+            visibilityState = VisibilityState.Hidden;
55
+            view.setVisibility(View.GONE);
60
         }
56
         }
61
     }
57
     }
62
 
58
 
59
+    private boolean isShowing() {
60
+        return visibilityState == VisibilityState.Shown || visibilityState == VisibilityState.AnimateShow;
61
+    }
62
+
63
+    private boolean isHiding() {
64
+        return visibilityState == VisibilityState.Hidden || visibilityState == VisibilityState.AnimateHide;
65
+    }
66
+
63
     private ObjectAnimator createAnimator(final boolean show) {
67
     private ObjectAnimator createAnimator(final boolean show) {
64
-        final ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, show ? SHOW_END_VALUE : hiddenEndValue);
68
+        ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, show ? SHOW_END_VALUE : hiddenEndValue);
65
         animator.setDuration(DURATION);
69
         animator.setDuration(DURATION);
66
-        animator.setInterpolator(interpolator);
70
+        animator.setInterpolator(new LinearOutSlowInInterpolator());
71
+        animator.addListener(new AnimatorListenerAdapter() {
72
+            @Override
73
+            public void onAnimationStart(Animator animation) {
74
+                visibilityState = show ? VisibilityState.AnimateShow : VisibilityState.AnimateHide;
75
+            }
76
+
77
+            @Override
78
+            public void onAnimationEnd(Animator animation) {
79
+                visibilityState = show ? VisibilityState.Shown : VisibilityState.Hidden;
80
+            }
81
+        });
67
         return animator;
82
         return animator;
68
     }
83
     }
69
 }
84
 }

+ 6
- 0
android/app/src/main/java/com/reactnativenavigation/views/TitleBar.java View File

32
         super(context);
32
         super(context);
33
     }
33
     }
34
 
34
 
35
+    @Override
36
+    protected void onLayout(boolean changed, int l, int t, int r, int b) {
37
+        super.onLayout(changed, l, t, r, b);
38
+    }
39
+
35
     @Override
40
     @Override
36
     public void onViewAdded(View child) {
41
     public void onViewAdded(View child) {
37
         super.onViewAdded(child);
42
         super.onViewAdded(child);
71
     }
76
     }
72
 
77
 
73
     public void setStyle(StyleParams params) {
78
     public void setStyle(StyleParams params) {
79
+        setVisibility(params.titleBarHidden ? GONE : VISIBLE);
74
         setTitleTextColor(params);
80
         setTitleTextColor(params);
75
         setTitleTextFont(params);
81
         setTitleTextFont(params);
76
         setSubtitleTextColor(params);
82
         setSubtitleTextColor(params);