Created
November 23, 2018 13:05
-
-
Save vishna/5ff3e51fe2d5ad7a957a3636ba64170c to your computer and use it in GitHub Desktop.
View.doOnNextLayout
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
// https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/core/ktx/src/main/java/androidx/core/view/View.kt | |
inline fun <T : View> T.doOnNextLayout(crossinline action: (view: T) -> Unit) { | |
addOnLayoutChangeListener(object : View.OnLayoutChangeListener { | |
override fun onLayoutChange( | |
view: View, | |
left: Int, | |
top: Int, | |
right: Int, | |
bottom: Int, | |
oldLeft: Int, | |
oldTop: Int, | |
oldRight: Int, | |
oldBottom: Int | |
) { | |
view.removeOnLayoutChangeListener(this) | |
@Suppress("UNCHECKED_CAST") | |
action(view as T) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment