Skip to content

Instantly share code, notes, and snippets.

@Sardorbekcyber
Last active October 25, 2021 18:21
Show Gist options
  • Save Sardorbekcyber/64e6678eda5582d532c2af985ed3c0a7 to your computer and use it in GitHub Desktop.
Save Sardorbekcyber/64e6678eda5582d532c2af985ed3c0a7 to your computer and use it in GitHub Desktop.
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
fun View.hide() {
// get the center for the clipping circle
val cx = this.width / 2
val cy = this.height / 2
// get the initial radius for the clipping circle
val initialRadius = hypot(cx.toDouble(), cy.toDouble()).toFloat()
// create the animation (the final radius is zero)
val anim = ViewAnimationUtils.createCircularReveal(this, cx, cy, initialRadius, 0f)
// make the view invisible when the animation is done
anim.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
super.onAnimationEnd(animation)
this@hide.visibility = View.INVISIBLE
}
})
// start the animation
anim.start()
}
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
fun View.show() {
// get the center for the clipping circle
val cx = this.width / 2
val cy = this.height / 2
// get the final radius for the clipping circle
val finalRadius = hypot(cx.toDouble(), cy.toDouble()).toFloat()
// create the animator for this view (the start radius is zero)
val anim = ViewAnimationUtils.createCircularReveal(this, cx, cy, 0f, finalRadius)
// make the view visible and start the animation
this.visibility = View.VISIBLE
anim.start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment