Has anyone thought of / is working on a bridge to ...
# compose
c
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
You have to create a layout containing a
FragmentContainerView
Copy code
<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()`:
Copy code
AndroidViewBinding(MyFragmentBinding::inflate) { }
https://developer.android.com/jetpack/compose/interop/interop-apis#views-in-compose
c
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
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
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
I do not think so, you have to create a new navgraph for compose.
c
got it