Created
November 30, 2018 22:23
-
-
Save afollestad/62fd4afa86883b7aba83ee0589d09ebc to your computer and use it in GitHub Desktop.
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
import android.view.View | |
import android.view.ViewTreeObserver | |
fun View.onLayout(cb: () -> Unit) { | |
if (this.viewTreeObserver.isAlive) { | |
this.viewTreeObserver.addOnGlobalLayoutListener( | |
object : ViewTreeObserver.OnGlobalLayoutListener { | |
override fun onGlobalLayout() { | |
cb() | |
this@onLayout.viewTreeObserver.removeOnGlobalLayoutListener(this) | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment