@@ -210,44 +210,6 @@ class ViewPropertySpringAnimator<T : View>(
210210 animatePropertyInternal(property, value + property.getValue(view), config)
211211 }
212212
213- private fun animatePropertyInternal (
214- property : FloatPropertyCompat <in T >,
215- finalValue : Float ,
216- configBuilder : SpringAnimationConfig .() -> Unit = {}
217- ) {
218- var anim = animatorMap[property]
219- if (anim == null ) {
220- anim = SpringAnimation (view, property)
221- anim.cleanSelfOnEnd(property)
222- animatorMap[property] = anim
223- }
224- val config = SpringAnimationConfig (finalValue).apply (configBuilder)
225- config.defaultDampingRatio = defaultDampingRatio
226- config.defaultStiffness = defaultStiffness
227- pendingAnimations + = SpringAnimationHolder (anim, config)
228- }
229-
230- private fun SpringAnimation.cleanSelfOnEnd (
231- property : FloatPropertyCompat <in T >
232- ) {
233- val listener = object : DynamicAnimation .OnAnimationEndListener {
234- override fun onAnimationEnd (
235- animation : DynamicAnimation <out DynamicAnimation <* >>? ,
236- canceled : Boolean ,
237- value : Float ,
238- velocity : Float
239- ) {
240- animatorMap.remove(property)
241- animation?.removeEndListener(this )
242-
243- if (animatorMap.isEmpty() && ! canceled) {
244- animatorListener?.onAnimationEnd(this @ViewPropertySpringAnimator)
245- }
246- }
247- }
248- addEndListener(listener)
249- }
250-
251213 @MainThread
252214 fun start (): ViewPropertySpringAnimator <T > = apply {
253215 if (pendingAnimations.isEmpty()) return @apply
@@ -320,4 +282,42 @@ class ViewPropertySpringAnimator<T : View>(
320282 setter.invoke(view, value)
321283 }
322284 }
285+
286+ private fun animatePropertyInternal (
287+ property : FloatPropertyCompat <in T >,
288+ finalValue : Float ,
289+ configBuilder : SpringAnimationConfig .() -> Unit = {}
290+ ) {
291+ var anim = animatorMap[property]
292+ if (anim == null ) {
293+ anim = SpringAnimation (view, property)
294+ anim.cleanSelfOnEnd(property)
295+ animatorMap[property] = anim
296+ }
297+ val config = SpringAnimationConfig (finalValue).apply (configBuilder)
298+ config.defaultDampingRatio = defaultDampingRatio
299+ config.defaultStiffness = defaultStiffness
300+ pendingAnimations + = SpringAnimationHolder (anim, config)
301+ }
302+
303+ private fun SpringAnimation.cleanSelfOnEnd (
304+ property : FloatPropertyCompat <in T >
305+ ) {
306+ val listener = object : DynamicAnimation .OnAnimationEndListener {
307+ override fun onAnimationEnd (
308+ animation : DynamicAnimation <out DynamicAnimation <* >>? ,
309+ canceled : Boolean ,
310+ value : Float ,
311+ velocity : Float
312+ ) {
313+ animatorMap.remove(property)
314+ animation?.removeEndListener(this )
315+
316+ if (animatorMap.isEmpty() && ! canceled) {
317+ animatorListener?.onAnimationEnd(this @ViewPropertySpringAnimator)
318+ }
319+ }
320+ }
321+ addEndListener(listener)
322+ }
323323}
0 commit comments