Jump to:
[Introduction](#Introduction) |
[Usage](#Usage) |
[Samples](#Samples) |
[FAQ](#FAQ) |
[License](#License)
## Introduction
The entrypoint to Mosaic is the `runMosaic` function.
The lambda passed to this function is responsible for both output and performing work.
```kotlin
suspend fun main() = runMosaic {
Text("The count is: 0")
}
```
To change the output dynamically we can use local properties to hold state.
Let's update our counter to actually count to 20.
```kotlin
suspend fun main() = runMosaic {
var count by remember { mutableIntStateOf(0) }
Text("The count is: $count")
LaunchedEffect(Unit) {
for (i in 1..20) {
delay(250)
count = i
}
}
}
```
(Note: You may need to add imports for `androidx.compose.runtime.getValue` and `import androidx.compose.runtime.setValue` manually.)
That is the most basic sample of Mosaic.
From there, the limit is only your imagination.
_(Note: graphs in the above have rendering problems due to asciinema/agg which do not appear in the real output)_
## Usage
Mosaic is a library for Compose, and it relies on JetBrains' Kotlin Compose plugin to be present for use.
Any module which wants to call `runMosaic` or define `@Composable` functions for use with Mosaic must have this plugin applied.
For more information, see [the JetBrains Compose compiler documentation](https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-compiler.html).
Mosaic itself can then be added like any other dependency:
```groovy
dependencies {
implementation("com.jakewharton.mosaic:mosaic-runtime:0.18.0")
}
```
Documentation is available at [jakewharton.github.io/mosaic/docs/0.x/](https://jakewharton.github.io/mosaic/docs/0.x/).
```groovy repository { mavenCentral() maven { url 'https://central.sonatype.com/repository/maven-snapshots/' } } dependencies { implementation("com.jakewharton.mosaic:mosaic-runtime:0.19.0-SNAPSHOT") } ``` Snapshot documentation is available at [jakewharton.github.io/mosaic/docs/latest/](https://jakewharton.github.io/mosaic/docs/latest/).