Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to know when a flow is entered or exited? #542

Closed
logynapp opened this issue Nov 30, 2023 · 1 comment
Closed

Is there a way to know when a flow is entered or exited? #542

logynapp opened this issue Nov 30, 2023 · 1 comment

Comments

@logynapp
Copy link

logynapp commented Nov 30, 2023

 DestinationsNavHost(
                navGraph = NavGraphs.root,
                engine = engine,
                startRoute = NavGraphs.root.startRoute,
                dependenciesContainerBuilder = {

                    dependency(NavGraphs.root) {
                        mainViewModel
                    }


                    dependency(NavGraphs.basicInfo) {
                        org.koin.compose.getKoin().getOrCreateScope(
                            scopeId = "basicFlow",
                            qualifier = named("basicFlow")
                        ).get<BasicInfoViewModel>()
                    }

                    dependency(NavGraphs.iceNavGraph) {
                        org.koin.compose.getKoin().getOrCreateScope(
                            scopeId = "iceFlow",
                            qualifier = named("iceFlow")
                        ).get<IceInfoViewModel>()
                    }


                }
            )

what I want to achieve is to destroy the scope or to be more precise to clear the graph dependencies after exiting like to clear koin scope after navigating away from the graph.

@raamcosta
Copy link
Owner

raamcosta commented Jan 1, 2024

I assume you mean a nested graph?

This is a question for the official library, since we haven't really changed this functionality.
I believe (I did not test it) you can add a lifecycle observer to iceNavGraph like this:

navController.getBackStackEntry(NavGraphs.iceNavGraph.route).lifecycle.addObserver(
    object : DefaultLifecycleObserver {
        override fun onDestroy(owner: LifecycleOwner) {
            // should be called when iceNavGraph leaves the backstack I believe
        }
    }
)

Let me know if this works for you, I'll go ahead and close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants