|
@@ -7,6 +7,7 @@ import android.animation.AnimatorSet;
|
7
|
7
|
import android.animation.ObjectAnimator;
|
8
|
8
|
import android.animation.TimeInterpolator;
|
9
|
9
|
import android.view.View;
|
|
10
|
+import android.view.animation.AccelerateDecelerateInterpolator;
|
10
|
11
|
import android.view.animation.DecelerateInterpolator;
|
11
|
12
|
import android.view.animation.LinearInterpolator;
|
12
|
13
|
|
|
@@ -15,12 +16,15 @@ import com.reactnativenavigation.views.topbar.TopBar;
|
15
|
16
|
|
16
|
17
|
import javax.annotation.Nullable;
|
17
|
18
|
|
|
19
|
+import static android.view.View.TRANSLATION_Y;
|
|
20
|
+
|
18
|
21
|
public class TopBarAnimator {
|
19
|
22
|
|
20
|
23
|
private static final int DEFAULT_COLLAPSE_DURATION = 100;
|
21
|
|
- private static final int DURATION_TOPBAR = 300;
|
22
|
|
- private final DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator();
|
23
|
|
- private final LinearInterpolator linearInterpolator = new LinearInterpolator();
|
|
24
|
+ private static final int DURATION = 300;
|
|
25
|
+ private static final TimeInterpolator DECELERATE = new DecelerateInterpolator();
|
|
26
|
+ private static final TimeInterpolator LINEAR = new LinearInterpolator();
|
|
27
|
+ private static final TimeInterpolator ACCELERATE_DECELERATE = new AccelerateDecelerateInterpolator();
|
24
|
28
|
|
25
|
29
|
private TopBar topBar;
|
26
|
30
|
private String stackId;
|
|
@@ -40,13 +44,13 @@ public class TopBarAnimator {
|
40
|
44
|
if (options.hasValue() && (!options.id.hasValue() || options.id.get().equals(stackId))) {
|
41
|
45
|
showAnimator = options.getAnimation(topBar);
|
42
|
46
|
} else {
|
43
|
|
- showAnimator = getDefaultShowAnimator(-1 * topBar.getMeasuredHeight(), decelerateInterpolator, DURATION_TOPBAR);
|
|
47
|
+ showAnimator = getDefaultShowAnimator(-1 * topBar.getMeasuredHeight(), DECELERATE, DURATION);
|
44
|
48
|
}
|
45
|
49
|
show();
|
46
|
50
|
}
|
47
|
51
|
|
48
|
52
|
public void show(float startTranslation) {
|
49
|
|
- showAnimator = getDefaultShowAnimator(startTranslation, linearInterpolator, DEFAULT_COLLAPSE_DURATION);
|
|
53
|
+ showAnimator = getDefaultShowAnimator(startTranslation, LINEAR, DEFAULT_COLLAPSE_DURATION);
|
50
|
54
|
show();
|
51
|
55
|
}
|
52
|
56
|
|
|
@@ -62,7 +66,7 @@ public class TopBarAnimator {
|
62
|
66
|
}
|
63
|
67
|
|
64
|
68
|
private AnimatorSet getDefaultShowAnimator(float startTranslation, TimeInterpolator interpolator, int duration) {
|
65
|
|
- ObjectAnimator showAnimator = ObjectAnimator.ofFloat(topBar, View.TRANSLATION_Y, startTranslation, 0);
|
|
69
|
+ ObjectAnimator showAnimator = ObjectAnimator.ofFloat(topBar, TRANSLATION_Y, startTranslation, 0);
|
66
|
70
|
showAnimator.setInterpolator(interpolator);
|
67
|
71
|
showAnimator.setDuration(duration);
|
68
|
72
|
AnimatorSet set = new AnimatorSet();
|
|
@@ -74,13 +78,13 @@ public class TopBarAnimator {
|
74
|
78
|
if (options.hasValue() && (!options.id.hasValue() || options.id.get().equals(stackId))) {
|
75
|
79
|
hideAnimator = options.getAnimation(topBar);
|
76
|
80
|
} else {
|
77
|
|
- hideAnimator = getDefaultHideAnimator(0, linearInterpolator, DURATION_TOPBAR);
|
|
81
|
+ hideAnimator = getDefaultHideAnimator(0, ACCELERATE_DECELERATE, DURATION);
|
78
|
82
|
}
|
79
|
83
|
hide(onAnimationEnd);
|
80
|
84
|
}
|
81
|
85
|
|
82
|
86
|
void hide(float startTranslation) {
|
83
|
|
- hideAnimator = getDefaultHideAnimator(startTranslation, linearInterpolator, DEFAULT_COLLAPSE_DURATION);
|
|
87
|
+ hideAnimator = getDefaultHideAnimator(startTranslation, LINEAR, DEFAULT_COLLAPSE_DURATION);
|
84
|
88
|
hide(() -> {});
|
85
|
89
|
}
|
86
|
90
|
|
|
@@ -96,7 +100,7 @@ public class TopBarAnimator {
|
96
|
100
|
}
|
97
|
101
|
|
98
|
102
|
private Animator getDefaultHideAnimator(float startTranslation, TimeInterpolator interpolator, int duration) {
|
99
|
|
- ObjectAnimator hideAnimator = ObjectAnimator.ofFloat(topBar, View.TRANSLATION_Y, startTranslation, -1 * topBar.getMeasuredHeight());
|
|
103
|
+ ObjectAnimator hideAnimator = ObjectAnimator.ofFloat(topBar, TRANSLATION_Y, startTranslation, -1 * topBar.getMeasuredHeight());
|
100
|
104
|
hideAnimator.setInterpolator(interpolator);
|
101
|
105
|
hideAnimator.setDuration(duration);
|
102
|
106
|
return hideAnimator;
|