Created
September 15, 2024 19:36
-
-
Save hristogochev/41c7d2f12447e3e4854705d9f5b4e5dc to your computer and use it in GitHub Desktop.
Voyager system bars workaround
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
// You can invoke LocalSystemBarsWindowInsets.current to get the correct window insets. | |
// You may need to pass this as a parameter to Scaffold if you use it, luckily Scaffold accepts custom WindowInsets. | |
val LocalSystemBarsWindowInsets = compositionLocalOf { WindowInsets(0.dp, 0.dp, 0.dp, 0.dp) } | |
// Wrap your main App function call with this one to access the system bars everywhere | |
@Composable | |
fun WithVoyagerSystemBars(content: @Composable () -> Unit) { | |
val systemBarsWindowInsets = WindowInsets.systemBars | |
CompositionLocalProvider(LocalSystemBarsWindowInsets provides systemBarsWindowInsets) { | |
content() | |
} | |
} | |
// Invoke this function in the places of Modifier.systemBarsPadding() | |
@Composable | |
fun Modifier.voyagerSystemBarsPadding() = | |
windowInsetsPadding(LocalSystemBarsWindowInsets.current) | |
// Invoke this function to access the system bars padding anywhere | |
@Composable | |
fun voyagerSystemBarsPadding() = | |
LocalSystemBarsWindowInsets.current.asPaddingValues(LocalDensity.current) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks man, good workaround.