# watercooler

Published articles for watercooler.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Jetpack Compose: A use case for view interop migration strategy

DevFeed: [Jetpack Compose: A use case for view interop migration strategy](<https://devfeed.tech/articles/jetpack-compose-a-use-case-for-view-interop-migration-strategy-24713.md>)

Original publisher: [Read original article](<https://dev.to/touchlab/jetpack-compose-a-use-case-for-view-interop-migration-strategy-4dba>)

Author: Jigar Brahmbhatt

Published: 2023-02-13T17:59:33Z

Content type: tutorial

Language: en

Sources: [Touchlab](<https://devfeed.tech/sources/touchlab.md>)

Topics: [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [migration](<https://devfeed.tech/topics/migration.md>), [Android](<https://devfeed.tech/topics/android.md>), [Testing](<https://devfeed.tech/topics/testing.md>), [ui](<https://devfeed.tech/topics/ui.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [coding](<https://devfeed.tech/tags/coding.md>), [community](<https://devfeed.tech/tags/community.md>), [compose](<https://devfeed.tech/tags/compose.md>), [development](<https://devfeed.tech/tags/development.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [inclusive](<https://devfeed.tech/tags/inclusive.md>), [interop](<https://devfeed.tech/tags/interop.md>), [jetpack](<https://devfeed.tech/tags/jetpack.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [migration](<https://devfeed.tech/tags/migration.md>), [music](<https://devfeed.tech/tags/music.md>), [software](<https://devfeed.tech/tags/software.md>), [testing](<https://devfeed.tech/tags/testing.md>), [ui-testing](<https://devfeed.tech/tags/ui-testing.md>), [watercooler](<https://devfeed.tech/tags/watercooler.md>)

### AI overview

This tutorial describes a gradual migration strategy for introducing Jetpack Compose into an Android sample app. It uses fragments hosted in Compose through AndroidViewBinding and FragmentContainerView, while moving navigation to the Compose navigation component and combining Compose UI tests with Espresso tests.

### Source excerpt

Approach Recently, we had an opportunity to redesign the sample app for an SDK we're developing. We were only redesigning one screen (home page), so we decided to introduce Jetpack Compose in the app. Based on what we read, most migration or view interop posts are about keeping Fragments and fragment navigation as they are and moving the content of the fragments into ComposeView. In fact, official docs also mention that strategy. For that, we would still have to touch other fragments in the app rather than just the home page. So it felt like more work than what we intended to do. On top of that, the sample app extensively uses PreferenceFragmentCompat for various setting screens. To move its content to ComposeView, we would have to re-create a kind of preferences screen from scratch because compose doesn't have a straight replacement for PreferenceFragment. So we decided to go with the Fragments in Compose approach. Along with that, we also moved our navigation using compose navigation component. Fragments in Compose Layout We created new layout files for each fragment with FragmentContainerView in each. <?xml version="1.0" encoding="utf-8"?> <androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragment_container_view_events" android:name="com.example.fragment.analytics.AnalyticsEventsFragment" android:layout_width="match_parent" android:layout_height="match_parent"> </androidx.fragment.app.FragmentContainerView> Composable We wrote a generic FragmentHolder composable with AndroidViewBinding. It composes an Android layout resource. The layout files we created above would have their Binding class generated that we can inflate and pass as BindingFactory in the AndroidViewBinding @Composable fun <T : ViewBinding> FragmentHolderScreen( topBarTitle: String, androidViewBindingFactory: (inflater: LayoutInflater, parent: ViewGroup, attachToParent: Boolean) -> T, onBackPress: () -> Unit = {}, androidViewBind