Last active
August 11, 2020 14:11
-
-
Save mr5z/94314d6bf8015b66381eea8cc6f53ec9 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
private class LayoutObserver(private val view: View, private val callback: (Size) -> Unit) : ViewTreeObserver.OnGlobalLayoutListener { | |
init { | |
if (!view.viewTreeObserver.isAlive) | |
throw IllegalArgumentException("Go fuck yourself") | |
view.viewTreeObserver.addOnGlobalLayoutListener(this) | |
} | |
override fun onGlobalLayout() { | |
view.viewTreeObserver.removeOnGlobalLayoutListener(this) | |
callback(Size(view.width, view.height)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment