JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.03k stars 1.16k forks source link

Locking parent window while child window is open #1506

Closed haikalpribadi closed 2 years ago

haikalpribadi commented 2 years ago

Hi 👋🏽 I need to open a popup/modal window while a parent window open, and I've found androidx.compose.ui.window.Window to be the most appropriate library that suits our requirement. I have set alwaysOnTop = true, however, I can't stop the parent window receiving user interaction. Note that I can't make this work with androidx.compose.ui.window.Popup or androidx.compose.material.AlertDialog either -- they both allow the parent window to be interacted by the user. Is there a way to make a popup/modal window that also prohibits the user from clicking/interacting with the parent window until the modal window is closed? Particularly, is can we make it work with Window?

igordmn commented 2 years ago

You can use Dialog as described here. Dialog will block the parent window

haikalpribadi commented 2 years ago

Thanks, @igordmn - I've actually tried that before, and I've tried it again just now, following your link. It doesn't work and it's worse that than Window as I can't set alwaysOnTop = true. When the Dialog opens, I can click on the parent, and the dialog gets hidden behind the parent. At least with Window, I can set alwaysOnTop = true so the child window never gets hidden.

Is this a bug with androidx.compose.ui.windowDialog? We're not expecting it to behave this way, right?

igordmn commented 2 years ago

What JDK and OS do you use? And what version of Compose?

Last time I checked, the parent window blocks when we open Dialog on all OS'es.

This is on Windows:

https://user-images.githubusercontent.com/5963351/144047412-4d09a6c1-50fc-453f-8dc0-e1a31f6f5af2.mp4

haikalpribadi commented 2 years ago

I'm on MacOS 12.0.1 Monterey, Java 11, and Jetpack Compose 1.0.0 RC3.

Here's the constructor that I use:

androidx.compose.ui.window.Dialog(
    title = Label.CONNECT_TO_TYPEDB,
    onCloseRequest = { State.connection.showWindow = false },
    state = rememberDialogState(
        position = WindowPosition.Aligned(Alignment.Center),
        size = DpSize(WINDOW_WIDTH, WINDOW_HEIGHT)
    )
) { ... }

And here's a recording of the behaviour:

https://user-images.githubusercontent.com/567679/144094120-a671b294-c940-403f-8f51-76794e7a1b2d.mov

Looks like a bug? 🤔

igordmn commented 2 years ago

Where Dialog is used? It should be inside Window, so it will know which window should be blocked

haikalpribadi commented 2 years ago

Ah! Amazing! that was the problem indeed! I was calling my dialogs outside the parent window. 🤦🏽‍♂️ Thanks for point this out. I've solved my problem now and will close this issue. Thanks, @igordmn !

okushnikov commented 1 month ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.