|
@@ -9,63 +9,52 @@ import android.view.animation.AccelerateInterpolator;
|
9
|
9
|
import android.view.animation.DecelerateInterpolator;
|
10
|
10
|
import android.view.animation.LinearInterpolator;
|
11
|
11
|
|
|
12
|
+import com.reactnativenavigation.NavigationApplication;
|
12
|
13
|
import com.reactnativenavigation.utils.ViewUtils;
|
13
|
|
-import com.reactnativenavigation.views.BottomTabs;
|
14
|
14
|
|
15
|
|
-public class ScreenAnimator {
|
16
|
|
- private static final String TAG = "ScreenAnimator";
|
17
|
|
- private BottomTabs bottomTabs;
|
18
|
|
-
|
19
|
|
- public ScreenAnimator() {
|
|
15
|
+import javax.annotation.Nullable;
|
20
|
16
|
|
21
|
|
- }
|
|
17
|
+public class ScreenAnimator {
|
|
18
|
+ private final float translationY;
|
|
19
|
+ private Screen screen;
|
22
|
20
|
|
23
|
|
- public ScreenAnimator(BottomTabs bottomTabs) {
|
24
|
|
- this.bottomTabs = bottomTabs;
|
|
21
|
+ public ScreenAnimator(Screen screen) {
|
|
22
|
+ this.screen = screen;
|
|
23
|
+ translationY = 0.08f * ViewUtils.getScreenHeight();
|
25
|
24
|
}
|
26
|
25
|
|
27
|
|
- public void show(Screen screenToShow, Runnable onScreenRemoved) {
|
28
|
|
- createPushAnimator(screenToShow, onScreenRemoved).start();
|
|
26
|
+ public void show(boolean animate, final Runnable onAnimationEnd) {
|
|
27
|
+ if (animate) {
|
|
28
|
+ createShowAnimator(onAnimationEnd).start();
|
|
29
|
+ } else {
|
|
30
|
+ screen.setVisibility(View.VISIBLE);
|
|
31
|
+ NavigationApplication.instance.runOnMainThread(onAnimationEnd, 200);
|
|
32
|
+ }
|
29
|
33
|
}
|
30
|
34
|
|
31
|
|
- public void show(Screen screenToShow) {
|
32
|
|
- createPushAnimator(screenToShow).start();
|
|
35
|
+ public void show(boolean animate) {
|
|
36
|
+ if (animate) {
|
|
37
|
+ createShowAnimator(null).start();
|
|
38
|
+ } else {
|
|
39
|
+ screen.setVisibility(View.VISIBLE);
|
|
40
|
+ }
|
33
|
41
|
}
|
34
|
42
|
|
35
|
|
- public void hide(Screen screenToHide, Runnable onScreenRemoved) {
|
36
|
|
- createPopAnimator(screenToHide, onScreenRemoved).start();
|
|
43
|
+ public void hide(boolean animate, Runnable onAnimationEnd) {
|
|
44
|
+ if (animate) {
|
|
45
|
+ createHideAnimator(onAnimationEnd).start();
|
|
46
|
+ } else {
|
|
47
|
+ screen.setVisibility(View.INVISIBLE);
|
|
48
|
+ onAnimationEnd.run();
|
|
49
|
+ }
|
37
|
50
|
}
|
38
|
51
|
|
39
|
|
- private Animator createPushAnimator(final Screen screen) {
|
40
|
|
- ObjectAnimator alpha = ObjectAnimator.ofFloat(screen, View.ALPHA, 0.7f, 1);
|
41
|
|
- alpha.setStartDelay(100);
|
42
|
|
- alpha.setInterpolator(new LinearInterpolator());
|
43
|
|
- alpha.setDuration(150);
|
44
|
|
-
|
45
|
|
- final float delta = 0.08f * ViewUtils.getScreenHeight();
|
46
|
|
- ObjectAnimator translationY = ObjectAnimator.ofFloat(screen, View.TRANSLATION_Y, delta, 0);
|
47
|
|
- translationY.setInterpolator(new AccelerateInterpolator());
|
48
|
|
- translationY.setDuration(250);
|
49
|
|
-
|
50
|
|
- AnimatorSet set = new AnimatorSet();
|
51
|
|
- set.playTogether(translationY, alpha);
|
52
|
|
- set.addListener(new AnimatorListenerAdapter() {
|
53
|
|
- @Override
|
54
|
|
- public void onAnimationStart(Animator animation) {
|
55
|
|
- screen.setVisibility(View.VISIBLE);
|
56
|
|
- }
|
57
|
|
- });
|
58
|
|
- return set;
|
59
|
|
- }
|
60
|
|
-
|
61
|
|
- private Animator createPushAnimator(final Screen screenToShow, final Runnable onScreenRemoved) {
|
62
|
|
- final float translationYValue = 0.08f * ViewUtils.getScreenHeight();
|
63
|
|
-
|
64
|
|
- ObjectAnimator alpha = ObjectAnimator.ofFloat(screenToShow, View.ALPHA, 0, 1);
|
|
52
|
+ private Animator createShowAnimator(final @Nullable Runnable onAnimationEnd) {
|
|
53
|
+ ObjectAnimator alpha = ObjectAnimator.ofFloat(screen, View.ALPHA, 0, 1);
|
65
|
54
|
alpha.setInterpolator(new DecelerateInterpolator());
|
66
|
55
|
alpha.setDuration(200);
|
67
|
56
|
|
68
|
|
- ObjectAnimator translationY = ObjectAnimator.ofFloat(screenToShow, View.TRANSLATION_Y, translationYValue, 0);
|
|
57
|
+ ObjectAnimator translationY = ObjectAnimator.ofFloat(screen, View.TRANSLATION_Y, this.translationY, 0);
|
69
|
58
|
translationY.setInterpolator(new DecelerateInterpolator());
|
70
|
59
|
translationY.setDuration(280);
|
71
|
60
|
|
|
@@ -74,26 +63,26 @@ public class ScreenAnimator {
|
74
|
63
|
set.addListener(new AnimatorListenerAdapter() {
|
75
|
64
|
@Override
|
76
|
65
|
public void onAnimationStart(Animator animation) {
|
77
|
|
- screenToShow.setVisibility(View.VISIBLE);
|
|
66
|
+ screen.setVisibility(View.VISIBLE);
|
78
|
67
|
}
|
79
|
68
|
|
80
|
69
|
@Override
|
81
|
70
|
public void onAnimationEnd(Animator animation) {
|
82
|
|
- onScreenRemoved.run();
|
|
71
|
+ if (onAnimationEnd != null) {
|
|
72
|
+ onAnimationEnd.run();
|
|
73
|
+ }
|
83
|
74
|
}
|
84
|
75
|
});
|
85
|
76
|
return set;
|
86
|
77
|
}
|
87
|
78
|
|
88
|
|
- private Animator createPopAnimator(final Screen screenToHide, final Runnable onScreenRemoved) {
|
89
|
|
- final float translationYValue = 0.08f * ViewUtils.getScreenHeight();
|
90
|
|
-
|
91
|
|
- ObjectAnimator alpha = ObjectAnimator.ofFloat(screenToHide, View.ALPHA, 0);
|
|
79
|
+ private Animator createHideAnimator(final Runnable onAnimationEnd) {
|
|
80
|
+ ObjectAnimator alpha = ObjectAnimator.ofFloat(screen, View.ALPHA, 0);
|
92
|
81
|
alpha.setInterpolator(new LinearInterpolator());
|
93
|
82
|
alpha.setStartDelay(100);
|
94
|
83
|
alpha.setDuration(150);
|
95
|
84
|
|
96
|
|
- ObjectAnimator translationY = ObjectAnimator.ofFloat(screenToHide, View.TRANSLATION_Y, translationYValue);
|
|
85
|
+ ObjectAnimator translationY = ObjectAnimator.ofFloat(screen, View.TRANSLATION_Y, this.translationY);
|
97
|
86
|
translationY.setInterpolator(new AccelerateInterpolator());
|
98
|
87
|
translationY.setDuration(250);
|
99
|
88
|
|
|
@@ -102,7 +91,7 @@ public class ScreenAnimator {
|
102
|
91
|
set.addListener(new AnimatorListenerAdapter() {
|
103
|
92
|
@Override
|
104
|
93
|
public void onAnimationEnd(Animator animation) {
|
105
|
|
- onScreenRemoved.run();
|
|
94
|
+ onAnimationEnd.run();
|
106
|
95
|
}
|
107
|
96
|
});
|
108
|
97
|
return set;
|