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. 3
      examples/notepad/src/main/kotlin/NotepadApplication.kt
  2. 3
      tutorials/Window_API_new/README.md

3
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,9 +15,11 @@ fun NotepadApplication(state: NotepadApplicationState) {
}
for (window in state.windows) {
key(window) {
NotepadWindow(window)
}
}
}
@OptIn(ExperimentalComposeUiApi::class)
@Composable

3
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,9 +204,11 @@ fun main() = application {
val applicationState = remember { MyApplicationState() }
for (window in applicationState.windows) {
key(window) {
MyWindow(window)
}
}
}
@OptIn(ExperimentalComposeUiApi::class)
@Composable

Loading…
Cancel
Save