This page provides a high-level introduction to Decompose, explaining what it is, its core architecture, and fundamental concepts. It covers the library's purpose, supported platforms, key components, and navigation models. For detailed setup instructions, see Installation and Setup. For hands-on examples, see Quick Start Guide. For in-depth coverage of specific concepts, see Core Concepts and Navigation Models.
Decompose is a Kotlin Multiplatform library for breaking down code into tree-structured, lifecycle-aware business logic components (BLoC) with routing functionality and pluggable UI. It enables sharing business logic and navigation across multiple platforms while keeping UI platform-specific.
The library provides:
Sources: README.md15 docs/index.md5
Decompose supports the following Kotlin Multiplatform targets:
| Platform | Targets |
|---|---|
| Android | android |
| JVM/Desktop | jvm |
| iOS | iosX64, iosArm64, iosSimulatorArm64 |
| tvOS | tvosArm64, tvosX64, tvosSimulatorArm64 |
| watchOS | watchosArm32, watchosArm64, watchosX64, watchosSimulatorArm64 |
| macOS | macosX64, macosArm64 |
| Web | js (IR and Legacy), wasmJs |
Sources: README.md47 docs/index.md8-15
Module Description:
ComponentContext, navigation models, and Value<T> observableChildren composable and animationsSources: deps.versions.toml1-70 README.md42-48 docs/getting-started/installation.md5-109
Description:
ComponentContext aggregates four essential services from the Essenty libraryDefaultComponentContext is the standard implementation used to create root componentsValue<T> provides multiplatform-friendly observable state (Swift/ObjC compatible)ComponentContext with isolated lifecycle and stateSources: docs/component/overview.md24-31 decompose/build.gradle.kts56-60
ComponentContext is the central abstraction in Decompose. Every component receives a ComponentContext which provides:
LifecycleOwner from EssentyStateKeeperOwner for surviving configuration changes and process deathInstanceKeeperOwner for retaining instances (like AndroidX ViewModel)BackHandlerOwner for intercepting back button eventsComponents typically receive ComponentContext via constructor and use delegation:
For detailed information, see ComponentContext.
Sources: docs/component/overview.md24-43 docs/getting-started/quick-start.md26-44
Decompose provides five predefined navigation models, each suited for different use cases:
Navigation Model Use Cases:
For detailed information, see Navigation Models.
Sources: docs/navigation/overview.md6-12 README.md55-59
Each child component is represented by a persistent configuration class that:
equals() and hashCode()@Serializable (using kotlinx-serialization)Configurations are automatically persisted using StateKeeper, allowing child components to be recreated after configuration changes or process death.
Sources: docs/navigation/overview.md19-36 docs/getting-started/quick-start.md152-158
Value<T> is Decompose's multiplatform observable state holder, providing:
subscribe/unsubscribesubscribeAsState()MutableValue<T> provides mutable variant for internal state management.
Alternative: You can use any state holder (StateFlow, LiveData, Reaktive Observable) instead of Value<T>. For detailed information, see Value and Observable State.
Sources: docs/component/overview.md190-203 docs/getting-started/quick-start.md51-82
Decompose draws strict boundaries between UI and business logic:
Benefits:
Sources: README.md24-28 docs/index.md19-22
Components have full lifecycle awareness with states matching Android's lifecycle:
| State | Description |
|---|---|
CREATED | Component exists but is not visible |
STARTED | Component is visible but not active |
RESUMED | Component is active and receiving input |
DESTROYED | Component is being destroyed |
Key Features:
CREATED (continue working in background)For detailed information, see Component Lifecycle.
Sources: README.md32-35 docs/component/overview.md3
Navigation uses persistent configurations with type-safe arguments:
Advantages:
Sources: README.md30 docs/navigation/overview.md19-36
Decompose can be used as either a library or a framework:
As a Library: Use only the features you need (e.g., just ComponentContext for lifecycle management)
As a Framework: Follow the recommended component-based architecture with navigation models
The ComponentContext interface can be extended with custom implementations, allowing:
Sources: README.md66-69 docs/index.md31-34
Characteristics:
ComponentContext and lifecycleCREATED stateSources: README.md71-82 docs/component/overview.md11-21
To begin using Decompose:
The core decompose module depends on the Essenty library, which provides:
lifecycle: Lifecycle managementstate-keeper: State preservationinstance-keeper: Instance retentionback-handler: Back button handlingThese are included as API dependencies, so no manual addition is required.
Sources: docs/getting-started/installation.md31-33 decompose/build.gradle.kts56-60
defaultComponentContext() extension function in Activity or FragmentSavedStateHandle mechanismjetpack-component-context moduleApplicationLifecycle() or manual LifecycleRegistry managementStateValue property wrapper for SwiftUI observationLifecycleController to bind lifecycle to window staterunOnUiThreadLifecycleRegistry to document visibility eventswithWebHistory for browser back/forward button integrationuseAsState hookFor detailed platform-specific setup, see Quick Start Guide.
Sources: docs/getting-started/quick-start.md304-595 docs/component/overview.md67-187
Decompose includes comprehensive sample applications demonstrating:
Sample locations:
For complete sample documentation, see Samples.
Sources: docs/samples.md1-53 README.md87-98
Sources: README.md1-114 docs/index.md1-35 docs/component/overview.md1-285 docs/navigation/overview.md1-51 docs/getting-started/installation.md1-162 deps.versions.toml1-70 mkdocs.yml1-159
Refresh this wiki