Skip to content

Instantly share code, notes, and snippets.

@nikhilpanju
Created December 2, 2019 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikhilpanju/7d6a1ba871e8ecb0aab6ee4c7ca3943c to your computer and use it in GitHub Desktop.
Save nikhilpanju/7d6a1ba871e8ecb0aab6ee4c7ca3943c to your computer and use it in GitHub Desktop.
inline fun <T : View> T.doOnGlobalLayout(crossinline action: () -> Unit) {
viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
viewTreeObserver.removeOnGlobalLayoutListener(this)
action()
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment