Alvin Dizon
05/22/2023, 8:05 AMDisposableEffect
like this on my root Composables for A & B:
val systemUiController = rememberSystemUiController()
DisposableEffect(systemUiController) {
systemUiController.setStatusBarColor(SpecificColor)
onDispose {
systemUiController.setStatusBarColor(OriginalColor)
}
}
When entering Composable A, the status bar color is successfully set to the specific color, but when entering B, the original status bar color returns. I imagine it's because of the onDispose
callback, but on my root composable for B, I have the same piece of code that sets the status bar color. Is there any other way of achieving this?Joel Denke
05/22/2023, 12:27 PMif (!LocalInspectionMode.current) {
SideEffect {
val window = (view.context as Activity).window
window.statusBarColor = colorScheme.primary.toArgb()
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
}
}
And then using that code inside theme making sure only applies once.Alvin Dizon
05/22/2023, 2:37 PMMaterialTheme
so that I can at least change the status bar color without resorting to hacks. I'm also using ComposeViews inside FragmentsJoel Denke
05/22/2023, 3:18 PM