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
This commit is contained in:
Igor Demin
2021-07-21 15:23:19 +03:00
parent 581b5f0b0a
commit f4f53d69c8
2 changed files with 8 additions and 2 deletions

View File

@@ -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)
}
}
}

View File

@@ -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)
}
}
}