Last active
October 5, 2023 09:12
-
-
Save atomofiron/010c57d75ef42cb972ec4fcaed584e54 to your computer and use it in GitHub Desktop.
Insets content padding
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
import androidx.compose.foundation.layout.PaddingValues | |
import androidx.compose.foundation.layout.WindowInsets | |
import androidx.compose.foundation.layout.union | |
import androidx.compose.runtime.Composable | |
import androidx.compose.ui.platform.LocalDensity | |
import androidx.compose.ui.platform.LocalLayoutDirection | |
LazyColumn(contentPadding = insetsPadding { systemBars + displayCutout }) { | |
} | |
operator fun WindowInsets.plus(other: WindowInsets) = union(other) | |
@Composable | |
inline fun insetsPadding( | |
crossinline block: @Composable WindowInsets.Companion.() -> WindowInsets, | |
): PaddingValues = WindowInsets.Companion.block().insetsPadding() | |
@Composable | |
fun WindowInsets.insetsPadding(): PaddingValues { | |
return LocalDensity.current.run { | |
val direction = LocalLayoutDirection.current | |
PaddingValues( | |
start = getLeft(this, direction).toDp(), | |
top = getTop(this).toDp(), | |
end = getRight(this, direction).toDp(), | |
bottom = getBottom(this).toDp(), | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment