<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Amit</title>
    <description>The latest articles on DEV Community by Amit (@being01amit).</description>
    <link>https://dev.to/being01amit</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4254837%2F47d11fe1-d8f8-42ae-bdec-412d90117209.jpg</url>
      <title>DEV Community: Amit</title>
      <link>https://dev.to/being01amit</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/being01amit"/>
    <language>en</language>
    <item>
      <title>Migration Debt: From Fragments/Views to Compose</title>
      <dc:creator>Amit</dc:creator>
      <pubDate>Fri, 20 Nov 2026 04:55:30 +0000</pubDate>
      <link>https://dev.to/being01amit/migration-debt-from-fragmentsviews-to-compose-501c</link>
      <guid>https://dev.to/being01amit/migration-debt-from-fragmentsviews-to-compose-501c</guid>
      <description>&lt;h2&gt;
  
  
  The hybrid reality nobody puts on the roadmap
&lt;/h2&gt;

&lt;p&gt;“We’re moving to Compose.”&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdgtej9wfs8xtw26pqxr5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdgtej9wfs8xtw26pqxr5.png" alt=" " width="800" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When a team says this, most people picture the same thing: XML files deleted, Fragments gone, every screen rebuilt as a clean composable. A few sprints of hard work, then a modern codebase.&lt;/p&gt;

&lt;p&gt;That isn’t what happens.&lt;/p&gt;

&lt;p&gt;What happens is that a Fragment starts returning a ComposeView. A ComposeView shows up in the middle of a LinearLayout. A new feature ships as its own Activity because nobody wants to touch the main navigation host. Months later, the app has more ways to render a screen than it had before the migration started.&lt;/p&gt;

&lt;p&gt;None of that is failure. It’s what migration looks like. But it has a cost, and that cost has a name.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Part Nobody Talks About
&lt;/h2&gt;

&lt;p&gt;A production app can’t stop shipping while it changes UI toolkits. Features still land, bugs still get fixed, releases still go out. So the old and new systems have to run side by side, often for a long time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fflxln5eit0rhnuows2je.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fflxln5eit0rhnuows2je.png" alt=" " width="799" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Even the official guidance assumes this. Google recommends an incremental migration in which Compose and Views co-exist in your codebase until the app is fully in Compose.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The word to notice is until. The co-existence period isn’t a short handover. It’s an architecture you will operate, debug, and onboard people into.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Migration debt is the complexity created by keeping two UI systems alive at once: two lifecycles to respect, two ways to observe state, two navigation models, often two DI setups, and design tokens defined twice. It’s not the same as the legacy debt you started with. It’s new debt, and the migration creates it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here is the argument of this article:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Compose migration is not mainly a UI rewrite. It’s a long-running architectural transition. The hard part is managing the boundary between old and new UI while keeping state, navigation, and ownership understandable.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Compose Still Makes Sense
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;If migration creates debt, why do it at all?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Because the value of Compose shows up early, well before the last Fragment is gone.&lt;/p&gt;

&lt;p&gt;Think about a screen with multi-select lists, quantity steppers, highlighted items, and loading, empty, and error variants. In the View world, that logic is spread across adapters, view holders, and notifyItemChanged calls. In Compose, it collapses into one immutable UiState data class and a function that renders it. You can read the whole screen's state in one place.&lt;/p&gt;

&lt;p&gt;That is where Compose tends to arrive first: where state complexity is highest. New, state-heavy features. Selection-heavy lists. UI with many visual variants.&lt;/p&gt;

&lt;p&gt;There’s a second payoff that’s easy to miss. A stateless composable, one that takes state and a set of callbacks, can be tested with createComposeRule without its legacy host. That matters a lot when the host is a large Activity that can't easily be launched in a test.&lt;/p&gt;

&lt;p&gt;And every new screen written in Compose is one less screen you’ll have to migrate later. You stop adding to the legacy surface, even if you can’t shrink it yet.&lt;/p&gt;

&lt;p&gt;What Compose doesn’t do is fix your architecture. A tangled Fragment with a declarative renderer is still a tangled Fragment.&lt;/p&gt;

&lt;h2&gt;
  
  
  The First Trap: Trying to Migrate Everything
&lt;/h2&gt;

&lt;p&gt;A big-bang rewrite means rebuilding navigation, lifecycle handling, DI, and every screen’s behaviour at once, while matching years of edge cases nobody wrote down.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fna3tjr02j8tpncasq1kf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fna3tjr02j8tpncasq1kf.png" alt=" " width="800" height="343"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Separate two things that often get mixed up:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Replacing UI means swapping XML and adapters for composables.&lt;/li&gt;
&lt;li&gt;Migrating architecture means moving state ownership, navigation, and dependency wiring.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can do the first without the second, and that’s usually the right first move. Replacing the renderer while the Fragment’s public API stays the same means the host Activity doesn’t change, the back stack doesn’t change, and the release risk stays small.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Just don’t confuse that first step with being finished.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Start Where the Boundary Is Clear
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Where should I start?” has no universal answer, but good candidates share one trait: the boundary between old and new is easy to draw.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft0vhqh2vl08w8kp28h3u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft0vhqh2vl08w8kp28h3u.png" alt=" " width="800" height="343"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;New features are the cleanest boundary. There’s no legacy behaviour to match, so you get Compose experience, a shared theme, and DI patterns without risking existing flows. The catch is that new features don’t reduce existing debt. A team can spend a long time writing new Compose before a single existing screen moves.&lt;/p&gt;

&lt;p&gt;Leaf UI inside existing screens comes next: a banner, a card, a section added to a dense XML screen. Drop in a ComposeView and the parent layout stays untouched. The official docs call this route the bottom-up approach.&lt;/p&gt;

&lt;p&gt;Screens with manageable state are good for full migrations, especially when the state can be described as one data class and the screen talks to the outside world through a few callbacks.&lt;/p&gt;

&lt;p&gt;Navigation hosts go last. If one Activity manages dozens of Fragment transactions and a back-press handler full of is SomeFragment checks, every screen depends on it. Touch it when nothing else is left.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A useful test: can I introduce Compose here without rewriting business logic or navigation? If yes, it’s a candidate. If not, it’s a later project.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Compose Inside a Fragment Is Not a Failure
&lt;/h2&gt;

&lt;p&gt;This is the pattern you’ll use most, and it’s often treated as a temporary embarrassment. It shouldn’t be.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F256178og8pyidy2g3k8d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F256178og8pyidy2g3k8d.png" alt=" " width="800" height="337"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Fragment keeps the jobs it’s already good at in a legacy app: lifecycle, arguments, and its place in the FragmentManager back stack. Compose becomes the renderer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProfileFragment&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Fragment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;UserViewModel&lt;/span&gt; &lt;span class="n"&gt;by&lt;/span&gt; &lt;span class="nf"&gt;viewModels&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onCreateView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;inflater&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;LayoutInflater&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;container&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ViewGroup&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;savedInstanceState&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Bundle&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;View&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ComposeView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;requireContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;apply&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;setViewCompositionStrategy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nc"&gt;ViewCompositionStrategy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DisposeOnViewTreeLifecycleDestroyed&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;setContent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="n"&gt;by&lt;/span&gt; &lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uiState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collectAsStateWithLifecycle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nc"&gt;ProfileScreen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;onEditClick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;onEditClick&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Two details matter here.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;First, the ViewCompositionStrategy. The default disposes of the composition when the ComposeView detaches from the window, and the docs warn that this can cause state loss when you’re adding Compose incrementally. For a ComposeView in a Fragment, the recommended strategy is DisposeOnViewTreeLifecycleDestroyed. It’s one line, and it’s easy to forget when different people write each host at different times. Make it a review checklist item.&lt;/p&gt;

&lt;p&gt;Second, the navigation. The official guidance says to keep using Fragment-based navigation until every destination is a composable, and only then move to Navigation Compose. So a Fragment hosting Compose isn’t a half-done job. For a hybrid app, it’s the recommended shape.&lt;/p&gt;

&lt;p&gt;When a new Compose flow needs its own internal navigation and the existing host is too big to touch, a separate Activity with its own NavHost is a reasonable firewall: it gives you a clean lifecycle, clean back handling, and no merging with the legacy back stack. The cost is that your app now has two navigation worlds that can’t see each other.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Real Migration: Who Owns the State?
&lt;/h2&gt;

&lt;p&gt;Here’s the trap that looks like success. The XML is gone, the screen is a clean stateless composable, and the tests pass. But the Fragment still looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProfileFragment&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Fragment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;_uiState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MutableStateFlow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;UiState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;selectedTab&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;isEditing&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;draftName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;pushState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_uiState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;UiState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;selectedTab&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;isEditing&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;draftName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onTabSelected&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;selectedTab&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;
        &lt;span class="nf"&gt;pushState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The rendering is declarative. The ownership is still imperative and scoped to the Fragment. Every mutation has to remember to call pushState(). The state isn't in a SavedStateHandle, so after process death it's whatever can be rebuilt from storage.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffwngabe86tgtk9uhghwj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffwngabe86tgtk9uhghwj.png" alt=" " width="800" height="338"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The bill arrives in your tests. If the Fragment can’t be attached outside its real host Activity, tests end up re-creating the Fragment’s observer wiring by hand, and production code picks up test-only hooks: an injectable ViewModel field here, an overridable dialog callback there. Test seams leaking into production code are a clear sign that the state holder never moved.&lt;/p&gt;

&lt;p&gt;The fix is a second, separate deliverable: move the state and its handlers into a ViewModel, and let the Fragment become a thin host. Plan it as its own ticket. If it’s hidden inside “migrate the screen”, it will be the part that quietly gets dropped.&lt;/p&gt;

&lt;h2&gt;
  
  
  Islands get two parents
&lt;/h2&gt;

&lt;p&gt;Embedded ComposeView Islands have their own ownership problem:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="n"&gt;binding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bannerCompose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setContent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="n"&gt;by&lt;/span&gt; &lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;banners&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collectAsStateWithLifecycle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isNotEmpty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;PromoBanner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// ...somewhere else in the Fragment&lt;/span&gt;
&lt;span class="n"&gt;binding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bannerCompose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isVisible&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isPremium&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now visibility is decided in two places, by two systems, with different rules. Add a third check in a role-update method, and nobody can say for sure why the banner is hidden. Pick one owner. A showBanner value derived in the ViewModel works well.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fek0n57lkin3azxeqmn5l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fek0n57lkin3azxeqmn5l.png" alt=" " width="800" height="338"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A quieter version of the same bug: a composable that reads a global or a data-binding variable directly. Those aren’t snapshot state, so Compose won’t recompose when they change. The UI only looks correct because something else happened to trigger recomposition.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let storage do the coordinating
&lt;/h2&gt;

&lt;p&gt;When a legacy screen and a Compose screen need the same data, the instinct is to share a ViewModel. Often a better option is a persisted, observable source of truth: a Room table or DataStore exposed Flow from a single repository. Each screen observes it on its own terms, and they stay consistent without knowing about each other.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft6wn5fy3sha3yqshvigh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft6wn5fy3sha3yqshvigh.png" alt=" " width="800" height="343"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It isn’t free. You can end up with several ViewModel instances wrapping the same stream with different setups, and someone will eventually read .value from an async StateFlow and get stale data. But it decouples screens that migrate at different speeds better than a shared in-memory object does.&lt;/p&gt;

&lt;h2&gt;
  
  
  Paying Down the Debt
&lt;/h2&gt;

&lt;p&gt;Some migration debt is temporary by design. Some become structural if nobody tracks them. The usual suspects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dead legacy UI. The adapters and layouts a screen used to need are still in the repo and referenced by nothing, sometimes after a commit message said they were removed. “Migrated” doesn’t mean “deleted”.&lt;/li&gt;
&lt;li&gt;Parallel implementations. A routing switch that sends some users to the new screen and others to the old one is a sound strangler pattern. It also means two UIs to keep in sync until the switch goes away.&lt;/li&gt;
&lt;li&gt;Two DI worlds. Hilt in new code and a hand-rolled service locator in old code, joined by @EntryPoint interfaces so legacy classes can reach Hilt-provided dependencies. That's a sensible bridge, but it's a bridge, not a destination.&lt;/li&gt;
&lt;li&gt;Duplicated tokens. Compose themes don’t read XML themes, so colours and fonts end up being defined twice. Extract them into one source early, before they drift.&lt;/li&gt;
&lt;li&gt;Mixed lifecycle conventions. observe(requireActivity()) next to viewLifecycleOwner, and a ComposeView with a disposal strategy next to one without. Each is small. Together, they're why hybrid bugs are hard to reproduce.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Feytb963hrx41xx4235bp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Feytb963hrx41xx4235bp.png" alt=" " width="800" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;None of this means the hybrid approach was wrong. It’s the cost of staying shippable. The mistake is pretending it isn’t there.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The Takeaway
&lt;/h2&gt;

&lt;p&gt;Hybrid isn’t a phase you pass through quickly. It’s an architecture, and it needs rules like any other: which ViewCompositionStrategy Each host uses, who owns visibility for each island, how one-off events cross into the legacy host, where tokens live, and when nested navigation is allowed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fywhrzzqe7d92qu6smxwn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fywhrzzqe7d92qu6smxwn.png" alt=" " width="800" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So write those rules down. Then define “done” per screen in four parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;UI: rendered by Compose.&lt;/li&gt;
&lt;li&gt;State: owned by a ViewModel, not the Fragment.&lt;/li&gt;
&lt;li&gt;Tests: running without the legacy host and without production test hooks.&lt;/li&gt;
&lt;li&gt;Deletion: the old layouts, adapters, and routing switches are gone.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Most teams stop at the first one and call it migrated. The hard part of a Compose migration was never the composables. It’s the boundary, and the boundary needs an owner.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>architecture</category>
      <category>android</category>
      <category>software</category>
    </item>
  </channel>
</rss>
