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.13k stars 1.17k forks source link

Desktop: AwtWindow makes MenuBar disappear on MacOS #4114

Closed SalomonBrys closed 4 weeks ago

SalomonBrys commented 9 months ago

Describe the bug When showing an AwtWindow, after the window has closed, the MenuBar does not display anymore on Mac OS X.

Affected platforms

Versions

To Reproduce

  1. Compile and run the following code:

    import androidx.compose.foundation.layout.Column
    import androidx.compose.material.Text
    import androidx.compose.runtime.*
    import androidx.compose.ui.window.AwtWindow
    import androidx.compose.ui.window.MenuBar
    import androidx.compose.ui.window.singleWindowApplication
    import java.awt.FileDialog
    import java.awt.Frame
    import java.nio.file.Path
    import kotlin.io.path.Path
    import kotlin.io.path.absolutePathString
    
    @Composable
    fun FileLoadDialog(
        title: String,
        visible: Boolean = true,
        onResult: (result: Path?) -> Unit,
    ) {
        AwtWindow(
            visible = visible,
            create = {
                object : FileDialog(null as Frame?, title, LOAD) {
                    override fun setVisible(value: Boolean) {
                        super.setVisible(value)
                        if (value) onResult(file?.let { Path(directory, file) })
                    }
                }
            },
            dispose = FileDialog::dispose
        )
    }
    
    fun main() = singleWindowApplication {
        var load: Boolean by remember { mutableStateOf(false) }
        var path: Path? by remember { mutableStateOf(null) }
    
        FileLoadDialog(
            title = "Load a file",
            visible = load,
            onResult = {
                path = it
                load = false
            }
        )
    
        MenuBar {
            Menu("File") {
                Item("Load") { load = true }
            }
            Menu("Edit") {
                Item("Hello World!") {}
            }
        }
    
        Column {
            Text(if (load) "Loading..." else "Use File > Load to load a file")
            path?.let { Text(it.absolutePathString()) }
        }
    }
  2. In the screen's top menu, select "File" > "Load"
  3. Select any file and click "Open" (or click "Cancel")
  4. See that the top menu (that should show "File" & "Edit") has disappeared.

Note that if the application window loses focus, when the app regains focus, the menu is shown again.

okushnikov commented 3 months ago

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