Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack Compose Navigation dialog configuration

I have a NavHost that looks something like this:

NavHost(
    navController = navController,
    startDestination = Screen.MAIN.route,
    modifier = modifier
) {
    dialog(
        Screen.LOGIN.route,
        dialogProperties = DialogProperties(
            usePlatformDefaultWidth = false,
            dismissOnBackPress = false,
            dismissOnClickOutside = false
        )
    ) { LoginScreen() }
    composable(Screen.MAIN.route) { MainScreen() }
}

For composable screen I can configure my MainActivity's windowSoftInputMode to adjustResize as well as other parameters like:

WindowCompat.setDecorFitsSystemWindows(window, false) 

But I can't seem to find a way to configure the way my dialog is displayed. It seems to use adjustPan functionality, as I can see, that when keyboard appears it pushes status bar up. How can I configure this dialog, or how can I at least change windowSoftInputMode of mentioned dialog?

EDIT I tried accessing window from context and explicitly setting required parameters, but it doesn't seem to have any effect

val context = LocalContext.current
SideEffect {
    val window = context.findWindow()!!
    WindowCompat.setDecorFitsSystemWindows(window, false)
    window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
}
like image 988
SMGhost Avatar asked Apr 16 '26 09:04

SMGhost


1 Answers

Inside the NavHost dialog you can use LocalView.current.parent as DialogWindowProvider to get the dialog window. Using this you can set softInputMode and many other properties.

val dialogWindowProvider = LocalView.current.parent as DialogWindowProvider

with(dialogWindowProvider.window) {
    setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
    // ...
}
like image 71
Chris Avatar answered Apr 19 '26 12:04

Chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!