Composable Window API breaking changes in 0.5.0-bu...
# compose-desktop
i
Composable Window API breaking changes in 0.5.0-build226: 1.
Window(onCloseRequest=)
is required parameter now 2.
WindowState.isMaximized
,
WindowState.isFullscreen
are merged to
WindowState.placement { Floating, Maximized, Fullscreen }
3.
WindowPosition
is sealed class
{ PlatformDefault, Aligned, Absolute }
,
initialAlignment
removed from Window/Dialog
👍 4
âś… 10
Window(onCloseRequest=)
 is required parameter now
We have only one case where omitting that parameter is useful - a single-window application. In the other cases if we omit this parameter - we will have state desynchronization:
Copy code
var isSecondWindowOpen = ...
if (isSecondWindowOpen) {
 // when we close the window, we change internal isOpen state, but don't change   isSecondWindowOpen state. And because we don't change isSecondWindowOpen, we can't reopen the window
  Window {

  }
}
For the single-window case we created a special function
exitApplication
, that closes all windows/trays and cancels `LaunchedEffect`'s inside
application
block. An alternative to
exitApplication
- is to use your own state:
Copy code
fun main() = application {
  var isApplicationOpen by remember { mutableStateOf(true) }
  if (isApplicationOpen) {
     Window(onCloseRequest = { isApplicationOpen = false }) { ... }
     Tray(...)
     LaunchedEffect(Unit) { ... }
  }
}