Here, i have a simple screen
IslandScreen
which is just a wrapper around a simple view. However, in order to show this screen alongside with all the other screens, I need to declare an
IslandComponent
.
@Composable
fun MainUi(component: MainComponent) {
Children(..) {
var numbers by remember { mutableStateOf(listOf(1, 2, 3)) }
when(val instance: ComponentContext = it.instance){
is IslandComponent -> IslandUi(instance)
is ShipComponent -> ShipUi(instance)
is DockComponent -> DockUi(instance)
}
}
}
This is because the
childFactory
of
MainComponent
here, requires you to provide a component
val childStack: Value<ChildStack<Config, ComponentContext>> = childStack(
source = navigation,
..
childFactory = { configuration, componentContext ->
when(configuration){
Island -> IslandComponent(componentContext) { .. }
Ship -> ShipComponent(
componentContext = componentContext,
..
)
Dock -> DockComponent(componentContext = componentContext) { .. }
}
}
)