Hi, hope you are all doing well. I am using `Compo...
# decompose
d
Hi, hope you are all doing well. I am using
ComponentContext
for my app navigation. What I noticed is the following I would sometimes have the following structure
Copy code
init {
        lifecycle.doOnCreate {
            Logger.e { " in on created !!!!! "}
        }
        lifecycle.doOnDestroy {
            Logger.e { " in on destroy !!!!! "}
        }
    }
inside of my components. This works well for 🤖, but for 🍎
doOnCreate
block is executed after the component has been destroyed Does someone have an idea on why this would be the case Here is a log to see that those 2 calls happen immediately one after another. Again this is just for iOS
a
d
Hey Arkadi, I was able to solve it. Followed couple of tutorials. I am using compose multiplatform wizard by jetbrains and in my
MainViewController
I had the following code:
Copy code
import androidx.compose.runtime.remember
import androidx.compose.ui.window.ComposeUIViewController
import navigation.RootComponent
import com.arkivanov.decompose.DefaultComponentContext
import com.arkivanov.essenty.lifecycle.LifecycleRegistry

fun MainViewController() = ComposeUIViewController {
    val root = remember {
  RootComponent(DefaultComponentContext(LifecycleRegistry()))
    }
    App(root)
}
I had to change
LifecycleRegistry()
to
ApplicationLifecycle()
working code is the follwing
Copy code
import androidx.compose.runtime.remember
import androidx.compose.ui.window.ComposeUIViewController
import navigation.RootComponent
import com.arkivanov.decompose.DefaultComponentContext
import com.arkivanov.decompose.lifecycle.ApplicationLifecycle

fun MainViewController() = ComposeUIViewController {
    val root = remember {
        RootComponent(DefaultComponentContext(ApplicationLifecycle()))
    }
    App(root)
}
a
Yes, I've seen this bad practice a couple of times. Not sure where it comes from!
Also please make sure you are following this guide: https://arkivanov.github.io/Decompose/component/overview/#root-componentcontext-in-jetpackjetbrains-compose It's advised to create the root component outside of Compose.
👍 1
d
I think its lackner's video
He used it there
a
Got it, thanks.
d
Thank you Arkadi :D
K 1