https://kotlinlang.org logo
Title
c

Can

11/24/2021, 10:09 AM
Has anyone thought of / is working on a bridge to draw Fragments in Compose? This may be a very useful tool for big apps to migrate to compose on a core level
c

Csaba Kozák

11/24/2021, 10:20 AM
You have to create a layout containing a
FragmentContainerView
<androidx.fragment.app.FragmentContainerView xmlns:android="<http://schemas.android.com/apk/res/android>"
    android:id="@+id/my_fragment"
    android:name="com.example.MyFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
Than wrap it in `AndroidViewBinding()`:
AndroidViewBinding(MyFragmentBinding::inflate) { }
https://developer.android.com/jetpack/compose/interop/interop-apis#views-in-compose
c

Can

11/24/2021, 10:29 AM
Interesting
I’m not sure this satisfies all needs though you would need to have a mix of fragments and compose views (Compose displays Fragments and Fragments display Compose Views). Including backstack handling
c

Csaba Kozák

11/24/2021, 10:37 AM
I am not sure what you mean. You can add these wrapped Fragments to the same compose navgraph as your normal compose screens, than you can navigate between them easily, including back stack. This is actually working in our app.
c

Can

11/24/2021, 10:39 AM
That’s actually awesome, thank you for that input. Is the Compose NavGraph compatible with the Fragment navGraph implementation? i.e. can Fragments modify the
rememberNavController
which is createed in Compose?
c

Csaba Kozák

11/24/2021, 10:42 AM
I do not think so, you have to create a new navgraph for compose.
c

Can

11/24/2021, 10:45 AM
got it