Browse Source

Fix multiple composable windows

If we open two windows and close the first one - the second one will jump to the position of the closed one
pull/927/head
Igor Demin 3 years ago
parent
commit
f4f53d69c8
  1. 5
      examples/notepad/src/main/kotlin/NotepadApplication.kt
  2. 5
      tutorials/Window_API_new/README.md

5
examples/notepad/src/main/kotlin/NotepadApplication.kt

@ -1,4 +1,5 @@
import androidx.compose.runtime.Composable
import androidx.compose.runtime.key
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.window.MenuScope
@ -14,7 +15,9 @@ fun NotepadApplication(state: NotepadApplicationState) {
}
for (window in state.windows) {
NotepadWindow(window)
key(window) {
NotepadWindow(window)
}
}
}

5
tutorials/Window_API_new/README.md

@ -191,6 +191,7 @@ fun getTrayIcon(): BufferedImage {
If an application has multiple windows, then it is better to put its state into a separate class and open/close window in response to `mutableStateListOf` changes (see [notepad example](https://github.com/JetBrains/compose-jb/tree/master/examples/notepad) for more complex use cases):
```kotlin
import androidx.compose.runtime.Composable
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
@ -203,7 +204,9 @@ fun main() = application {
val applicationState = remember { MyApplicationState() }
for (window in applicationState.windows) {
MyWindow(window)
key(window) {
MyWindow(window)
}
}
}

Loading…
Cancel
Save