Storytale is a Compose Multiplatform library designed to help developers more easily test their written @Composable components. It offers convenient and concise APIs, along with a well-designed editor to simplify the testing process.
Since Storytale is still in the early stages of development, the api is marked as unstable, but this section will also show you how to use Storytale
to write code for your components, so let's get started! π
using Version Catalog
libs.versions.toml
[versions]
storytale = "1.0"
[plugins]
storytale = { id = "org.jetbrains.compose.storytale", version.ref = "storytale" }
build.gradle.kts
root level
plugins {
alias(libs.plugins.storytale) apply false
}
build.gradle.kts
app level
plugins {
alias(libs.plugins.storytale)
}
Storytale is published on Maven Central, so if you haven't defined the repository yet, please do it:
repositories {
mavenCentral()
}
Storytale can be used for Compose Multiplatform projects. To start using the Storytale API, you need to define a sourceset for the component you want to test (for example, it might only be used for Android/iOS
platforms, or it could be common for all platforms).
In your app's 'src' folder, go to New -> Directory:
Now, your project structure will look like this:
βββ src/
βββ androidMain
βββ commonMain
βββ xxxxxStories/
β βββ kotlin
βββ desktopMain
Let's try to write a simple function in commonMain
:
commonMain/PrimaryButton.kt
@Composable
fun PrimaryButton(onClick: () -> Unit, enabled: Boolean = true) {
Button(onClick = onClick, enabled = enabled) {
Text("Click me!")
}
}
commonStories/kotlin/PrimaryButton.story.kt
import org.jetbrains.compose.storytale.story
val `PrimaryButton default state` by story {
PrimaryButton(onClick = {})
}
Next, let's run the desktopStoriesRun
command, you can find it in the project/Storytale
section on the right side of the Gradle panel.
If you can't find all Gradle tasks containing Storytale
after syncing, check if this option is enabled:
settings->Experimental
For your first build of Storytale, you need to comment out alias(libs.plugins.storytale)
in the build.gradle.kts
file under the examples module
(if itβs not already commented). Then, sync Gradle.
Once the sync is successful, uncomment it and sync again, then run ./gradlew publishToMavenLocal
.
At this point, if you see these Storytale Gradle tasks
, it means youβve successfully set up the project and can start contributing! :)
Before running XXXXStoryRun
, you need to run ./gradlew publishToMavenLocal
to deploy the latest changes if you've modified any part of the code (except for examples module)
.
βββ modules/
βββ compiler-plugin
βββ gallery
βββ gradle-plugin
βββ runtime
Includes the entry point of the Storytale compiler plugin and its related features.
The gallery represents the final, fully functional multi-platform application that is produced by Storytale.
All aspects related to building Storytale, including various Gradle tasks, generating Storytale apps for different platforms, and so on.
The runtime module is designed to provide developers with essential APIs during the coding process