<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ayxan Vəliyev on Medium]]></title>
        <description><![CDATA[Stories by Ayxan Vəliyev on Medium]]></description>
        <link>https://medium.com/@ayxan.ev?source=rss-7ff6631b00a9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*rS3GYsRZP7Ld1DZa.jpg</url>
            <title>Stories by Ayxan Vəliyev on Medium</title>
            <link>https://medium.com/@ayxan.ev?source=rss-7ff6631b00a9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 09:05:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ayxan.ev/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Best way of managing Compose Recompositions]]></title>
            <link>https://medium.com/@ayxan.ev/best-way-of-managing-compose-recompositions-1d0cb62e5c8a?source=rss-7ff6631b00a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d0cb62e5c8a</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[state-management]]></category>
            <dc:creator><![CDATA[Ayxan Vəliyev]]></dc:creator>
            <pubDate>Thu, 12 Feb 2026 20:36:49 GMT</pubDate>
            <atom:updated>2026-02-13T12:42:29.262Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V1JoEAnam_Xvj-3S-s2YGQ.png" /></figure><p>Compose is modern way of developing UI in Android and Kotlin Multiplatform spheres. It’s very powerful way of defining UI in market, but no the best one (at least as it is purely). Just be patient and keep reading below for more details.</p><p>Usually, developers use MVI design pattern with Compose and Clean Architecture pattern (Uncle’s onion model) in daily Android development. These stuffs look working perfectly.</p><p>Wait a second, let’s look closer to specifically on source of MVI state and recompositions communication. I feel there is something wrong in here, else Google’s Android jetpack compose team wouldn’t give an option like “Strong skipping”, right? Of course, they solves big problems like making stable passed lambda instances and some other known stuff. But this made me nervous about what happens under the curtains.</p><p>First of all, it is very handy when the topic is defining UI structure, building models, animate UI components and style them like a pro in a single step of development cycle. But update of them looks messed up when it comes to changing things over the time.</p><p>Let’s see what triggers recompositions of a composable:</p><ol><li>Changes in composable function parameters</li><li>Changes in composable’s state (but pay attention, it happens where the state reads happen)</li></ol><p>What is the problem now? Problem started with this kind of scenarios below:</p><p>Let’s say, you have a parent composable which takes state instance from a ViewModel. Also it has several child composables.</p><p>In this case, parent is responsible for: layout them, provide data to them, manage their visibility and other things like this. By this way, parent knows something about its child composables — state reads which happen in parent scope. Let’s stop here and look at what is state of parent and what is state of child:</p><p>Information for layouting, handling visibility of children and properties of parent are part of parent’s state. On the other hand, passed data are the concern of child’s state.</p><p>Most of the time, parent doesn’t change its child composables’ place, scale and so on. Usually, changes happen on leaf (last levels of a UI tree) layer, but keeping parents stateful for their children makes them recompose too unnecessarily. At this point, official docs provide solutions like:</p><ol><li>Use derived states</li><li>Use deffered reads (Slot design also works with this principle)</li></ol><p>While building an app which is very large project in coorperative level, I don’t like this because of couple of points:</p><ol><li>Complex UIs ends up with tons of derivedStates</li><li>Using deffered reads directly in front of developers’ eyes makes composables lambda graves</li></ol><p>These points matter while you attend in big coorperative company with lots of Android developers. Project goes crazy day by day with hell of Kotlin files contain many many composables with their lambdas and derivedStates.</p><p>So, what should I do now? I don’t reinvent the wheel, I’ll just make some adjustments which solves everything.</p><p>I’ve admired for thi idea from how universe is exist currently and how things happen in every scale and each scale doesn’t care about lower and higher scales.</p><p>Let’s change our vision first. Dream that you use a microscope and start to see different things on each scale while narrowing the lens. Lower scale changes doesn’t care about upper and upper scales doesn’t know anything about lower but adapt changes without doing any extra work.</p><p>Let’s apply this for Compose now:</p><ol><li>Each scale of existance is consist of Composables in Compose Universe</li><li>Each scale requires a microscope lens to access it</li><li>Each composable has its own existance — State</li><li>Universe consists of cummilation of existences — States’ sum of each scale</li></ol><p>So think, you are a giant to look things in a universe, you need different lenses to access to each scale of existence.</p><p>Now, time is to translate things!</p><p>Universe means a screen = the biggest composable existence in UI. It has its own UI state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oa3hZDJD15OO3qLvdKkoIQ.png" /></figure><p>This UI state is consist of different states and self properties as any other composable states. This pattern continues to the very last composable in depth — leaves of a UI tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*5nbDJSctfiIeDxhXnsaMwA.png" /></figure><p>This makes every composable to have a state for itself. Very clean and easy to understand what happens in this layer. Let’s see other composables and their states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5fpnt7hsQh2Gtes3W70Fjw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TG1HMCVORCPDRro5ykbX7g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a-1n619Qpi2jkKcM-51h1A.png" /></figure><p>And let’s add universe mechanism:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hbxkDQEKKANjWfbBQFAmow.png" /></figure><p>Until here. We’ve seen lots of examples like these but there is an issue with this pattern. When child’s state is refactored, this results recomposition of parents too, because by this way you look at every scale with just your eyes.</p><p>Now we have lack of lenses in this scenario. This is just a helper tool to manage and see things.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TW1zkNtDmZf9oCwebKVhrA.png" /></figure><p>And now we need different kind of Lenses built with different materials (reactive object kinds such as Flow, Flowable and so on). I’ll use a lens which made of Coroutines Flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C2guznIHC0DDY0ZlbwK43w.png" /></figure><p>And a helper to go deeper:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TkMH-Cpd8X5IUTP08G9KWw.png" /></figure><p>That’s it. Let’s use them in practice:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XRCx7CKQq9l-WKc04Sr_nw.png" /></figure><p>Main Screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c2-RTpISRJZ4OU9DdBW2NA.png" /></figure><p>Counter Card:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JNH0CLArlhPc8HvKJiJA3g.png" /></figure><p>Counter Text:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AFxKM1Xll5z9Xf20ZeJiOw.png" /></figure><p>Version Tag:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Do3Qo3zmcQbGDjdPESvaLw.png" /></figure><p>That’s all. Now you can see that development will just consist of defining composables and their state classes and place them as it is for developers. But this lenses will deffer state reads bellow and will protect parents from recompositions.</p><p>Note: You can create a complex outcome according to different informations on a state via select functionality of a lens.</p><p>By this way, we will obey rules of recomposition but protects simplest UI tree define without going to crazy state provider lambdas (deffered reads) or lots of derived states.</p><p>It’s ready to test. Each change in universe will be applied only needed its place.</p><p><strong>Extra note of adaptibility for your project:</strong></p><p><strong>You can add some Quantum superposition theory somehow on root state level. In quantum physics, there is nothing which is clearly defined, but only what it’s seen is depend on who is watching at that time.</strong></p><p><strong>This means you can still hold a messy single state class for your ViewModel, and provide several “watchers” (mapper functions) to get data to form any needed state class in Screen level. This will bring you comfort of using single copy function in ViewModel side…</strong></p><p>Thanks for your attention! <a href="https://medium.com/u/7ff6631b00a9">Ayxan Vəliyev</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d0cb62e5c8a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>