Jetpack Compose Immersive mode Dialog
Asked Answered
K

2

4

I have an Immersive application that's hiding the system bar using the Compose accompanist library in system navigation

val systemUiController: SystemUiController = rememberSystemUiController()

systemUiController.isStatusBarVisible = false // Status bar
systemUiController.isNavigationBarVisible = false // Navigation bar
systemUiController.isSystemBarsVisible = false // Status & Navigation bars
systemUiController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE

This works fine but when I open a new alertDialog the system navigations show up again. Looking for a compose way of preventing the system bar to appear when AlertDialog or DropdownMenu is opened.

My code is basically a scaffold with a variable that controls showing/hiding the AlertDialog from the ViewModel.

Here is a gif to make it more clear. You can see the system navigation are hidden normally but when I clicked on DropDownMenu and when the AlertDialog they appear. enter image description here

Kiangsi answered 16/11, 2022 at 18:30 Comment(2)
Is this helpful? https://mcmap.net/q/1633674/-full-screen-dialog-in-android-compose-does-not-take-full-screen-heightPorterhouse
Different issues. I actually don't want a full-screen modal. I just want to keep the system navigation hiddenKiangsi
K
3

Want to answer my own question in case anyone else is looking for a solution. Please follow the Github conversation

Kiangsi answered 1/12, 2022 at 16:14 Comment(0)
Y
0

Once inside the dialog we can get the window with DialogWindowProvider and then use the InsetsController to hide the bars. This works with compose dialogs for hiding the navigation bar. Can be extended to other bars, of course.

    Dialog(onDismissRequest = onCancel) {

    val window = (LocalView.current.parent as? DialogWindowProvider)?.window
    val view = LocalView.current
    val windowInsetsController = window?.let { WindowCompat.getInsetsController(it, view) }
    DisposableEffect(view) {
        windowInsetsController?.hide(WindowInsetsCompat.Type.navigationBars())
        onDispose {
            windowInsetsController?.hide(WindowInsetsCompat.Type.navigationBars())
        }
    }
enter code here
    ...
Yalta answered 12/9, 2024 at 9:24 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.