android: force navigation bar color update when system theme changes

This commit is contained in:
Harsh Shandilya 2022-02-08 01:47:46 +05:30
parent 2e503422c8
commit 2bfdab7a1a
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80

View file

@ -16,6 +16,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.painterResource
@ -72,6 +73,7 @@ fun LobstersApp(
colorScheme = decideColorScheme(LocalContext.current),
) {
ProvideWindowInsets {
val currentUiMode = LocalConfiguration.current.uiMode
val systemBarsColor = MaterialTheme.colorScheme.surfaceColorAtNavigationBarElevation()
val navItems =
listOf(
@ -89,7 +91,8 @@ fun LobstersApp(
SideEffect { systemUiController.setStatusBarColor(color = systemBarsColor) }
LaunchedEffect(currentDestination) {
// Track UI mode as a key to force a navbar color update when dark theme is toggled
LaunchedEffect(currentDestination, currentUiMode) {
val color =
if (currentDestination !in navItems.map { it.route }) {
Color.Transparent