Circuit

Circuit adapts presenter factories to their corresponding ui factories using screens. Create instances using the Builder and create new CircuitContent with it to run presenter/UI pairings.

Construction

Construction of Circuit instances is done using the Builder.

val circuit = Circuit.Builder()
.addUiFactory(AddFavoritesUiFactory())
.addPresenterFactory(AddFavoritesPresenterFactory())
.build()

Usage

These instances can then be used with the composable CircuitContent functions to run presenter/UI pairings for individual screens.

Circuit instances are consumed within these composable functions via the CircuitCompositionLocals CompositionLocalProvider.

CircuitCompositionLocals(circuit) {
CircuitContent(AddFavoritesScreen())
}

If using navigation, use NavigableCircuitContent instead.

val backStack = rememberSaveableBackStack(root = HomeScreen)
val navigator = rememberCircuitNavigator(backstack, ::onBackPressed)
CircuitCompositionLocals(circuit) {
NavigableCircuitContent(navigator, backstack)
}

See also

NavigableCircuitContent

Types

Link copied to clipboard
class Builder

Properties

Link copied to clipboard
val onUnavailableContent: @Composable (screen: Screen, modifier: Modifier) -> Unit
Link copied to clipboard

If enabled, presenters will be "paused" when inactive on the back stack and cache their last emitted state.

Functions

Link copied to clipboard
Link copied to clipboard
fun nextPresenter(skipPast: Presenter.Factory?, screen: Screen, navigator: Navigator, context: CircuitContext): Presenter<*>?
Link copied to clipboard
fun nextUi(skipPast: Ui.Factory?, screen: Screen, context: CircuitContext): Ui<*>?
Link copied to clipboard
fun presenter(screen: Screen, navigator: Navigator, context: CircuitContext = CircuitContext(null).also { it.circuit = this }): Presenter<*>?
Link copied to clipboard
fun ui(screen: Screen, context: CircuitContext = CircuitContext(null).also { it.circuit = this }): Ui<*>?