Slide 121
Slide 121 text
https:/
/gist.github.com/chris-horner/4718402eb6ebd4d89b63491245a359ff
fun View.updatePaddingWithInsets(left: Boolean = false,
top: Boolean = false,
right: Boolean = false,
bottom: Boolean = false) {
doOnApplyWindowInsets { insets, padding ->
updatePadding(left = if (left) padding.left + insets.systemWindowInsetLeft else padding.left,
top = if (top) padding.top + insets.systemWindowInsetTop else padding.top,
right = if (right) padding.right + insets.systemWindowInsetRight else padding.right,
bottom = if (bottom) padding.bottom + insets.systemWindowInsetBottom else padding.bottom)
}
}
inline fun View.doOnApplyWindowInsets(crossinline block: (insets: WindowInsets, padding: Rect) -> Unit) {
// Create a snapshot of padding.
val initialPadding = Rect(paddingLeft, paddingTop, paddingRight, paddingBottom)
// Set an actual OnApplyWindowInsetsListener which proxies to the given lambda, also passing in the original padding.
chris-horner / InsetUtils.kt