Skip to content

Instantly share code, notes, and snippets.

@AshuTyagi16
Created May 14, 2020 11:17
Show Gist options
  • Save AshuTyagi16/f6bf1441ff97f7f8aac697f89a8a151f to your computer and use it in GitHub Desktop.
Save AshuTyagi16/f6bf1441ff97f7f8aac697f89a8a151f to your computer and use it in GitHub Desktop.
var currentVelocity = 0f
/**
* A [SpringAnimation] for this RecyclerView item. This animation rotates the view with a bouncy
* spring configuration, resulting in the oscillation effect.
*
* The animation is started in [Recyclerview.onScrollListener].
*/
val rotation: SpringAnimation = SpringAnimation(itemView, SpringAnimation.ROTATION)
.setSpring(
SpringForce()
.setFinalPosition(0f)
.setDampingRatio(SpringForce.DAMPING_RATIO_HIGH_BOUNCY)
.setStiffness(SpringForce.STIFFNESS_LOW)
)
.addUpdateListener { _, _, velocity ->
currentVelocity = velocity
}
/**
* A [SpringAnimation] for this RecyclerView item. This animation is used to bring the item back
* after the over-scroll effect.
*/
val translationY: SpringAnimation = SpringAnimation(itemView, SpringAnimation.TRANSLATION_Y)
.setSpring(
SpringForce()
.setFinalPosition(0f)
.setDampingRatio(SpringForce.DAMPING_RATIO_MEDIUM_BOUNCY)
.setStiffness(SpringForce.STIFFNESS_LOW)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment