Tree composition support and runtime infrastructure for Compose Multiplatform desktop applications with declarative UI development APIs.
npx @tessl/cli install tessl/maven-org-jetbrains-compose-runtime--runtime-desktop@1.8.00
# Compose Runtime Desktop
1
2
Compose Runtime Desktop provides the core runtime infrastructure for building declarative user interfaces with Compose Multiplatform on desktop platforms (Windows, macOS, Linux). It includes tree composition support, state management, recomposition logic, and the foundational APIs needed for reactive UI development.
3
4
## Package Information
5
6
- **Package Name**: org.jetbrains.compose.runtime:runtime-desktop
7
- **Package Type**: maven
8
- **Language**: Kotlin
9
- **Target Platform**: JVM Desktop (Windows, macOS, Linux)
10
- **Installation**: Add to your `build.gradle.kts` dependencies
11
12
```kotlin
13
dependencies {
14
implementation("org.jetbrains.compose.runtime:runtime-desktop:1.8.2")
15
}
16
```
17
18
## Core Imports
19
20
```kotlin
21
import androidx.compose.runtime.*
22
```
23
24
For specific functionalities:
25
26
```kotlin
27
import androidx.compose.runtime.Composable
28
import androidx.compose.runtime.mutableStateOf
29
import androidx.compose.runtime.remember
30
import androidx.compose.runtime.LaunchedEffect
31
import androidx.compose.runtime.DisposableEffect
32
import androidx.compose.runtime.CompositionLocalProvider
33
import androidx.compose.runtime.derivedStateOf
34
import androidx.compose.runtime.produceState
35
```
36
37
## Basic Usage
38
39
```kotlin
40
import androidx.compose.runtime.*
41
42
@Composable
43
fun Counter() {
44
var count by remember { mutableStateOf(0) }
45
46
Button(
47
onClick = { count++ }
48
) {
49
Text("Count: $count")
50
}
51
}
52
53
@Composable
54
fun App() {
55
var name by remember { mutableStateOf("World") }
56
57
Column {
58
TextField(
59
value = name,
60
onValueChange = { name = it },
61
label = { Text("Name") }
62
)
63
Text("Hello, $name!")
64
}
65
}
66
```
67
68
## Architecture
69
70
Compose Runtime Desktop is built around several key components:
71
72
- **Composition Engine**: The core system that manages the composition tree and recomposition process
73
- **State System**: Reactive state management with automatic recomposition triggering
74
- **Effect System**: APIs for side effects, lifecycle management, and external system integration
75
- **Snapshot System**: Isolated state observation and mutation tracking
76
- **CompositionLocal**: Context-like implicit value propagation through the composition tree
77
78
## Capabilities
79
80
### State Management
81
82
Core state management APIs for creating reactive UI state that automatically triggers recomposition when changed.
83
84
```kotlin { .api }
85
fun <T> mutableStateOf(
86
value: T,
87
policy: SnapshotMutationPolicy<T> = structuralEqualityPolicy()
88
): MutableState<T>
89
90
interface State<out T> {
91
val value: T
92
}
93
94
interface MutableState<T> : State<T> {
95
override var value: T
96
}
97
```
98
99
[State Management](./state-management.md)
100
101
### Effects and Lifecycle
102
103
Side effect APIs for integrating with external systems, managing resources, and handling component lifecycle.
104
105
```kotlin { .api }
106
@Composable
107
fun LaunchedEffect(
108
vararg keys: Any?,
109
block: suspend CoroutineScope.() -> Unit
110
)
111
112
@Composable
113
fun DisposableEffect(
114
vararg keys: Any?,
115
effect: DisposableEffectScope.() -> DisposableEffectResult
116
)
117
118
@Composable
119
fun SideEffect(effect: () -> Unit)
120
```
121
122
[Effects and Lifecycle](./effects.md)
123
124
### Composition and Context
125
126
Core composition APIs for building composable functions and managing implicit context propagation.
127
128
```kotlin { .api }
129
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.TYPE)
130
@Retention(AnnotationRetention.BINARY)
131
annotation class Composable
132
133
@Composable
134
fun <T> remember(calculation: () -> T): T
135
136
@Composable
137
fun CompositionLocalProvider(
138
vararg values: ProvidedValue<*>,
139
content: @Composable () -> Unit
140
)
141
```
142
143
[Composition and Context](./composition.md)
144
145
### Collections and Observables
146
147
Reactive collections and observable data structures that integrate with the composition system.
148
149
```kotlin { .api }
150
fun <T> mutableStateListOf(vararg elements: T): SnapshotStateList<T>
151
152
fun <K, V> mutableStateMapOf(vararg pairs: Pair<K, V>): SnapshotStateMap<K, V>
153
154
@Composable
155
fun <T> Flow<T>.collectAsState(
156
initial: T,
157
context: CoroutineContext = EmptyCoroutineContext
158
): State<T>
159
```
160
161
[Collections and Observables](./collections.md)