|
@@ -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
|
}
|