Setting up Circuit¶
Setting up Circuit is a breeze! Just add the following to your build:
Installation¶
The simplest way to get up and running is with the circuit-foundation dependency, which includes all the core Circuit artifacts.
dependencies {
implementation("com.slack.circuit:circuit-foundation:<version>")
}
Setup¶
Create a Circuit instance. This controls all your common configuration, Presenter/Ui factories, etc.
val circuit = Circuit.Builder()
.addUiFactory(AddFavoritesUiFactory())
.addPresenterFactory(AddFavoritesPresenterFactory())
.build()
This configuration can be rebuilt via newBuilder() and usually would live in your program’s DI graph.
Once you have a configuration ready, the simplest way to get going with Circuit is via CircuitCompositionLocals. This exposes the configuration and a CircuitSaver to child Circuit composables. It uses the saver configured on Circuit, then a saver inherited from an outer ProvideCircuitSaver, or creates a registry-backed default when neither is available. See Saving navigation state for the available persistence strategies and explicit overrides.
CircuitCompositionLocals(circuit) {
CircuitContent(AddFavoritesScreen())
}
See the docs for CircuitContent and NavigableCircuitContent for more information.
Granular Artifacts¶
Circuit is split into a few different artifacts to allow for more granular control over your dependencies. The following table shows the available artifacts and their purpose:
| Artifact ID | Dependencies |
|---|---|
circuit-backstack |
Circuit’s backstack implementation. |
circuit-runtime |
Common runtime APIs like Screen, Navigator, etc. |
circuit-runtime-presenter |
The Presenter API, depends on circuit-runtime. |
circuit-runtime-ui |
The Ui API, depends on circuit-runtime. |
circuit-foundation |
The Circuit foundational APIs like Circuit, CircuitContent, etc. Depends on the first four. |
circuit-test |
First-party test APIs for testing navigation, state emissions, and event sinks. |
circuit-overlay |
Optional Overlay APIs. |
circuit-retained |
Optional rememberRetained() APIs. |
circuit-sharedelements |
Optional shared elements transition APIs. |
circuit-serialization |
Kotlin Multiplatform serialization for explicitly registered CircuitSaveable types. |
circuit-serialization-reflect |
Reflective serialization for CircuitSaveable types on JVM and Android. |
Platform Support¶
Circuit is a multiplatform library, but not all features are available on all platforms. The following table shows which features are available on which platforms:
- ✅ Available
- ❌ Not available
- – Not applicable
| Feature | Android | JVM | iOS | JS | Notes |
|---|---|---|---|---|---|
Backstack |
✅ | ✅ | ✅ | ✅ | |
CircuitContent |
✅ | ✅ | ✅ | ✅ | |
ContentWithOverlays |
✅ | ✅ | ✅ | ✅ | |
NavigableCircuitContent |
✅ | ✅ | ✅ | ✅ | |
Navigator |
✅ | ✅ | ✅ | ✅ | |
SaveableBackstack |
✅ | ✅ | ✅ | ✅ | Saveable is a no-op on non-android. |
rememberCircuitNavigator |
✅ | ✅ | ✅ | ✅ | |
rememberRetained |
✅ | ✅ | ✅ | ✅ | |
TestEventSink |
✅ | ✅ | ✅ | ✅ | On JS you must use asEventSinkFunction(). |