Skip to content

Commit 0d8ebb4

Browse files
authored
Merge pull request #7 from lcdsmao/fix-animate-by
fix animate by
2 parents bab7faf + ab9fdc3 commit 0d8ebb4

File tree

2 files changed

+57
-61
lines changed

2 files changed

+57
-61
lines changed

library/src/main/java/com/github/lcdsmao/springx/SpringAnimationConfig.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ class SpringAnimationConfig internal constructor(private var finalValue: Float)
1010
val NOT_SET = Float.MAX_VALUE
1111
}
1212

13-
internal var finalValueBias: Float = 0f
14-
1513
private var startValueIsSet: Boolean = false
1614
var startValue: Float = NOT_SET
1715
set(value) {

library/src/main/java/com/github/lcdsmao/springx/ViewPropertySpringAnimator.kt

Lines changed: 57 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -35,185 +35,184 @@ class ViewPropertySpringAnimator<T : View>(
3535
}
3636

3737
fun x(
38-
finalValue: Float,
38+
value: Float,
3939
config: SpringAnimationConfig.() -> Unit = {}
4040
): ViewPropertySpringAnimator<T> =
41-
animateProperty(DynamicAnimation.X, finalValue, config)
41+
animateProperty(DynamicAnimation.X, value, config)
4242

4343
fun xBy(
44-
finalValue: Float,
44+
value: Float,
4545
config: SpringAnimationConfig.() -> Unit = {}
4646
): ViewPropertySpringAnimator<T> =
47-
animatePropertyBy(DynamicAnimation.X, finalValue, config)
47+
animatePropertyBy(DynamicAnimation.X, value, config)
4848

4949
fun y(
50-
finalValue: Float,
50+
value: Float,
5151
config: SpringAnimationConfig.() -> Unit = {}
5252
): ViewPropertySpringAnimator<T> =
53-
animateProperty(DynamicAnimation.Y, finalValue, config)
53+
animateProperty(DynamicAnimation.Y, value, config)
5454

5555
fun yBy(
56-
finalValue: Float,
56+
value: Float,
5757
config: SpringAnimationConfig.() -> Unit = {}
5858
): ViewPropertySpringAnimator<T> =
59-
animatePropertyBy(DynamicAnimation.Y, finalValue, config)
59+
animatePropertyBy(DynamicAnimation.Y, value, config)
6060

6161
fun z(
62-
finalValue: Float,
62+
value: Float,
6363
config: SpringAnimationConfig.() -> Unit = {}
6464
): ViewPropertySpringAnimator<T> =
65-
animateProperty(DynamicAnimation.Z, finalValue, config)
65+
animateProperty(DynamicAnimation.Z, value, config)
6666

6767
fun zBy(
68-
finalValue: Float,
68+
value: Float,
6969
config: SpringAnimationConfig.() -> Unit = {}
7070
): ViewPropertySpringAnimator<T> =
71-
animatePropertyBy(DynamicAnimation.Z, finalValue, config)
71+
animatePropertyBy(DynamicAnimation.Z, value, config)
7272

7373
fun rotation(
74-
finalValue: Float,
74+
value: Float,
7575
config: SpringAnimationConfig.() -> Unit = {}
7676
): ViewPropertySpringAnimator<T> =
77-
animateProperty(DynamicAnimation.ROTATION, finalValue, config)
77+
animateProperty(DynamicAnimation.ROTATION, value, config)
7878

7979
fun rotationBy(
80-
finalValue: Float,
80+
value: Float,
8181
config: SpringAnimationConfig.() -> Unit = {}
8282
): ViewPropertySpringAnimator<T> =
83-
animatePropertyBy(DynamicAnimation.ROTATION, finalValue, config)
83+
animatePropertyBy(DynamicAnimation.ROTATION, value, config)
8484

8585
fun rotationX(
86-
finalValue: Float,
86+
value: Float,
8787
config: SpringAnimationConfig.() -> Unit = {}
8888
): ViewPropertySpringAnimator<T> =
89-
animateProperty(DynamicAnimation.ROTATION_X, finalValue, config)
89+
animateProperty(DynamicAnimation.ROTATION_X, value, config)
9090

9191
fun rotationXBy(
92-
finalValue: Float,
92+
value: Float,
9393
config: SpringAnimationConfig.() -> Unit = {}
9494
): ViewPropertySpringAnimator<T> =
95-
animatePropertyBy(DynamicAnimation.ROTATION_X, finalValue, config)
95+
animatePropertyBy(DynamicAnimation.ROTATION_X, value, config)
9696

9797
fun rotationY(
98-
finalValue: Float,
98+
value: Float,
9999
config: SpringAnimationConfig.() -> Unit = {}
100100
): ViewPropertySpringAnimator<T> =
101-
animateProperty(DynamicAnimation.ROTATION_Y, finalValue, config)
101+
animateProperty(DynamicAnimation.ROTATION_Y, value, config)
102102

103103
fun rotationYBy(
104-
finalValue: Float,
104+
value: Float,
105105
config: SpringAnimationConfig.() -> Unit = {}
106106
): ViewPropertySpringAnimator<T> =
107-
animatePropertyBy(DynamicAnimation.ROTATION_Y, finalValue, config)
107+
animatePropertyBy(DynamicAnimation.ROTATION_Y, value, config)
108108

109109
fun translationX(
110-
finalValue: Float,
110+
value: Float,
111111
config: SpringAnimationConfig.() -> Unit = {}
112112
): ViewPropertySpringAnimator<T> =
113-
animateProperty(DynamicAnimation.TRANSLATION_X, finalValue, config)
113+
animateProperty(DynamicAnimation.TRANSLATION_X, value, config)
114114

115115
fun translationXBy(
116-
finalValue: Float,
116+
value: Float,
117117
config: SpringAnimationConfig.() -> Unit = {}
118118
): ViewPropertySpringAnimator<T> =
119-
animatePropertyBy(DynamicAnimation.TRANSLATION_X, finalValue, config)
119+
animatePropertyBy(DynamicAnimation.TRANSLATION_X, value, config)
120120

121121
fun translationY(
122-
finalValue: Float,
122+
value: Float,
123123
config: SpringAnimationConfig.() -> Unit = {}
124124
): ViewPropertySpringAnimator<T> =
125-
animateProperty(DynamicAnimation.TRANSLATION_Y, finalValue, config)
125+
animateProperty(DynamicAnimation.TRANSLATION_Y, value, config)
126126

127127
fun translationYBy(
128-
finalValue: Float,
128+
value: Float,
129129
config: SpringAnimationConfig.() -> Unit = {}
130130
): ViewPropertySpringAnimator<T> =
131-
animatePropertyBy(DynamicAnimation.TRANSLATION_Y, finalValue, config)
131+
animatePropertyBy(DynamicAnimation.TRANSLATION_Y, value, config)
132132

133133
fun translationZ(
134-
finalValue: Float,
134+
value: Float,
135135
config: SpringAnimationConfig.() -> Unit = {}
136136
): ViewPropertySpringAnimator<T> =
137-
animateProperty(DynamicAnimation.TRANSLATION_Z, finalValue, config)
137+
animateProperty(DynamicAnimation.TRANSLATION_Z, value, config)
138138

139139
fun translationZBy(
140-
finalValue: Float,
140+
value: Float,
141141
config: SpringAnimationConfig.() -> Unit = {}
142142
): ViewPropertySpringAnimator<T> =
143-
animatePropertyBy(DynamicAnimation.TRANSLATION_Z, finalValue, config)
143+
animatePropertyBy(DynamicAnimation.TRANSLATION_Z, value, config)
144144

145145
fun scaleX(
146-
finalValue: Float,
146+
value: Float,
147147
config: SpringAnimationConfig.() -> Unit = {}
148148
): ViewPropertySpringAnimator<T> =
149-
animateProperty(DynamicAnimation.SCALE_X, finalValue, config)
149+
animateProperty(DynamicAnimation.SCALE_X, value, config)
150150

151151
fun scaleXBy(
152-
finalValue: Float,
152+
value: Float,
153153
config: SpringAnimationConfig.() -> Unit = {}
154154
): ViewPropertySpringAnimator<T> =
155-
animatePropertyBy(DynamicAnimation.SCALE_X, finalValue, config)
155+
animatePropertyBy(DynamicAnimation.SCALE_X, value, config)
156156

157157
fun scaleY(
158-
finalValue: Float,
158+
value: Float,
159159
config: SpringAnimationConfig.() -> Unit = {}
160160
): ViewPropertySpringAnimator<T> =
161-
animateProperty(DynamicAnimation.SCALE_Y, finalValue, config)
161+
animateProperty(DynamicAnimation.SCALE_Y, value, config)
162162

163163
fun scaleYBy(
164-
finalValue: Float,
164+
value: Float,
165165
config: SpringAnimationConfig.() -> Unit = {}
166166
): ViewPropertySpringAnimator<T> =
167-
animatePropertyBy(DynamicAnimation.SCALE_Y, finalValue, config)
167+
animatePropertyBy(DynamicAnimation.SCALE_Y, value, config)
168168

169169
fun alpha(
170-
finalValue: Float,
170+
value: Float,
171171
config: SpringAnimationConfig.() -> Unit = {}
172172
): ViewPropertySpringAnimator<T> =
173-
animateProperty(DynamicAnimation.ALPHA, finalValue, config)
173+
animateProperty(DynamicAnimation.ALPHA, value, config)
174174

175175
fun alphaBy(
176-
finalValue: Float,
176+
value: Float,
177177
config: SpringAnimationConfig.() -> Unit = {}
178178
): ViewPropertySpringAnimator<T> =
179-
animatePropertyBy(DynamicAnimation.ALPHA, finalValue, config)
179+
animatePropertyBy(DynamicAnimation.ALPHA, value, config)
180180

181181
fun animateProperty(
182-
finalValue: Float,
182+
value: Float,
183183
setter: T.(Float) -> Unit,
184184
getter: T.() -> Float,
185185
config: SpringAnimationConfig.() -> Unit = {}
186186
): ViewPropertySpringAnimator<T> =
187-
animateProperty(createCustomProperty(setter, getter), finalValue, config)
187+
animateProperty(createCustomProperty(setter, getter), value, config)
188188

189189
fun animatePropertyBy(
190190
setter: T.(Float) -> Unit,
191191
getter: T.() -> Float,
192-
finalValue: Float,
192+
value: Float,
193193
config: SpringAnimationConfig.() -> Unit = {}
194194
): ViewPropertySpringAnimator<T> =
195-
animatePropertyBy(createCustomProperty(setter, getter), finalValue, config)
195+
animatePropertyBy(createCustomProperty(setter, getter), value, config)
196196

197197
fun animateProperty(
198198
property: FloatPropertyCompat<in T>,
199-
finalValue: Float,
199+
value: Float,
200200
config: SpringAnimationConfig.() -> Unit = {}
201201
) = apply {
202-
animateProperty(property, finalValue, 0f, config)
202+
animatePropertyInternal(property, value, config)
203203
}
204204

205205
fun animatePropertyBy(
206206
property: FloatPropertyCompat<in T>,
207-
finalValue: Float,
207+
value: Float,
208208
config: SpringAnimationConfig.() -> Unit = {}
209209
) = apply {
210-
animateProperty(property, finalValue, property.getValue(view), config)
210+
animatePropertyInternal(property, value + property.getValue(view), config)
211211
}
212212

213-
private fun animateProperty(
213+
private fun animatePropertyInternal(
214214
property: FloatPropertyCompat<in T>,
215215
finalValue: Float,
216-
finalValueBias: Float,
217216
configBuilder: SpringAnimationConfig.() -> Unit = {}
218217
) {
219218
var anim = runningAnimations[property]
@@ -225,7 +224,6 @@ class ViewPropertySpringAnimator<T : View>(
225224
val config = SpringAnimationConfig(finalValue).apply(configBuilder)
226225
config.defaultDampingRatio = defaultDampingRatio
227226
config.defaultStiffness = defaultStiffness
228-
config.finalValueBias = finalValueBias
229227
pendingAnimations += SpringAnimationHolder(anim, config)
230228
}
231229

0 commit comments

Comments
 (0)