hello. I am trying use the child slot navigation. ...
# decompose
f
hello. I am trying use the child slot navigation.
Copy code
interface RootComponent {
    val childSlot: Value<ChildSlot<*, Child>>

    sealed interface Child {
        data class Main(val component: MainComponent) : Child
        data class Scan(val component: ScanComponent) : Child
    }

}


private val navigation = SlotNavigation<Configuration>()

private val slot =
        childSlot(
            source = navigation,
            // initialConfiguration = ??????,
            handleBackButton = true,
            childFactory = ::createChild,
        )

override val childSlot: Value<ChildSlot<*, RootComponent.Child>> = slot

private fun createChild(
    configuration: Configuration,
    componentContext: ComponentContext,
) : RootComponent.Child =
    when (configuration) {
        Configuration.Main -> RootComponent.Child.Main(mainComponent(componentContext))
        Configuration.Scan -> RootComponent.Child.Scan(scanComponent(componentContext))
    }

private sealed interface Configuration : Parcelable {
    @Parcelize
    data object Main : Configuration

    @Parcelize
    data object Scan : Configuration
}
I unable to create a childSlot with initialConfiguration. Can you help me???
I had a misunderstood about childSlot. Child slot is just for one child and not to more.
a
initialConfiguration is a lambda returning either a configuration or null. Child Slot allows only one child at a time, or none.
f
ahhh ok, tks
just one more question: I am trying use a ChildStack more one ChildSlot in a same component: is it possible???
a
Yes, absolutely
f
okk, the answer is yes to me as well. dunno why I asked. btw, I unable to add the view of slot component , for example:
Copy code
@Composable
internal fun RootContent(rootComponent: RootComponent) {

   // I want to add the view of slot here, but I am not able to do that (shame on me)

    Children(
        stack = rootComponent.childStack,
    ) {
        when (val child = it.instance) {
            is Main -> MainContent(child.component)
            is Scan -> ScanContent(child.component)
        }
    }
}
I checked there is not a composable function like children : https://github.com/arkivanov/Decompose/issues/395
a
You don't need any support from Decompose for Child Slot. Just subscribe using
subscribeAsState
extension function. See https://github.com/arkivanov/Decompose/blob/cb80388011d3334d2b2b01938513c364419cc8[…]/com/arkivanov/sample/shared/counters/counter/CounterContent.kt
f
works fine, tks again I was trying like that:
Copy code
val toolbar = rootComponent.toolbar.value.child
if ( toolbar is Child.Created) {
    ToolbarTemp(toolbar.instance)
}
but the following is the correct
Copy code
val toolbarSlot by rootComponent.toolbar.subscribeAsState()
        toolbarSlot.child?.instance?.also {
            ToolbarTemp(it)
        }
decompose 1
210 Views