-
greetings, fellow decomposers. I've exhausted my knowledge trying to find an answer / creating a solution for two scenarios. let's use decompose-desktop-example as a canvas to illustrate them.
this is the first time I post a question anywhere, so please forgive me if I forgot to provide some basic information. even though I would be so very happy if I got any answers / ideas. cheers! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hello! This looks more like a Compose question. But I can share some ideas. Scenario 01 I assume that you want to change the size of the window on an event from a component. You do something as follows: class RootComponent constructor(
componentContext: ComponentContext,
private val onResizeWindow: (WindowSize) -> Unit,
) : Root, ComponentContext by componentContext {
enum class WindowSize {
NORMAL, LARGE
}
private fun makeLarge() {
onResizeWindow(WindowSize.LARGE)
}
}
// Main.kt
fun main() {
val lifecycle = LifecycleRegistry()
val windowState = WindowState()
val root =
RootComponent(
componentContext = DefaultComponentContext(lifecycle = lifecycle),
onResizeWindow = {
windowState.size = when (it) {
RootComponent.WindowSize.NORMAL -> DpSize(800.dp, 600.dp)
RootComponent.WindowSize.LARGE -> DpSize(1000.dp, 800.dp)
}
}
)
application {
LifecycleController(lifecycle, windowState)
Window(
onCloseRequest = ::exitApplication,
state = windowState,
title = "Decompose Sample"
) {
Surface(modifier = Modifier.fillMaxSize()) {
MaterialTheme {
CompositionLocalProvider(LocalScrollbarStyle provides defaultScrollbarStyle()) {
RootContent(root)
}
}
}
}
}
} Scenario 02 For a child window or a dialog you can use either a simple state data class, or the new Child Overlay navigation model. You can prefer a simple state data class for simple dialogs, and the Simple case interface SomeComponent{
val model: Value<Model> // You can also use Flow or Rx here
fun dismissDialog()
data class Model(
val dialog: Dialog?,
) {
data class Dialog(
val text: String,
)
}
}
@Composable
fun SomeComponentContent(component: SomeComponent) {
val model by component.model.subscribeAsState()
val dialog = model.dialog
if (dialog != null) {
Dialog(
onCloseRequest = component::dismissDialog,
) {
Text(text = dialog.text)
}
}
} Also see the |
Beta Was this translation helpful? Give feedback.
Hello! This looks more like a Compose question. But I can share some ideas.
Scenario 01
I assume that you want to change the size of the window on an event from a component. You do something as follows: