electrolobzik
08/21/2024, 3:19 PMfun LifecycleRegistry(): LifecycleRegistry = LifecycleRegistry(initialState = Lifecycle.State.INITIALIZED)
and then pass it to the child component via fun <Ctx : GenericComponentContext<Ctx>> Ctx.childContext(key: String, lifecycle: Lifecycle? = null): Ctx
I get this error when I try to destroy the component:
"The lifecycle of a child ComponentContext must never be destroyed manually."
I am just calling onDestroy
on the LifecycleRegistry. What is the correct way to create own lifecycle and put it into DESTROYED
state? What I am trying to achieve is to get child component removed correctly from the stateKeeper
when I actually have destroyed it.Arkadii Ivanov
08/21/2024, 10:54 PMelectrolobzik
08/22/2024, 1:22 PMArkadii Ivanov
08/22/2024, 1:36 PMchildContext
. The passed lifecycle is expected to be never destroyed. Please see the docs: https://arkivanov.github.io/Decompose/component/child-components/#adding-a-child-component-manually
But permanent child components must never be destroyed manually.If you need to dynamically create and destroy a child component, then you need navigation. You can try Child Slot.
electrolobzik
08/22/2024, 1:45 PMelectrolobzik
08/22/2024, 1:48 PMelectrolobzik
08/22/2024, 1:48 PMArkadii Ivanov
08/22/2024, 1:52 PMelectrolobzik
08/22/2024, 2:35 PMprivate val selfieComponentDisposableDelegate = disposableManually<SelfieRootComponent>()
private var selfieTakerComponent by selfieComponentDisposableDelegate
and inside the childFactory:
Configuration.ReplaceSelfie -> {
createReplaceSelfieComponent(childComponentContext).also { createdComponent ->
selfieComponentDisposableDelegate.restore()
selfieTakerComponent = createdComponent
childComponentContext.lifecycle.doOnDestroy {
selfieComponentDisposableDelegate.dispose()
}
}
Child.ReplaceSelfie(selfieTakerComponent)
}
In such way I have not nullable var which is easy to access and it is recreated along with navigation. (Accessing to it between disposal and recreation throws exception)electrolobzik
08/22/2024, 2:36 PMArkadii Ivanov
08/22/2024, 2:36 PMArkadii Ivanov
08/22/2024, 2:37 PMelectrolobzik
08/22/2024, 2:42 PMArkadii Ivanov
08/22/2024, 2:46 PMelectrolobzik
08/22/2024, 2:53 PMArkadii Ivanov
08/22/2024, 3:11 PM