Seeking help regarding Lifecycle functions are not getting called. #631
Unanswered
gulabsagevadiya
asked this question in
Q&A
Replies: 1 comment
-
This is because you are just passing |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
MyCode Declaration with dependancy. -- Issue shown at bottom
extensionsComposeJetbrains = "2.2.2-compose-experimental"
decompose= "2.2.2"
commonMain.dependencies {
//Other deps
implementation(libs.decompose)
implementation(libs.decompose.extension.compose)
}
IOS Main
fun MainViewController() = ComposeUIViewController {
val root = remember {
AppComponent(DefaultComponentContext(lifecycle = LifecycleRegistry()))
}
App(root)
}
CommonMain
@Composable
fun App(rootComponent: AppComponent) {
AppTheme {
val childStack by rootComponent.childStack.subscribeAsState()
Children(
stack = childStack,
animation = stackAnimation(fade())
) { child ->
when (val instance = child.instance) {
is AppComponent.Child.SplashScreenChild -> SplashScreenView(instance.component)
is AppComponent.Child.MainScreenChild -> MainScreenView(instance.component)
}
}
}
}
App Component Declaration
import com.arkivanov.decompose.ComponentContext
import com.arkivanov.decompose.router.stack.StackNavigation
import com.arkivanov.decompose.router.stack.childStack
import com.arkivanov.essenty.lifecycle.doOnResume
import kotlinx.serialization.Serializable
class AppComponent(
componentContext: ComponentContext
) : ComponentContext by componentContext {
private val appNavigation = StackNavigation<Configuration>()
val childStack = childStack(
source = appNavigation,
serializer = Configuration.serializer(),
initialConfiguration = Configuration.SplashScreenConfig,
handleBackButton = true,
childFactory = ::createChild
)
private fun createChild(
config: Configuration,
context: ComponentContext
): Child {
return when (config) {
Configuration.SplashScreenConfig -> Child.SplashScreenChild(SplashComponent(context))
Configuration.MainScreenConfig -> Child.MainScreenChild(MainComponent(context))
}
}
sealed class Child {
data class SplashScreenChild(val component: SplashComponent) : Child()
data class MainScreenChild(val component: MainComponent) : Child()
}
@Serializable
sealed class Configuration {
@Serializable
data object SplashScreenConfig : Configuration()
@Serializable
data object MainScreenConfig : Configuration()
}
}
Lifecycle event not working
class MainComponent(componentContext: ComponentContext): ComponentContext by componentContext {
init {
lifecycle.doOnResume {
print("OnResume Called") // This is not getting printed
}
print("Init Called") //this is gets printed
}
}
Beta Was this translation helpful? Give feedback.
All reactions