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
Properties
If enabled, NavigationEventHandler use in Circuit will be disabled when no NavigationEventDispatcherOwner is present.
If enabled, presenters will be "paused" when inactive on the back stack and cache their last emitted state.