Slide 66
Slide 66 text
data class InitialPadding(
val left: Int, val top: Int,
val right: Int, val bottom: Int
)
private fun recordInitialPaddingForView(view: View) = ...
fun View.doOnApplyWindowInsets(f: (View, WindowInsets, InitialPadding) -> Unit) {
// Create a snapshot of the view's padding state
val initialPadding = recordInitialPaddingForView(this)
// Set an OnApplyWindowInsetsListener which proxies to the given
// lambda, passing in the original padding state
ViewCompat.setOnApplyWindowInsetsListener(this) { v, insets ->
f(v, insets, initialPadding)
// Always return the insets, so that children can also use them
insets
}
}