# compose

Rizwan Minhas

09/17/2021, 9:21 AM
Hi! I am currently working on an aap with all composables (No fragment) with single activity, I am little confuse about navigation compose. If in future, I have to use fragment in this app, can I navigate from a composable to a fragment or How its work?


09/17/2021, 9:49 AM
I don't think you'll ever need fragments again. Using fragments and compose together works as a migration strategy, but when you create apps from scratch, no fragments are needed. Navigation compose can't be used to navigate to fragments as far as i know.
👍 1

Csaba Szugyiczki

09/17/2021, 9:50 AM
What if you integrate 3rd party library that is still using Fragments? Im affraid you will need to include Fragment based navigation in your app, and find a way to navigate between fragments when needed, and have a ComposeFragment or such as the host of your Composable part of your application

Albert Chang

09/17/2021, 11:13 AM
Navigation can be used to navigate to any destination as long as there is a navigator for that type, so it's totally possible to navigate to a fragment. You can do something like this:
Copy code
val navController = rememberNavController()
val activity = LocalContext.current as FragmentActivity
val fragmentNavigator = remember(activity) {
    FragmentNavigator(activity, activity.supportFragmentManager,
navController.navigatorProvider += fragmentNavigator
NavHost(navController, startDestination) {
        FragmentNavigator.Destination(provider[FragmentNavigator::class]).apply {
            route = "SomeFragment"
😮 1

Csaba Szugyiczki

09/17/2021, 12:17 PM
@Albert Chang How would you set up the Activity to support having a container and your composable next to each other?

Albert Chang

09/17/2021, 12:19 PM
That's what you need to figure out yourself depending on your use case.
I think you can alternatively add an
and create an activity which shows the fragment.
💯 1

Ian Lake

09/17/2021, 6:39 PM
Don't do any of this please. Your composable destination can inflate layouts that include fragments with
and they'll work just fine in Compose
☝️ 3
😮 1