Skip to content

Instantly share code, notes, and snippets.

View Sardorbekcyber's full-sized avatar
🎯
Growing

Sardor Narziyev Sardorbekcyber

🎯
Growing
View GitHub Profile
@Sardorbekcyber
Sardorbekcyber / fadeTo.kt
Created May 21, 2021 18:18 — forked from gpeal/fadeTo.kt
Fade To
/**
* Fade a view to visible or gone. This function is idempotent - it can be called over and over again with the same
* value without affecting an in-progress animation.
*/
fun View.fadeTo(visible: Boolean, duration: Long = 500, startDelay: Long = 0, toAlpha: Float = 1f) {
// Make this idempotent.
val tagKey = "fadeTo".hashCode()
if (visible == isVisible && animation == null && getTag(tagKey) == null) return
if (getTag(tagKey) == visible) return