|
@@ -5,6 +5,9 @@ import android.animation.ObjectAnimator;
|
5
|
5
|
import android.support.annotation.NonNull;
|
6
|
6
|
import android.view.View;
|
7
|
7
|
|
|
8
|
+import com.facebook.drawee.drawable.ScalingUtils;
|
|
9
|
+import com.facebook.drawee.generic.GenericDraweeHierarchy;
|
|
10
|
+import com.facebook.drawee.view.DraweeView;
|
8
|
11
|
import com.reactnativenavigation.params.InterpolationParams;
|
9
|
12
|
import com.reactnativenavigation.params.PathInterpolationParams;
|
10
|
13
|
import com.reactnativenavigation.params.parsers.SharedElementTransitionParams;
|
|
@@ -49,54 +52,47 @@ class SharedElementAnimatorCreator {
|
49
|
52
|
result.add(createYAnimator(resolver, params));
|
50
|
53
|
}
|
51
|
54
|
}
|
52
|
|
- if (shouldCreateScaleXAnimator(resolver, params)) {
|
|
55
|
+ if (shouldAddScaleXAnimator(resolver, params)) {
|
53
|
56
|
result.add(createScaleXAnimator(resolver, params));
|
54
|
57
|
}
|
55
|
|
- if (shouldCreateScaleYAnimator(resolver, params)) {
|
|
58
|
+ if (shouldAddScaleYAnimator(resolver, params)) {
|
56
|
59
|
result.add(createScaleYAnimator(resolver, params));
|
57
|
60
|
}
|
58
|
|
- if (shouldCreateColorAnimator(resolver)) {
|
|
61
|
+ if (shouldAddColorAnimator(resolver)) {
|
59
|
62
|
result.add(createColorAnimator(resolver, params.duration));
|
60
|
63
|
}
|
61
|
|
- if (shouldCreateImageClipBoundsAnimator(params)) {
|
|
64
|
+ if (shouldAddImageClipBoundsAnimator(params)) {
|
62
|
65
|
result.add(createImageClipBoundsAnimator(resolver, params.duration));
|
|
66
|
+ result.add(createImageTransformAnimator(resolver, params));
|
63
|
67
|
}
|
64
|
68
|
return result;
|
65
|
69
|
}
|
66
|
70
|
|
67
|
|
- private boolean shouldCreateScaleYAnimator(AnimatorValuesResolver resolver, SharedElementTransitionParams params) {
|
|
71
|
+ private boolean shouldAddScaleYAnimator(AnimatorValuesResolver resolver, SharedElementTransitionParams params) {
|
68
|
72
|
return resolver.startScaleY != resolver.endScaleY && !params.animateClipBounds;
|
69
|
73
|
}
|
70
|
74
|
|
71
|
|
- private boolean shouldCreateScaleXAnimator(AnimatorValuesResolver resolver, SharedElementTransitionParams params) {
|
|
75
|
+ private boolean shouldAddScaleXAnimator(AnimatorValuesResolver resolver, SharedElementTransitionParams params) {
|
72
|
76
|
return resolver.startScaleX != resolver.endScaleX && !params.animateClipBounds;
|
73
|
77
|
}
|
74
|
78
|
|
75
|
79
|
private boolean shouldAddLinearMotionXAnimator(AnimatorValuesResolver resolver, SharedElementTransitionParams params) {
|
76
|
|
- if (params.animateClipBounds) {
|
77
|
|
- return to.getWidth() - from.getWidth() != resolver.dx * 2;
|
78
|
|
- } else {
|
79
|
|
- return resolver.dx != 0;
|
80
|
|
- }
|
|
80
|
+ return params.animateClipBounds || resolver.dx != 0;
|
81
|
81
|
}
|
82
|
82
|
|
83
|
83
|
private boolean shouldAddLinearMotionYAnimator(AnimatorValuesResolver resolver, SharedElementTransitionParams params) {
|
84
|
|
- if (params.animateClipBounds) {
|
85
|
|
- return to.getHeight() - from.getHeight() != resolver.dy * 2;
|
86
|
|
- } else {
|
87
|
|
- return resolver.dy != 0;
|
88
|
|
- }
|
|
84
|
+ return params.animateClipBounds || resolver.dy != 0;
|
89
|
85
|
}
|
90
|
86
|
|
91
|
87
|
private boolean shouldAddCurvedMotionAnimator(AnimatorValuesResolver resolver, InterpolationParams interpolation) {
|
92
|
88
|
return interpolation instanceof PathInterpolationParams && (resolver.dx != 0 || resolver.dy != 0);
|
93
|
89
|
}
|
94
|
90
|
|
95
|
|
- private boolean shouldCreateColorAnimator(AnimatorValuesResolver resolver) {
|
|
91
|
+ private boolean shouldAddColorAnimator(AnimatorValuesResolver resolver) {
|
96
|
92
|
return resolver.startColor != resolver.endColor;
|
97
|
93
|
}
|
98
|
94
|
|
99
|
|
- private boolean shouldCreateImageClipBoundsAnimator(SharedElementTransitionParams params) {
|
|
95
|
+ private boolean shouldAddImageClipBoundsAnimator(SharedElementTransitionParams params) {
|
100
|
96
|
return params.animateClipBounds;
|
101
|
97
|
}
|
102
|
98
|
|
|
@@ -130,16 +126,18 @@ class SharedElementAnimatorCreator {
|
130
|
126
|
|
131
|
127
|
private ObjectAnimator createScaleXAnimator(AnimatorValuesResolver resolver, SharedElementTransitionParams params) {
|
132
|
128
|
to.getSharedView().setPivotX(0);
|
133
|
|
- ObjectAnimator animator = ofFloat(to.getSharedView(), View.SCALE_X, resolver.startScaleX, resolver.endScaleX)
|
134
|
|
- .setDuration(params.duration);
|
|
129
|
+ ObjectAnimator animator =
|
|
130
|
+ ofFloat(to.getSharedView(), View.SCALE_X, resolver.startScaleX, resolver.endScaleX)
|
|
131
|
+ .setDuration(params.duration);
|
135
|
132
|
animator.setInterpolator(params.interpolation.easing.getInterpolator());
|
136
|
133
|
return animator;
|
137
|
134
|
}
|
138
|
135
|
|
139
|
136
|
private ObjectAnimator createScaleYAnimator(AnimatorValuesResolver resolver, SharedElementTransitionParams params) {
|
140
|
137
|
to.getSharedView().setPivotY(0);
|
141
|
|
- ObjectAnimator animator = ofFloat(to.getSharedView(), View.SCALE_Y, resolver.startScaleY, resolver.endScaleY)
|
142
|
|
- .setDuration(params.duration);
|
|
138
|
+ ObjectAnimator animator =
|
|
139
|
+ ofFloat(to.getSharedView(), View.SCALE_Y, resolver.startScaleY, resolver.endScaleY)
|
|
140
|
+ .setDuration(params.duration);
|
143
|
141
|
animator.setInterpolator(params.interpolation.easing.getInterpolator());
|
144
|
142
|
return animator;
|
145
|
143
|
}
|
|
@@ -163,4 +161,16 @@ class SharedElementAnimatorCreator {
|
163
|
161
|
resolver.endDrawingRect)
|
164
|
162
|
.setDuration(duration);
|
165
|
163
|
}
|
|
164
|
+ private Animator createImageTransformAnimator(AnimatorValuesResolver resolver, SharedElementTransitionParams params) {
|
|
165
|
+ ScalingUtils.InterpolatingScaleType ist = new ScalingUtils.InterpolatingScaleType(
|
|
166
|
+ resolver.fromScaleType,
|
|
167
|
+ resolver.toScaleType,
|
|
168
|
+ resolver.fromBounds,
|
|
169
|
+ resolver.toBounds
|
|
170
|
+ );
|
|
171
|
+ ((DraweeView<GenericDraweeHierarchy>) to.getSharedView()).getHierarchy().setActualImageScaleType(ist);
|
|
172
|
+ ObjectAnimator animator = ObjectAnimator.ofFloat(to, "matrixTransform", 0, 1).setDuration(params.duration);
|
|
173
|
+ animator.setInterpolator(params.interpolation.easing.getInterpolator());
|
|
174
|
+ return animator;
|
|
175
|
+ }
|
166
|
176
|
}
|