accompanist
accompanist copied to clipboard
[System UI Controller] Request - Provide current statusBarColor, navigationBarColor
Description It would be useful if SystemUiController could be used to get current values statusBarColor, navigationBarColor. One usecase would be user moving from some main screen which has already set e.g. statusBarColor to a different screen which wants to set a different statusBar color and have possibility of reverting back to orig value
Steps to reproduce
Expected behavior
Additional context
I thought it was a bug that when navigating back the original color is not retained
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
I used this kind of solution by using DisposableEffect to toggle the original statusBarColor back when Lifecycle goes to STOP state
DisposableEffect(viewLifecycleOwner) {
val observer = LifecycleEventObserver { _, event ->
if (event == Lifecycle.Event.ON_START) {
// Toggle transparent bar
systemUiController.setStatusBarColor(Color.Black.copy(0.32f))
} else if (event == Lifecycle.Event.ON_STOP) {
// Toggle original
systemUiController.setStatusBarColor(statusBarColor)
}
}
viewLifecycleOwner.lifecycle.addObserver(observer)
onDispose {
viewLifecycleOwner.lifecycle.removeObserver(observer)
}
}
@Veeksi Thanks for your code, it works fine in my project.
Any chance to provide such function in system ui controller as an extension or optional params?
@xiaozhikang0916 Dunno about that, but I would like to see that kind of functionality straight from the library itself!
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
I second this request. I have the use case where a detail screen changes the status bar color. When the composable is disposed, I want to restore the previous color. It could look like this:
DisposableEffect(Unit) {
val prevColor = systemUiController.statusBarColor
systemUiController.setStatusBarColor(Color.White)
onDispose {
systemUiController.setStatusBarColor(prevColor)
}
}
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
Unfortunately Accompanist SystemUIController has been deprecated and won't be supported going forwards. I am closing this issue. For more information please see our update blog