l

    Luke

    1 year ago
    Is it possible to mix fragment and composable destination in a
    NavHost
    ? I want to add a fragment that I don’t own, from a library, as a destination. I tried:
    NavHost(
        navController = navController,
        startDestination = route,
    ) {
        composable(...) { ... )
        fragment<LibraryFragment>(id)
    }
    But when I run, the activity crashes with
    Could not find Navigator with name "fragment". You must call NavController.addNavigator() for each navigation type.
    If it’s not possible, is there another way to add a fragment to composition?
    i

    Ian Lake

    1 year ago
    This is not possible via Navigation Compose, no.
    I don't know what the latest is on adding a fragment within a Compose hierarchy is (to be somewhat honest, I'd be surprised if it works consistently), but I would imagine it would involve an
    AndroidView
    or
    AndroidViewBindin
    (if you want to inflate a
    FragmentContainerView
    with an
    android:name
    ) ala: https://developer.android.com/jetpack/compose/interop#views-in-compose
    l

    Luke

    1 year ago
    I’ll try the view binding approach. Thanks for your hindsight
    i

    Ian Lake

    1 year ago
    If you look at apps like JetChat, it generally uses fragments as the outer layer in a hybrid app, but with each screen (i.e., each fragment) implementing its UI in Compose, rather than implementing everything in Compose then adding fragments, etc. within that hierarchy
    Definitely do file bugs against Compose if you run into issues with that approach though - ideally, both approaches work
    a

    allan.conda

    1 year ago
    I tried AndroidView with a Fragment before, there’s still a crash when you’re using hardware keyboard in an emulator though it got fixed recentlyhttps://issuetracker.google.com/issues/165034731 Will be available in the next release