How can i use Essenty's Lifecycle with composables (multiplatform)? Should i have disposable and launched effects and manually link the events? (Not using Decompose, only Essenty)
a
Arkadii Ivanov
05/12/2023, 6:52 PM
Yes, you will have to drive the lifecycle manually. On Android you can get the lifecycle from the activity or fragment.
Arkadii Ivanov
05/12/2023, 6:52 PM
Also not sure about navigation. The lifecycle should follow I guess, and each screen should have its own lifecycle, perhaps.
l
Lucas
05/12/2023, 7:08 PM
In this case some helper function like
Copy code
@Composable
fun lifeCycleComposable(
content: @Composable LifecycleRegistry.() -> Unit
) {
val registry = LifecycleRegistry()
LaunchedEffect(Unit){
registry.onCreate()
registry.onStart()
}
DisposableEffect(Unit){
onDispose {
registry.onDestroy()
}
}
with(registry){
content()
}
}
might be useful, right?
I'm trying to find a solution for destroying my viewmodels that i inject with koin because right now i think they're not being disposed, not sure i'm on the right track tho 😅
a
Arkadii Ivanov
05/12/2023, 7:24 PM
That's not so straightforward I guess. ViewModels are usually tied to the back stack.