Skip to content

Instantly share code, notes, and snippets.

@hristogochev
Created September 15, 2024 19:36
Show Gist options
  • Save hristogochev/41c7d2f12447e3e4854705d9f5b4e5dc to your computer and use it in GitHub Desktop.
Save hristogochev/41c7d2f12447e3e4854705d9f5b4e5dc to your computer and use it in GitHub Desktop.
Voyager system bars workaround
// 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)
@comm1x
Copy link

comm1x commented Dec 12, 2024

Thanks man, good workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment