|
@@ -5,18 +5,28 @@ import android.animation.AnimatorListenerAdapter;
|
5
|
5
|
import android.animation.AnimatorSet;
|
6
|
6
|
import android.animation.ObjectAnimator;
|
7
|
7
|
import android.view.View;
|
|
8
|
+import android.view.animation.AccelerateDecelerateInterpolator;
|
8
|
9
|
import android.view.animation.AccelerateInterpolator;
|
9
|
10
|
import android.view.animation.DecelerateInterpolator;
|
10
|
11
|
import android.view.animation.LinearInterpolator;
|
|
12
|
+
|
11
|
13
|
import com.reactnativenavigation.NavigationApplication;
|
12
|
14
|
import com.reactnativenavigation.utils.ViewUtils;
|
13
|
15
|
import com.reactnativenavigation.views.sharedElementTransition.SharedElementsAnimator;
|
14
|
16
|
|
15
|
|
-import javax.annotation.Nullable;
|
16
|
17
|
import java.util.ArrayList;
|
17
|
18
|
import java.util.List;
|
18
|
19
|
|
|
20
|
+import javax.annotation.Nullable;
|
|
21
|
+
|
19
|
22
|
class ScreenAnimator {
|
|
23
|
+ private static final int DURATION = 250;
|
|
24
|
+ private static final int ALPHA_START_DELAY = 100;
|
|
25
|
+ private static final int ALPHA_SHORT_DURATION = 150;
|
|
26
|
+ private static final LinearInterpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
|
|
27
|
+ private static final DecelerateInterpolator DECELERATE_INTERPOLATOR = new DecelerateInterpolator();
|
|
28
|
+ private static final AccelerateDecelerateInterpolator ACCELERATE_DECELERATE_INTERPOLATOR = new AccelerateDecelerateInterpolator();
|
|
29
|
+ private static final AccelerateInterpolator ACCELERATE_INTERPOLATOR = new AccelerateInterpolator();
|
20
|
30
|
private final float translationY;
|
21
|
31
|
private final float translationX;
|
22
|
32
|
private Screen screen;
|
|
@@ -24,7 +34,7 @@ class ScreenAnimator {
|
24
|
34
|
ScreenAnimator(Screen screen) {
|
25
|
35
|
this.screen = screen;
|
26
|
36
|
translationY = 0.08f * ViewUtils.getWindowHeight(screen.activity);
|
27
|
|
- translationX = 0.08f * ViewUtils.getWindowWidth(screen.activity);
|
|
37
|
+ translationX = ViewUtils.getWindowWidth(screen.activity);
|
28
|
38
|
}
|
29
|
39
|
|
30
|
40
|
public void show(boolean animate, final Runnable onAnimationEnd) {
|
|
@@ -32,7 +42,7 @@ class ScreenAnimator {
|
32
|
42
|
createShowAnimator(onAnimationEnd).start();
|
33
|
43
|
} else {
|
34
|
44
|
screen.setVisibility(View.VISIBLE);
|
35
|
|
- NavigationApplication.instance.runOnMainThread(onAnimationEnd, 200);
|
|
45
|
+ NavigationApplication.instance.runOnMainThread(onAnimationEnd, DURATION);
|
36
|
46
|
}
|
37
|
47
|
}
|
38
|
48
|
|
|
@@ -55,28 +65,27 @@ class ScreenAnimator {
|
55
|
65
|
|
56
|
66
|
private Animator createShowAnimator(final @Nullable Runnable onAnimationEnd) {
|
57
|
67
|
ObjectAnimator alpha = ObjectAnimator.ofFloat(screen, View.ALPHA, 0, 1);
|
58
|
|
- alpha.setInterpolator(new DecelerateInterpolator());
|
59
|
|
- alpha.setDuration(200);
|
|
68
|
+ alpha.setInterpolator(DECELERATE_INTERPOLATOR);
|
60
|
69
|
|
61
|
70
|
AnimatorSet set = new AnimatorSet();
|
62
|
71
|
switch (String.valueOf(this.screen.screenParams.animationType)) {
|
63
|
72
|
case "fade": {
|
|
73
|
+ alpha.setDuration(DURATION);
|
64
|
74
|
set.play(alpha);
|
65
|
75
|
break;
|
66
|
76
|
}
|
67
|
77
|
case "slide-horizontal": {
|
68
|
78
|
ObjectAnimator translationX = ObjectAnimator.ofFloat(screen, View.TRANSLATION_X, this.translationX, 0);
|
69
|
|
- translationX.setInterpolator(new DecelerateInterpolator());
|
70
|
|
- translationX.setDuration(280);
|
71
|
|
-
|
72
|
|
- set.playTogether(translationX, alpha);
|
|
79
|
+ translationX.setInterpolator(ACCELERATE_DECELERATE_INTERPOLATOR);
|
|
80
|
+ translationX.setDuration(DURATION);
|
|
81
|
+ set.play(translationX);
|
73
|
82
|
break;
|
74
|
83
|
}
|
75
|
84
|
default: {
|
76
|
85
|
ObjectAnimator translationY = ObjectAnimator.ofFloat(screen, View.TRANSLATION_Y, this.translationY, 0);
|
77
|
|
- translationY.setInterpolator(new DecelerateInterpolator());
|
78
|
|
- translationY.setDuration(280);
|
79
|
|
-
|
|
86
|
+ translationY.setInterpolator(DECELERATE_INTERPOLATOR);
|
|
87
|
+ translationY.setDuration(DURATION);
|
|
88
|
+ alpha.setDuration(ALPHA_SHORT_DURATION);
|
80
|
89
|
set.playTogether(translationY, alpha);
|
81
|
90
|
break;
|
82
|
91
|
}
|
|
@@ -100,29 +109,28 @@ class ScreenAnimator {
|
100
|
109
|
|
101
|
110
|
private Animator createHideAnimator(final Runnable onAnimationEnd) {
|
102
|
111
|
ObjectAnimator alpha = ObjectAnimator.ofFloat(screen, View.ALPHA, 0);
|
103
|
|
- alpha.setInterpolator(new LinearInterpolator());
|
104
|
|
- alpha.setStartDelay(100);
|
105
|
|
- alpha.setDuration(150);
|
|
112
|
+ alpha.setInterpolator(DECELERATE_INTERPOLATOR);
|
106
|
113
|
|
107
|
114
|
AnimatorSet set = new AnimatorSet();
|
108
|
115
|
switch (String.valueOf(this.screen.screenParams.animationType)) {
|
109
|
116
|
case "fade": {
|
|
117
|
+ alpha.setDuration(DURATION);
|
110
|
118
|
set.play(alpha);
|
111
|
119
|
break;
|
112
|
120
|
}
|
113
|
121
|
case "slide-horizontal": {
|
114
|
122
|
ObjectAnimator translationX = ObjectAnimator.ofFloat(screen, View.TRANSLATION_X, this.translationX);
|
115
|
|
- translationX.setInterpolator(new AccelerateInterpolator());
|
116
|
|
- translationX.setDuration(250);
|
117
|
|
-
|
118
|
|
- set.playTogether(translationX, alpha);
|
|
123
|
+ translationX.setInterpolator(ACCELERATE_INTERPOLATOR);
|
|
124
|
+ translationX.setDuration(DURATION);
|
|
125
|
+ set.play(translationX);
|
119
|
126
|
break;
|
120
|
127
|
}
|
121
|
128
|
default: {
|
122
|
129
|
ObjectAnimator translationY = ObjectAnimator.ofFloat(screen, View.TRANSLATION_Y, this.translationY);
|
123
|
|
- translationY.setInterpolator(new AccelerateInterpolator());
|
124
|
|
- translationY.setDuration(250);
|
125
|
|
-
|
|
130
|
+ translationY.setInterpolator(ACCELERATE_INTERPOLATOR);
|
|
131
|
+ translationY.setDuration(DURATION);
|
|
132
|
+ alpha.setStartDelay(ALPHA_START_DELAY);
|
|
133
|
+ alpha.setDuration(ALPHA_SHORT_DURATION);
|
126
|
134
|
set.playTogether(translationY, alpha);
|
127
|
135
|
break;
|
128
|
136
|
}
|