This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <K: View> K.springAnimationOf(property: FloatPropertyCompat<K>, | |
func: SpringForce.() -> Unit): SpringAnimation { | |
val springAnimation = SpringAnimation(this, property) | |
val springForce = SpringForce() | |
springForce.func() | |
springAnimation.spring = springForce | |
return springAnimation | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val springAnimation = view.springAnimationOf(DynamicAnimation.TRANSLATION_X, 0f) { | |
stiffness = STIFFNESS_MEDIUM | |
dampingRatio = DAMPING_RATIO_MEDIUM_BOUNCY | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <K: View> K.springAnimationOf(property: FloatPropertyCompat<K>, | |
finalPosition: Float, | |
func: SpringForce.() -> Unit): SpringAnimation { | |
val springAnimation = SpringAnimation(this, property, finalPosition) | |
springAnimation.spring.func() | |
return springAnimation | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val springForce = SpringForce(0f) | |
.setStiffness(SpringForce.STIFFNESS_MEDIUM) | |
.setDampingRatio(SpringForce.DAMPING_RATIO_HIGH_BOUNCY) | |
val springAnimation = SpringAnimation(view, DynamicAnimation.TRANSLATION_X) | |
.setSpring(springForce) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val springAnimation = view.springAnimationOf(DynamicAnimation.TRANSLATION_Y) | |
val springAnimation = view.springAnimationOf(DynamicAnimation.TRANSLATION_Y, 0f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <K> K.springAnimationOf( | |
property: FloatPropertyCompat<K>, | |
finalPosition: Float = Float.NaN | |
): SpringAnimation { | |
return if (finalPosition.isNaN()) { | |
SpringAnimation(this, property) | |
} else { | |
SpringAnimation(this, property, finalPosition) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <K> K.flingAnimationOf(property: FloatPropertyCompat<K>): FlingAnimation { | |
return FlingAnimation(this, property) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val springAnimation = SpringAnimation(view, DynamicAnimation.TRANSLATION_X) | |
.withSpringForceProperties { | |
finalPosition = 0f | |
stiffness = SpringForce.STIFFNESS_MEDIUM | |
dampingRatio = SpringForce.DAMPING_RATIO_HIGH_BOUNCY | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun SpringAnimation.withSpringForceProperties(func: SpringForce.() -> Unit): SpringAnimation { | |
if (spring == null) { | |
spring = SpringForce() | |
} | |
spring.func() | |
return this | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val springForce = SpringForce(0f) | |
.setStiffness(SpringForce.STIFFNESS_MEDIUM) | |
.setDampingRatio(SpringForce.DAMPING_RATIO_HIGH_BOUNCY) | |
val springAnimation = SpringAnimation(view, DynamicAnimation.TRANSLATION_X).setSpring(springForce) |