google / accompanist

A collection of extension libraries for Jetpack Compose
https://google.github.io/accompanist
Apache License 2.0
7.38k stars 596 forks source link

[System UI Controller] Cannot hide the system navigation when Dialog appears #1682

Closed GCZeng closed 1 year ago

GCZeng commented 1 year ago

Describe the bug

I have a full screen application for a kiosk and when the dialogs show up the system navigation appears as well.

To Reproduce

Open a dialog and the system navigations pop up. code:

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            FullScreenDialogDemoTheme {
                // A surface container using the 'background' color from the theme
                Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colors.background) {
                    var showDialog by remember { mutableStateOf(false) }
                    val parentSystemUiController = rememberSystemUiController()
                    parentSystemUiController.isSystemBarsVisible = false
                    parentSystemUiController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE

                    Box {
                        Button(onClick = { showDialog = true }) {
                            Text(text = "Open Dialog")
                        }
                    }

                    if (showDialog) {
                        AboutDialog(onDismiss = { showDialog = !showDialog })
                    }
                }
            }
        }
    }
}

@Composable
fun AboutDialog(
    confirmText: String = "OK",
    onDismiss: () -> Unit = {},
) {
    AlertDialog(
        onDismissRequest = { onDismiss() },
        confirmButton = {
            val dialogSystemUiController = rememberSystemUiController()
            dialogSystemUiController.isStatusBarVisible = false // Status bar
            dialogSystemUiController.isNavigationBarVisible = false // Navigation bar
            dialogSystemUiController.isSystemBarsVisible = false // Status & Navigation bars
            dialogSystemUiController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
            TextButton(onClick = onDismiss) { Text(text = confirmText) }
        },
        title = {
            Text(
                text = "title",
                fontWeight = FontWeight.Bold,
                style = MaterialTheme.typography.h5
            )
        },
        text = {
            Column() {
                Text(
                    text = "about",
                    color = Color.Black,
                    style = MaterialTheme.typography.h6
                )
            }
        },
        modifier = Modifier
            .width(600.dp)
            .clip(RoundedCornerShape(12.dp)),
    )
}

Expected behavior

For the system navigations to stay hidden

Screenshots?

device-2023-07-19-173430 image

Environment:

bentrengrove commented 1 year ago

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