<?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 Mahdi Zareei on Medium]]></title>
        <description><![CDATA[Stories by Mahdi Zareei on Medium]]></description>
        <link>https://medium.com/@mahdizareeii?source=rss-7b76fe3714ad------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3B199RXPR5FehZN205PnWA.jpeg</url>
            <title>Stories by Mahdi Zareei on Medium</title>
            <link>https://medium.com/@mahdizareeii?source=rss-7b76fe3714ad------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 14:42:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mahdizareeii/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[Mini-Uber Part 2: Building an Adaptive iPhone Duo UI with Compose Multiplatform]]></title>
            <link>https://medium.com/@mahdizareeii/mini-uber-part-2-building-an-adaptive-iphone-duo-ui-with-compose-multiplatform-70fde9189685?source=rss-7b76fe3714ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/70fde9189685</guid>
            <category><![CDATA[pcm]]></category>
            <category><![CDATA[compose-multiplatform]]></category>
            <category><![CDATA[iphone-duo]]></category>
            <category><![CDATA[adaptive-layout]]></category>
            <dc:creator><![CDATA[Mahdi Zareei]]></dc:creator>
            <pubDate>Sat, 31 Oct 2026 11:48:32 GMT</pubDate>
            <atom:updated>2026-10-31T11:48:32.212Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*PLGo9HBWzBILKTnsN8294A.gif" /><figcaption>adaptive layout compose multiplatform in iphone duo</figcaption></figure><p>Connecting UIKit reserved regions to shared Kotlin layout logic while preserving selection, scrolling, and navigation intent.</p><p>In <a href="https://medium.com/@mahdizareeii/building-a-mini-uber-with-kotlin-multiplatform-viper-architecture-compose-multiplatform-1d3dd0a08399">Part 1</a>, I built Mini-Uber with Kotlin Multiplatform, Compose Multiplatform, and a VIPER-inspired architecture. Compose screens observed presenter state, interactors exposed ride operations, and a router handled navigation.</p><p>For Part 2, I wanted to explore what happens when the available screen space changes while someone is using the app.</p><p>On iPhone Duo, opening, closing, rotating, or partially folding the device can change both the available space and the regions that content needs to avoid. A selected ride should remain selected while its presentation changes from one pane to two.</p><p>I added a separate, read-only adaptive demo to Mini-Uber. It uses six bundled sample rides, so I can explore layout behavior independently of Maps credentials and ride requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*CzmieRVSUCX9yqJ9.gif" /></figure><p><em>The recording shows the iPhone Duo simulator rotating, opening, entering a partially open book posture, and closing with Harbour Walk still selected.</em></p><h3>Keeping the shared architecture</h3><p>The application still has the same basic responsibilities:</p><ul><li><strong>View:</strong> a Compose screen that renders state and sends events.</li><li><strong>Presenter:</strong> a lifecycle ViewModel that owns feature state and handles events.</li><li><strong>Interactor:</strong> operations used by the map and ride-request features.</li><li><strong>Entity:</strong> shared Kotlin models.</li><li><strong>Router:</strong> typed navigation and destination arguments.</li></ul><p>The adaptive feature fits into the presentation layer. Its state contains local demo rides and the selected ride ID; it does not call the ride repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WFUTfCvibj6xc9lx.png" /></figure><p><em>Native hosts and geometry adapters feed a shared Compose presentation layer. The map feature retains its interactor and repository path.</em></p><p>KMP compiles the shared Kotlin code for each target. Android consumes the Android library target; iOS receives a static ComposeApp framework built with Kotlin/Native. A SwiftUI wrapper creates a UIKit host, which embeds the shared Compose controller.</p><p>The platform-specific boundary supplies native geometry. The shared layer decides where the list and details belong. The same feature presenter and Compose components remain in use on both platforms.</p><h3>State ownership before layout</h3><p>I first tightened the base state contract. Each presenter creates its flows once and exposes read-only views:</p><pre>protected val _state = MutableStateFlow(UiState(initialState))<br>override val state = _state.asStateFlow()</pre><pre>protected val _action = MutableSharedFlow&lt;UI_ACTION&gt;()<br>override val action = _action.asSharedFlow()</pre><p>The state wrapper keeps content, loading, and errors together:</p><pre>data class UiState&lt;T&gt;(<br>    val data: T,<br>    val isLoading: Boolean = false,<br>    val error: String? = null,<br>)</pre><p>This lets a presenter update loading or error information while retaining its existing content. Screens observe presenter.state.collectAsState() and send typed events to onEvent.</p><p>For example, the adaptive presenter validates a ride ID and publishes a copied state:</p><pre>private fun selectRide(id: String) {<br>    _state.update { state -&gt;<br>        if (state.data.rides.none { it.id == id }) {<br>            state<br>        } else {<br>            state.copy(data = state.data.copy(selectedRideId = id))<br>        }<br>    }<br>}</pre><p>update operates on the current value atomically. Copying the feature data leaves previously published snapshots intact. StateFlow holds the latest state and suppresses equal values, which is appropriate for rendering the current screen.</p><p>There was also a correction to the action contract from Part 1: a getter that constructs MutableSharedFlow() creates a different stream on each access. Keeping it in a val gives collectors and emitters the same instance. The current features navigate through the router directly; this action flow is available infrastructure, with no replay or extra buffer by default. It does not provide durable or exactly-once event delivery. <a href="https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-shared-flow/">SharedFlow documentation</a>.</p><h3>Reading iPhone Duo geometry with UIKit</h3><p>Apple describes regions that can divide or cover parts of the display. The folding area and camera regions can become active as the device’s configuration changes. Custom layouts can respond through ReservedRegion. <a href="https://developer.apple.com/design/human-interface-guidelines/designing-for-iphone-duo">Designing for iPhone Duo</a>.</p><p>I represent those regions with a small shared model:</p><pre>data class AdaptiveRegion(<br>    val left: Float,<br>    val top: Float,<br>    val right: Float,<br>    val bottom: Float,<br>    val kind: AdaptiveRegionKind<br>)</pre><pre>enum class AdaptiveRegionKind {<br>    DIVISION,<br>    OCCLUSION<br>}</pre><p>The Swift host retains one AdaptiveWindowState and one Compose controller. Inside its custom UIView, it reads active regions during updateConstraints():</p><pre>override func updateConstraints() {<br>    var regions: [AdaptiveRegion] = []<br>    if #available(iOS 27.1, *), let window {<br>        for region in reservedRegions(kind: .division) where region.isActive {<br>            regions.append(sharedRegion(<br>                frame: convert(region.frame, to: window),<br>                kind: .division<br>            ))<br>        }<br>        for region in reservedRegions(kind: .occlusion) where region.isActive {<br>            regions.append(sharedRegion(<br>                frame: convert(region.frame, to: window),<br>                kind: .occlusion<br>            ))<br>        }<br>    }<br>    onRegionsChanged?(regions)<br>    super.updateConstraints()<br>}</pre><p><em>From </em><em>AdaptiveHostViewController.swift. The </em><em>sharedRegion helper converts a </em><em>CGRect into the shared Kotlin model.</em></p><p>UIKit observes reserved-region reads in this constraint-update path. The host also requests constraint updates when its window frame or safe-area insets change. The availability guard lets earlier supported iOS versions continue using size-based layouts and safe areas. <a href="https://developer.apple.com/documentation/uikit/uiview/reservedregion">UIView.ReservedRegion</a>.</p><p>AdaptiveWindowState filters invalid rectangles and publishes the list through mutableStateOf. The Kotlin MainViewController supplies that object through LocalAdaptiveWindowState. The iOS implementation of the shared region reader is then small:</p><pre>@Composable<br>actual fun currentAdaptiveRegions(): List&lt;AdaptiveRegion&gt; =<br>    LocalAdaptiveWindowState.current.regions</pre><p>On Android, the equivalent implementation reads Material3 Adaptive hinge information and converts its pixel bounds by display density. Both platforms produce the same shared region model.</p><p>Layout changes update this observable geometry while the existing Compose controller stays alive. That preserves the composition and its navigation owner through changes to the native window.</p><h3>Putting the coordinates in the same space</h3><p>The coordinate conversion was one of the most important details in this implementation.</p><p>UIKit provides a region relative to its view. The shared layout works with the Compose content area, which may be offset by safe areas or navigation insets. Using those coordinates directly can shift the apparent fold away from its physical location.</p><p>I use this pipeline:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kZ7C_20F-y68yJ8T.png" /></figure><p><em>UIKit points are converted to window coordinates. Android window pixels are converted to dp. The shared policy then subtracts the Compose content’s window origin.</em></p><p>On iOS, Swift calls convert(region.frame, to: window). UIKit points correspond to Compose dp in this integration.</p><p>The Compose screen applies WindowInsets.safeDrawing and measures its position in the window. Its pixel position is divided by the Compose density to obtain the content origin in dp:</p><pre>.onGloballyPositioned { coordinates -&gt;<br>    val position = coordinates.positionInWindow()<br>    origin = Offset(<br>        x = position.x / density.density,<br>        y = position.y / density.density<br>    )<br>}</pre><p>The layout policy translates every valid region into the content’s local coordinate space:</p><pre>val left = region.left - originX<br>val right = region.right - originX<br>val top = region.top - originY<br>val bottom = region.bottom - originY</pre><p>For example, a horizontal region starting at window y = 360dp belongs at local y = 320dp when the content begins 40dp below the window’s origin. The policy then clips the translated region to the content bounds.</p><p>Keeping this transformation in shared code makes it possible to test independently of UIKit and Compose rendering.</p><h3>Choosing and placing the panes</h3><p>The layout policy takes measured content width and height, window-relative regions, the Compose content origin, layout direction, and whether the user has selected a ride.</p><p>A reserved region that spans the content can act as a divider:</p><ul><li>A vertical division places the list and details on opposite sides.</li><li>A horizontal division places the list above the details.</li><li>Occlusions reduce the usable pane rectangles. If one pane becomes unusable, the remaining safe pane uses compact navigation.</li></ul><p>Without a spanning divider, the policy uses a <strong>600dp content-width breakpoint</strong>. Below it, the screen shows either the list or the selected detail. At or above it, it shows both. The list receives 35% of the width, constrained to 240–360dp, with a 24dp gap.</p><p>These numbers are this demo’s layout policy. They are not a mapping of UIKit compact and regular size classes.</p><p>RTL changes which pane contains the list while retaining the physical region coordinates. When rendering, the custom Compose Layout measures each pane to its assigned rectangle, rounds pixel bounds inward, and clips its children. This keeps drawing and touch targets inside the calculated safe area.</p><h3>Keeping selection and scrolling stable</h3><p>A wide layout needs something useful in its detail pane before the user selects a ride. I show the first ride as a derived preview:</p><pre>fun effectiveSelectedRide(isTwoPane: Boolean): DemoRide? {<br>    val selectedRide = rides.firstOrNull { it.id == selectedRideId }<br>    return selectedRide ?: if (isTwoPane) rides.firstOrNull() else null<br>}</pre><p>The key is that this function does not write selectedRideId. A default wide-screen preview therefore does not create a user selection. If the device closes before an explicit selection, the compact layout still opens on the list. After an explicit selection, it shows that ride&#39;s details.</p><p>Scroll ownership follows the same principle. The screen creates its scroll states before rendering either pane:</p><pre>val listScrollState = rememberLazyListState()<br>val detailScrollStates = rememberSaveable(saver = RideScrollStatesSaver) {<br>    mutableMapOf&lt;String, ScrollState&gt;()<br>}</pre><p>The list keeps its LazyListState, and each ride&#39;s details retrieve a ScrollState by ride ID. The custom saver stores integer scroll offsets. Rearranging the panes therefore reuses their scroll owners rather than creating a fresh position inside each layout branch.</p><p>Selection belongs to the destination’s ViewModel; it is not explicitly saved for process-death restoration. Retention during folding follows the lifetime of that destination and its retained Compose host.</p><p>Navigation also remains separate from pane placement. NavHost wraps the feature; the pane layout only arranges content. The compact &quot;All rides&quot; action clears the explicit selection. Returning Home uses the router.</p><h3>Validation and the remaining iOS work</h3><p>I kept the layout policy as a pure Kotlin function so its behavior can be tested with ordinary inputs. The adaptive tests cover the 599/600dp boundary, pane sizing, thin folds, horizontal and vertical divisions, window-origin offsets, RTL, occlusion fallback, and selection behavior.</p><p>I also exercised the app in iPhone Duo Device Hub. The recording above shows rotation, an open inner display, a partially open book posture, and closing onto the selected ride. It does not demonstrate the horizontal/tabletop arrangement; that geometry has separate policy-test coverage.</p><p>Apple’s guidance also applies to navigation and the rest of the app. The next work is to adapt global navigation controls to Duo’s side placement where appropriate, extend reserved-region handling beyond the adaptive demo, and give Ride Request a usable short-window scrolling fallback. Native Split View sizes and active-camera/Dynamic Island changes also need interactive validation. <a href="https://developer.apple.com/design/human-interface-guidelines/designing-for-iphone-duo">iPhone Duo design guidance</a>.</p><p>The part I found most useful was giving each concern a clear owner: native code reports the available geometry, shared Kotlin calculates the pane bounds, and the presenter keeps the user’s selection. That makes layout changes easier to reason about without coupling user intent to a particular window shape.</p><p>The implementation is available in <a href="https://github.com/mahdizareeii/Mini-Uber">Mini-Uber on GitHub</a>. Start with <a href="https://github.com/mahdizareeii/Mini-Uber/blob/main/iosApp/iosApp/AdaptiveHostViewController.swift">AdaptiveHostViewController.swift</a>, <a href="https://github.com/mahdizareeii/Mini-Uber/blob/main/composeApp/src/commonMain/kotlin/com/shared/miniuber/component/adaptive/AdaptiveLayoutPolicy.kt">AdaptiveLayoutPolicy.kt</a>, and <a href="https://github.com/mahdizareeii/Mini-Uber/blob/main/composeApp/src/commonMain/kotlin/com/shared/miniuber/feature/adaptive/AdaptiveDemoScreen.kt">AdaptiveDemoScreen.kt</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70fde9189685" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compose A2UI: From Fixed Screens to AI-Assembled Interfaces]]></title>
            <link>https://medium.com/@mahdizareeii/compose-a2ui-from-fixed-screens-to-ai-assembled-interfaces-e09b49885a2d?source=rss-7b76fe3714ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/e09b49885a2d</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Mahdi Zareei]]></dc:creator>
            <pubDate>Fri, 02 Oct 2026 12:32:15 GMT</pubDate>
            <atom:updated>2026-10-02T13:49:13.244Z</atom:updated>
            <content:encoded><![CDATA[<p>What if an app answered your request with a useful interface—not another paragraph?</p><p>Google’s Agent-to-UI renderer for Jetpack Compose enables exactly that. An AI agent describes an interface using JSON, and the app renders it with native Compose components. The agent sends a UI description—not Kotlin code for the app to compile or execute.</p><p>How it works</p><p>Developers provide a component catalog: approved UI building blocks and their supported properties. The agent arranges those components to match the user’s request. You can use the provided Material 3 implementation or create a catalog based on your own design system.</p><p>Think of it this way: developers build the components; the agent decides how to assemble them.</p><p>A simple example: “Track my delivery”</p><p>Imagine a user asking:</p><p>“Where is my order, and how can I contact the courier?”</p><p>The agent could respond with a delivery status and a native Contact courier button.</p><p>This illustrative A2UI v0.9.1 message assumes an order surface has already been created using the Basic Catalog. Components reference one another through IDs.</p><pre>{<br>  &quot;version&quot;: &quot;v0.9.1&quot;,<br>  &quot;updateComponents&quot;: {<br>    &quot;surfaceId&quot;: &quot;order&quot;,<br>    &quot;components&quot;: [<br>      {<br>        &quot;id&quot;: &quot;root&quot;,<br>        &quot;component&quot;: &quot;Column&quot;,<br>        &quot;children&quot;: [&quot;status&quot;, &quot;contact&quot;]<br>      },<br>      {<br>        &quot;id&quot;: &quot;status&quot;,<br>        &quot;component&quot;: &quot;Text&quot;,<br>        &quot;text&quot;: &quot;Your courier is on the way.&quot;<br>      },<br>      {<br>        &quot;id&quot;: &quot;contactLabel&quot;,<br>        &quot;component&quot;: &quot;Text&quot;,<br>        &quot;text&quot;: &quot;Contact courier&quot;<br>      },<br>      {<br>        &quot;id&quot;: &quot;contact&quot;,<br>        &quot;component&quot;: &quot;Button&quot;,<br>        &quot;child&quot;: &quot;contactLabel&quot;,<br>        &quot;action&quot;: {<br>          &quot;event&quot;: { &quot;name&quot;: &quot;contact_courier&quot; }<br>        }<br>      }<br>    ]<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oLViHHHoD95OLHf6gVFIow.gif" /></figure><pre>val catalog = A2uiCatalog(<br>      catalogId = &quot;https://example.com/a2ui/booking/v1&quot;, <br>      components = listOf(<br>           MaterialA2uiBasicCatalogV1Defaults.column, <br>           MaterialA2uiBasicCatalogV1Defaults.text, <br>           MaterialA2uiBasicCatalogV1Defaults.button<br>      )<br>)<br>val parser = remember { A2uiMessageParser() }<br><br>val processor = remember(catalog) {<br>    A2uiMessageProcessor(catalogs = listOf(catalog))<br>}<br><br>val surfaces by processor.activeSurfaces.collectAsState()<br><br>LaunchedEffect(processor) {<br>    // Process queued messages.<br>    launch {<br>        processor.collectMessages()<br>    }<br><br>    // Receive button actions and protocol errors.<br>    launch(start = CoroutineStart.UNDISPATCHED) {<br>        processor.outboundEvents.collect { event -&gt;<br>            println(event) // Debug only; not network serialization.<br>        }<br>    }<br><br>    // Local messages for now; replace their source with your backend later.<br>    initialBookingMessages().forEach { json -&gt;<br>        processor.processInput(parser, json)<br>    }<br>}<br><br>surfaces.forEach { surface -&gt;<br>    key(surface.id) {<br>        A2uiSurface(surfaceModel = surface)<br>    }<br>}</pre><p>Tapping the button produces an event that your application or backend must handle. Later messages can update the delivery status or change the interface’s composition. Describing a button does not implement the action behind it.</p><p>What changes—and what does not</p><p>A2UI lets an agent create different interfaces using capabilities already available in the installed app. It cannot invent a new native component implementation that your catalog does not provide. Dynamic composition is not unlimited app modification.</p><p>The Compose renderer also provides schema validation and error handling for malformed agent output. That helps protect the rendering pipeline; it should not be treated as proof that an agent’s content or requested action is correct.</p><p>My prediction: fewer hardcoded screens, more carefully designed capabilities</p><p>I expect more apps to combine stable core flows with AI-assembled interfaces for flexible tasks.</p><p>I would keep authentication and payment confirmation predictable, while letting an agent assemble a support form or order-management interface from approved components.</p><p>That shifts some development effort toward component catalogs, backend contracts, permissions, accessibility, and testing unexpected combinations. It does not eliminate engineering responsibility.</p><p><strong>My bet: mobile developers will spend less time defining every possible screen—and more time defining what an intelligent interface is allowed to do.</strong></p><p><a href="https://developer.android.com/develop/ui/compose/agentic/render-surfaces">https://developer.android.com/develop/ui/compose/agentic/render-surfaces</a></p><p><a href="https://developer.android.com/develop/ui/compose/agentic">Agent-to-UI renderer for Jetpack Compose (A2UI) | Android Developers</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e09b49885a2d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When GPT-5.6 Sol Ultra Lost to Engineering Experience]]></title>
            <link>https://medium.com/@mahdizareeii/when-gpt-5-6-sol-ultra-lost-to-engineering-experience-f3cf32190cfb?source=rss-7b76fe3714ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3cf32190cfb</guid>
            <category><![CDATA[code-review]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Mahdi Zareei]]></dc:creator>
            <pubDate>Tue, 11 Aug 2026 07:08:12 GMT</pubDate>
            <atom:updated>2026-08-11T07:08:12.238Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QThr5qDqWQJzXe4j3HaUuA.png" /></figure><p>I was working on an Android application built with a hybrid architecture combining Fragments, XML, and Jetpack Compose.</p><p>A Bottom Sheet was rendered inside a Compose screen, while the Bottom Navigation belonged to the parent Activity. As a result, the sheet appeared above the navigation bar instead of opening from the bottom of the entire screen.</p><p>I used GPT-5.6 Sol with Ultra reasoning to solve it—the most capable and expensive configuration available to me.</p><h3>The AI Solution</h3><p>The model treated the issue as a View hierarchy problem.</p><p>It decided to move the Bottom Sheet outside the Fragment by creating a new ComposeView and attaching it directly to the Activity as an overlay:</p><pre>ActivityContentComposeOverlay</pre><p>That decision quickly introduced several additional concerns:</p><ul><li>Transferring the LifecycleOwner</li><li>Transferring the ViewModelStoreOwner</li><li>Managing the SavedStateRegistryOwner</li><li>Restoring state after Activity recreation</li><li>Preserving rememberSaveable</li><li>Handling focus and accessibility</li><li>Coordinating gestures and pointer input</li><li>Disposing the new Composition safely</li><li>Managing persistent and modal sheets</li><li>Introducing visibility claims and tokens to prevent stale cleanup</li></ul><p>Technically, the model was doing a good job of addressing the edge cases of its chosen design.</p><p>The problem was that most of those edge cases had been created by the design itself.</p><p>A small UI issue was turning into a new subsystem with more files, more tests, more failure modes, significantly more token usage, and a higher AI bill.</p><h3>The Simpler Solution</h3><p>Instead of asking how to move the Bottom Sheet to the Activity level, I asked a different question:</p><blockquote><em>Who actually owns the Bottom Navigation?</em></blockquote><p>The answer was simple: the Activity.</p><p>I created a small contract:</p><pre>interface DashboardActivityApi {<br>    fun hideBottomNavigation()<br>    fun showBottomNavigation()<br>}</pre><p>The Activity implemented it:</p><pre>class DashboardActivity :AppCompatActivity(), DashboardActivityApi {<br>    override fun hideBottomNavigation() {<br>        binding.bottomNavigation.isGone = true<br>    }<br>    override fun showBottomNavigation() {<br>        binding.bottomNavigation.isVisible = true<br>    }<br>}</pre><p>The Fragment accessed its parent Activity through that contract:</p><pre>val dashboardActivity = requireActivity() as DashboardActivityApi</pre><p>I then connected the Bottom Navigation visibility to the Bottom Sheet’s existing state transitions:</p><pre>val sheetState = rememberModalBottomSheetState(<br>    initialValue = ModalBottomSheetValue.Hidden,<br>    skipHalfExpanded = true,<br>    confirmValueChange = { value -&gt;<br>        when (value) {<br>            ModalBottomSheetValue.Hidden -&gt;<br>                    dashboardActivity.showBottomNavigation()<br>            else -&gt; <br>                    dashboardActivity.hideBottomNavigation()<br>        }<br>        true<br>    },<br>)</pre><p>No Activity-level overlay. No additional ComposeView. No manual transfer of lifecycle or state owners.</p><p>The simpler solution did not move the Bottom Sheet. It controlled the component that actually belonged to the Activity.</p><h3>Where Did the Model Go Wrong?</h3><p>The model was not bad at writing Kotlin or Compose code. It even identified reasonable edge cases for its proposed solution.</p><p>The mistake happened before implementation: it framed the problem incorrectly.</p><p>The model asked:</p><blockquote><em>How can I build a reliable Activity-level Compose overlay?</em></blockquote><p>The better question was:</p><blockquote><em>Who owns the component that needs to be hidden?</em></blockquote><p>The first question leads to overlays, lifecycle bridging, state restoration, accessibility handling, visibility claims, and many additional tests.</p><p>The second leads to a small interface.</p><p>AI can produce an excellent technical answer to the wrong question. Professional abstractions, extensive tests, and carefully handled edge cases can even make a poor architectural decision look impressive.</p><p>Ultra reasoning does not eliminate this risk. More reasoning can simply take the model deeper into the wrong solution while burning more tokens.</p><h3>AI Is Not Always Right</h3><p>There is a growing trend toward making everything “AI-first.” That becomes dangerous when generated code is accepted without serious review.</p><p>A junior developer might accept an unnecessarily complicated solution because:</p><ul><li>A powerful model generated it.</li><li>The code compiles.</li><li>The tests pass.</li><li>It works at runtime.</li></ul><p>None of these guarantees that the architecture is good.</p><p>Reviewing only runtime behavior is not enough. Code review should also ask:</p><ul><li>Why does this abstraction exist?</li><li>Who owns this responsibility?</li><li>Why is this file becoming so large?</li><li>Does the package structure reflect the system’s architecture?</li><li>Are unrelated responsibilities being mixed?</li><li>How many new failure modes were introduced?</li><li>Was all this code actually necessary?</li></ul><p>If teams ignore these questions, the result is often oversized files, weak package boundaries, unclear ownership, and code that runs without anyone fully understanding why it was designed that way.</p><p>The product may continue working for a while. But small changes gradually become expensive refactors, developers become afraid to touch critical areas, and the architecture eventually reaches a dead end.</p><p>AI is a powerful tool for generating code, writing tests, and identifying edge cases. It should not be the final authority on architectural decisions.</p><blockquote><em>A stronger model, deeper reasoning, and a higher bill do not guarantee a better engineering decision.</em></blockquote><p>Sometimes the most valuable engineering skill in the age of AI is not producing more code. It is recognizing which code should never have been written.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3cf32190cfb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build iOS XCFramework in Kotlin Multiplatform Without a Mac]]></title>
            <link>https://medium.com/@mahdizareeii/how-to-build-ios-xcframework-in-kotlin-multiplatform-without-a-mac-6d4f1c33f2f5?source=rss-7b76fe3714ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d4f1c33f2f5</guid>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[xcframework]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <dc:creator><![CDATA[Mahdi Zareei]]></dc:creator>
            <pubDate>Sat, 06 Jun 2026 18:40:01 GMT</pubDate>
            <atom:updated>2026-06-07T06:26:38.190Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3NWzvv51pZjrULBPJDUkSg.png" /><figcaption>build xcframework without mac</figcaption></figure><p>Kotlin Multiplatform (KMP) is a powerful way to share code between Android and iOS.<br> But one big problem many Android developers face is:</p><p>👉 “I don’t have a Mac, how can I build iOS output?”</p><p>In this article, I will show how to generate an <strong>XCFramework for iOS without owning a Mac</strong>, using <strong>GitHub Actions (CI/CD)</strong>.</p><h3>Why this problem exists?</h3><p>iOS build tools depend on Apple tools like:</p><ul><li>Xcode</li><li>xcodebuild</li><li>iOS SDK</li><li>Kotlin/Native compiler for Apple targets</li></ul><p>Because of this:</p><p>❌ Windows cannot build iOS frameworks<br>❌ Linux cannot build iOS frameworks</p><p>Even if you run KMP project on these systems, iOS compilation will fail.</p><h3>The solution</h3><p>Instead of buying a Mac or using Mac Cloud services, we use:</p><p>👉 <strong>GitHub Actions macOS runners</strong></p><p>GitHub gives free macOS machines for CI/CD builds.</p><h3>KMP XCFramework configuration</h3><p>Here is the full setup used in the shared module:</p><pre>import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl<br>import org.jetbrains.kotlin.gradle.dsl.JvmTarget<br>import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework<br><br>plugins {<br>    alias(libs.plugins.kotlinMultiplatform)<br>    alias(libs.plugins.androidMultiplatformLibrary)<br>    alias(libs.plugins.composeMultiplatform)<br>    alias(libs.plugins.composeCompiler)<br>}<br><br>kotlin {<br><br>    // Create XCFramework container for all iOS targets<br>    val xcFramework = XCFramework(xcFrameworkName = &quot;Shared&quot;)<br><br>    listOf(<br>        // iOS device (iPhone / iPad real devices)<br>        iosArm64(),<br><br>        // iOS simulator (Apple Silicon Macs)<br>        iosSimulatorArm64()<br>    ).forEach { iosTarget -&gt;<br><br>        iosTarget.binaries.framework {<br><br>            // Framework name used in Xcode<br>            baseName = &quot;Shared&quot;<br><br>            // Static framework avoids runtime linking issues<br>            isStatic = true<br><br>            // Export dependencies so iOS can access them directly<br>            export(libs.compose.runtime)<br>            export(libs.compose.foundation)<br>            export(libs.compose.material3)<br>            export(libs.compose.ui)<br>            export(libs.compose.components.resources)<br>            export(libs.androidx.lifecycle.viewmodelCompose)<br>            export(libs.androidx.lifecycle.runtimeCompose)<br><br>            // Add framework into final XCFramework bundle<br>            xcFramework.add(this)<br><br>            // Bundle identifier for iOS framework metadata<br>            binaryOption(&quot;bundleId&quot;, libs.plugins.projectId.get().pluginId)<br>        }<br>    }<br><br>    // Other targets<br>    jvm()<br><br>    js {<br>        browser()<br>    }<br><br>    @OptIn(ExperimentalWasmDsl::class)<br>    wasmJs {<br>        browser()<br>    }<br><br>    androidLibrary {<br>        namespace = &quot;org.example.project.shared&quot;<br>        compileSdk = libs.versions.android.compileSdk.get().toInt()<br>        minSdk = libs.versions.android.minSdk.get().toInt()<br><br>        compilerOptions {<br>            jvmTarget = JvmTarget.JVM_11<br>        }<br><br>        androidResources {<br>            enable = true<br>        }<br><br>        withHostTest {<br>            isIncludeAndroidResources = true<br>        }<br>    }<br><br>    sourceSets {<br>        commonMain.dependencies {<br>            api(libs.compose.runtime)<br>            api(libs.compose.foundation)<br>            api(libs.compose.material3)<br>            api(libs.compose.ui)<br>            api(libs.compose.components.resources)<br>            api(libs.androidx.lifecycle.viewmodelCompose)<br>            api(libs.androidx.lifecycle.runtimeCompose)<br>            api(libs.compose.uiToolingPreview)<br>        }<br><br>        androidMain.dependencies {}<br>        jsMain.dependencies {<br>            implementation(libs.wrappers.browser)<br>        }<br><br>        commonTest.dependencies {<br>            implementation(libs.kotlin.test)<br>        }<br>    }<br>}<br><br>dependencies {<br>    androidRuntimeClasspath(libs.compose.uiTooling)<br>}</pre><h3>GitHub Actions CI/CD setup</h3><p>We use macOS runners to build XCFramework automatically.</p><h3>Debug build workflow</h3><pre>name: iOS debug XCFramework Build<br><br>on:<br>  workflow_dispatch:<br>  push:<br>    branches: [ develop ]<br><br>jobs:<br>  ios-build:<br>    runs-on: macos-latest<br><br>    steps:<br>      - name: Checkout<br>        uses: actions/checkout@v4<br><br>      - name: Setup Java<br>        uses: actions/setup-java@v4<br>        with:<br>          distribution: temurin<br>          java-version: 17<br><br>      - name: Setup Gradle<br>        uses: gradle/actions/setup-gradle@v3<br><br>      - name: Grant permission<br>        run: chmod +x ./gradlew<br><br>      - name: Clean project<br>        run: ./gradlew clean<br><br>      - name: Build XCFramework<br>        run: ./gradlew :shared:assembleSharedDebugXCFramework<br><br>      - name: Upload artifact<br>        uses: actions/upload-artifact@v4<br>        with:<br>          name: ios-xcframework<br>          path: shared/build/XCFrameworks/**<br>          if-no-files-found: error</pre><p>Release build workflow</p><pre>name: iOS release XCFramework Build<br><br>on:<br>  workflow_dispatch:<br>  push:<br>    branches: [ master ]<br><br>jobs:<br>  ios-build:<br>    runs-on: macos-latest<br><br>    steps:<br>      - uses: actions/checkout@v4<br><br>      - uses: actions/setup-java@v4<br>        with:<br>          distribution: temurin<br>          java-version: 17<br><br>      - uses: gradle/actions/setup-gradle@v3<br><br>      - run: chmod +x ./gradlew<br><br>      - run: ./gradlew clean<br><br>      - run: ./gradlew :shared:assembleSharedReleaseXCFramework<br><br>      - uses: actions/upload-artifact@v4<br>        with:<br>          name: ios-xcframework<br>          path: shared/build/XCFrameworks/**</pre><h3>How to download the XCFramework</h3><p>After CI finishes:</p><ol><li>Go to GitHub Actions tab</li><li>Open latest workflow run</li><li>Open <strong>Artifacts</strong> section</li><li>Download ios-xcframework</li></ol><p>Inside you will find:</p><pre>Shared.xcframework</pre><h3>What iOS developers do with it?</h3><p>They can:</p><ul><li>Import XCFramework into Xcode</li><li>Use shared Kotlin code</li><li>Avoid rebuilding KMP project</li></ul><p>No Kotlin setup required on their machine.</p><h3>Important note</h3><p>This does NOT mean iOS apps can run on Windows or Linux.</p><p>You still need macOS for:</p><ul><li>Running Xcode</li><li>iOS Simulator</li><li>App Store deployment</li></ul><p>But building shared code is fully automated.</p><h3>Benefits of this approach</h3><p>Using this setup:</p><ul><li>No need for a personal Mac</li><li>No need for Mac cloud subscription</li><li>CI/CD builds iOS automatically</li><li>Shared code is always validated for iOS</li><li>Every push checks iOS compatibility</li><li>Easy handover to iOS team</li></ul><h3>Conclusion</h3><p>With Kotlin Multiplatform + GitHub Actions, you can fully automate iOS XCFramework builds without owning a Mac.</p><p>This makes development:</p><ul><li>cheaper</li><li>faster</li><li>CI/CD friendly</li><li>scalable for teams</li></ul><h3>👇 My project</h3><p>You can check my project here:</p><p><a href="https://github.com/mahdizareeii/KMPStructure">https://github.com/mahdizareeii/KMPStructure</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d4f1c33f2f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Building a Mini Uber with Kotlin Multiplatform + VIPER Architecture + Compose Multiplatform]]></title>
            <link>https://medium.com/@mahdizareeii/building-a-mini-uber-with-kotlin-multiplatform-viper-architecture-compose-multiplatform-1d3dd0a08399?source=rss-7b76fe3714ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d3dd0a08399</guid>
            <category><![CDATA[viper-architecture]]></category>
            <category><![CDATA[uber-clone]]></category>
            <category><![CDATA[google-maps]]></category>
            <category><![CDATA[viper]]></category>
            <category><![CDATA[compose-multiplatform]]></category>
            <dc:creator><![CDATA[Mahdi Zareei]]></dc:creator>
            <pubDate>Fri, 03 Oct 2025 00:20:58 GMT</pubDate>
            <atom:updated>2025-10-03T00:22:23.579Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Uber with Kotlin Multiplatform + VIPER Architecture + Compose Multiplatform + Google Map native implementation Compose Multiplatform" src="https://cdn-images-1.medium.com/max/1024/1*xT-KbscTc81yftiSTivZLQ.png" /></figure><p>👉 Full source code: <a href="https://github.com/mahdizareeii/Mini-Uber">GitHub — Mini-Uber</a></p><h3>Why this project?</h3><p>When we think of <strong>cross-platform apps</strong>, the challenge is to balance <strong>shared business logic</strong> with <strong>native UI flexibility</strong>. Kotlin Multiplatform (KMP) lets us do exactly that.</p><p>On top of that, I wanted to experiment with <strong>VIPER architecture</strong> — traditionally known from iOS — but reimagined for <strong>KMP + Jetpack Compose Multiplatform (CMP)</strong>.</p><p>The result is a <strong>Mini Uber clone</strong> (not production, just educational) that demonstrates how to:</p><ul><li>Structure an app with <strong>VIPER (View–Interactor–Presenter–Entity–Router)</strong>.</li><li>Keep <strong>UI state strongly typed and generic</strong>.</li><li>Use <strong>Presenter as a ViewModel</strong> to integrate with Compose.</li><li>Handle <strong>navigation + screen arguments</strong> in a clean, multiplatform way.</li></ul><h3>🏛 Architecture Overview</h3><p>Here’s how VIPER fits into KMP/CMP:</p><ul><li><strong>View</strong> → Composable screens observing StateFlow&lt;UiState&lt;T&gt;&gt;.</li><li><strong>Presenter</strong> → Extends ViewModel, processes events, updates state.</li><li><strong>Interactor</strong> → Business logic (e.g., fetch drivers, request ride).</li><li><strong>Router</strong> → Handles navigation between screens + result passing.</li><li><strong>Entities</strong> → Models like DriverResponse, RideRequest.</li></ul><h3>🧩 Base Contract</h3><p>To keep things consistent, I defined a <strong>BaseContract</strong>.</p><pre><br>interface BaseContract {<br>    interface View&lt;UI_STATE, UI_ACTION&gt; {<br>        val _state: MutableStateFlow&lt;UiState&lt;UI_STATE&gt;&gt;<br>        val state: StateFlow&lt;UiState&lt;UI_STATE&gt;&gt;<br><br>        val _action: MutableSharedFlow&lt;UI_ACTION&gt;<br>        val action: SharedFlow&lt;UI_ACTION&gt;<br>    }<br><br>    abstract class Presenter&lt;EVENT, UI_STATE, UI_ACTION&gt;(<br>        initialState: UiState&lt;UI_STATE&gt; = UiState.Init<br>    ) : ViewModel(), View&lt;UI_STATE, UI_ACTION&gt; {<br>        override val _state = MutableStateFlow&lt;UiState&lt;UI_STATE&gt;&gt;(initialState)<br>        override val state: StateFlow&lt;UiState&lt;UI_STATE&gt;&gt; get() = _state<br><br>        override val _action: MutableSharedFlow&lt;UI_ACTION&gt; get() = MutableSharedFlow&lt;UI_ACTION&gt;()<br>        override val action: SharedFlow&lt;UI_ACTION&gt; get() = _action.asSharedFlow()<br><br>        abstract fun onEvent(event: EVENT)<br>    }<br><br>    interface Interactor<br><br>    interface Router {<br>        fun &lt;RESULT&gt; setParentResult(key: String, value: RESULT)<br>        fun &lt;RESULT&gt; getResultFlow(key: String, initialValue: RESULT?): StateFlow&lt;RESULT?&gt;?<br><br>        fun &lt;T&gt; getScreenArg(screen: KClass&lt;*&gt;): T<br><br>        fun navigate(route: String)<br>        fun navigate(route: String, popUpTo: String, popUpToInclusive: Boolean)<br><br>        fun &lt;T : Any&gt; navigate(route: T)<br>        fun &lt;T : Any&gt; navigate(route: T, popUpTo: KClass&lt;*&gt;, popUpToInclusive: Boolean)<br><br>        fun navigateUp()<br>    }<br>}</pre><p>This ensures every screen has:</p><ul><li><strong>Events → Presenter</strong></li><li><strong>UiState → View</strong></li><li><strong>Actions → one-time effects (snackbars, toasts, nav)</strong></li></ul><p>🎛 Example: Home Presenter</p><pre>class HomePresenter(<br>    private val interactor: HomeContract.Interactor,<br>    private val router: BaseContract.Router<br>) : HomeContract.Presenter() {<br><br>    private var homeState = HomeState()<br>        set(value) {<br>            field = value<br>            _state.update { UiState.Success(value) }<br>        }<br><br>    override fun onEvent(event: HomeEvent) {<br>        when (event) {<br>            is HomeEvent.Init -&gt; init()<br>            is HomeEvent.NavigateBack -&gt; router.navigateUp()<br>            is HomeEvent.OnMapStateUpdated -&gt; {<br>               //handleOnMapStateUpdated<br>            }<br><br>            is HomeEvent.CancelTravel -&gt; {<br>                //handleCancelTravel<br>            }<br><br>            is HomeEvent.OnConfirmButtonClicked -&gt; {<br>                //handleOnConfirmButtonClicked<br>            }<br><br>            is HomeEvent.OnCancelButtonClicked -&gt; {<br>                //handleOnCancelButtonClicked<br>            }<br>        }<br>    }<br><br>    private fun init() {<br>        _state.update { UiState.Loading }<br>        viewModelScope.launch {<br>            interactor.getLastTrip().onSuccess {<br>                when (val state = it.state) {<br>                    is TripResponse.TripState.EndTrip -&gt; {<br>                        //Update state to EndTrip<br>                    }<br><br>                    is TripResponse.TripState.NoTrip -&gt; {<br>                        //Update state to NoTrip<br>                    }<br><br>                    is TripResponse.TripState.OnTrip -&gt; {<br>                        //Update state to OnTrip<br>                    }<br><br>                    is TripResponse.TripState.NavigateToRideRequest -&gt; {<br>                        //Navigate to RideRequestScreen<br>                        router.navigate&lt;AppScreens.RideRequestScreen&gt;(<br>                            route = AppScreens.RideRequestScreen(),<br>                            popUpTo = AppScreens.HomeScreen::class,<br>                            popUpToInclusive = true<br>                        )<br>                    }<br>                }<br>            }.onFailure { error -&gt;<br>                _state.update { UiState.Error(error = error.message) }<br>            }<br>        }<br>    }<br>}</pre><p>Here the <strong>Presenter</strong>:</p><ul><li>Listens for events like OnMapStateUpdated.</li><li>Calls the <strong>Interactor</strong> for data.</li><li>Updates UiState.Success(HomeState) for the <strong>View</strong>.</li><li>Delegates navigation to the <strong>Router</strong>.</li></ul><pre>class HomeInteractor(private val repository: DriverRepository) : HomeContract.Interactor {<br>    override suspend fun getNearbyDrivers(<br>        location: LocationRequest<br>    ): Result&lt;List&lt;DriverResponse&gt;&gt; {<br>        return repository.fetchNearbyDrivers(location)<br>    }<br><br>    override suspend fun getLastTrip(): Result&lt;TripResponse&gt; {<br>        return repository.getLastTrip()<br>    }<br>}</pre><p>This keeps <strong>business logic isolated</strong>, you can also create and inject <strong>use cases</strong> here.</p><h3>🧭 Navigation (Router)</h3><p>Navigation is handled by ComposeRouter, wrapping NavController.<br> The trick is to <strong>keep track of backStackEntry</strong> so we can:</p><ul><li>Pass screen arguments.</li><li>Get results from child screens.</li></ul><pre><br>class ComposeRouter : BaseContract.Router {<br><br>    private var navController: NavController? = null<br>    var lastBackStackEntry: NavBackStackEntry? =null<br><br>    fun initNavController(navController: NavController) {<br>        this.navController = navController<br>    }<br><br>    fun setCurrentBackStackEntry(backStackEntry: NavBackStackEntry) {<br>        this.lastBackStackEntry = backStackEntry<br>    }<br><br>    override fun &lt;RESULT&gt; setParentResult(key: String, value: RESULT) {<br>        navController?.previousBackStackEntry?.savedStateHandle?.set(key = key, value = value)<br>    }<br><br>    override fun &lt;RESULT&gt; getResultFlow(key: String, initialValue: RESULT?): StateFlow&lt;RESULT?&gt;? {<br>        return navController?.currentBackStackEntry?.savedStateHandle?.getStateFlow(<br>            key = key,<br>            initialValue = initialValue<br>        )<br>    }<br><br>    override fun &lt;T&gt; getScreenArg(screen: KClass&lt;*&gt;): T {<br>        return lastBackStackEntry?.toRoute(route = screen) ?: error(&quot;No back stack entry available for screen $screen call setCurrentBackStackEntry in composable fun of your NavHost&quot;)<br>    }<br><br>    override fun navigate(route: String) {<br>        navController?.navigate(route = route)<br>    }<br><br>    override fun navigate(<br>        route: String,<br>        popUpTo: String,<br>        popUpToInclusive: Boolean<br>    ) {<br>        navController?.navigate(route = route) {<br>            popUpTo(route = popUpTo) {<br>                inclusive = popUpToInclusive<br>            }<br>        }<br>    }<br><br>    override fun &lt;T : Any&gt; navigate(route: T) {<br>        navController?.navigate(route = route)<br>    }<br><br>    override fun &lt;T : Any&gt; navigate(<br>        route: T,<br>        popUpTo: KClass&lt;*&gt;,<br>        popUpToInclusive: Boolean<br>    ) {<br>        navController?.navigate(route = route) {<br>            popUpTo(route = popUpTo) {<br>                inclusive = popUpToInclusive<br>            }<br>        }<br>    }<br><br><br>    override fun navigateUp() {<br>        navController?.navigateUp()<br>    }<br>}</pre><p>🎨 App Entry</p><pre><br>//App screens with their arguments<br>sealed class AppScreens {<br>    @Serializable<br>    data object HomeScreen : AppScreens()<br><br>    @Serializable<br>    data class RideRequestScreen(<br>        val pickupLat: Double,<br>        val pickupLng: Double,<br>        val dropOffLat: Double,<br>        val dropOffLng: Double,<br>    ) : AppScreens() {<br>        constructor() : this(Double.NaN, Double.NaN, Double.NaN, Double.NaN)<br><br>        fun isValidLocation() = (pickupLat + pickupLng + dropOffLat + dropOffLng) &gt; Double.NaN<br>    }<br>}<br><br><br>@Composable<br>fun App() {<br>    val navController = rememberNavController()<br>    //get instance of the ComposeRouter<br>    val composeRouter = getKoin().get&lt;ComposeRouter&gt;()<br>    //init the composeRouter navController to use in presenters<br>    composeRouter.initNavController(navController)<br><br>    MaterialTheme(colorScheme = lightColorScheme()) {<br>        NavHost(<br>            navController = navController,<br>            startDestination = AppScreens.HomeScreen<br>        ) {<br>            composable&lt;AppScreens.HomeScreen&gt; { entry -&gt;<br>                //update the backStackEntry in every composable to get screen arguments<br>                composeRouter.setCurrentBackStackEntry(entry)<br>                HomeScreen()<br>            }<br>            composable&lt;AppScreens.RideRequestScreen&gt; { entry -&gt;<br>                //update the backStackEntry in every composable to get screen arguments<br>                composeRouter.setCurrentBackStackEntry(entry)<br>                RideRequestScreen()<br>            }<br>        }<br>    }<br>}</pre><h3>📱 Screens in Mini Uber</h3><p>For the demo, I built two main screens:</p><ol><li><strong>Home Screen</strong> → The map experience is <strong>fully native</strong> on each platform:</li></ol><ul><li><strong>Android</strong> → implemented using <strong>Google Maps Compose</strong> (the official Jetpack Compose integration).</li><li><strong>iOS</strong> → implemented using a <strong>UIKitViewController</strong> in <strong>compose </strong>(the official <strong>UIKit</strong> integration).</li></ul><ol><li><strong>Ride Request Screen</strong> → Confirm ride, simulate trip.</li></ol><p>That’s enough to showcase:</p><ul><li><strong>Map interaction</strong></li><li><strong>Navigation</strong></li><li><strong>State management with VIPER</strong></li></ul><h3>🏁 Conclusion</h3><p>With this <strong>Mini Uber</strong>, I proved that:</p><ul><li><strong>VIPER architecture</strong> can be adapted to <strong>Kotlin Multiplatform + Compose Multiplatform</strong>.</li><li>Using a <strong>BaseContract</strong> makes screens reusable and consistent.</li><li>The <strong>Presenter</strong> as ViewModel plays well with <strong>Compose state management</strong>.</li><li>Navigation concerns stay <strong>separated in Router</strong>, not spread in the UI.</li><li>Google map implementation, state management, and challenges in the compose multipaltform</li></ul><p>👉 Full source code: <a href="https://github.com/mahdizareeii/Mini-Uber">GitHub — Mini-Uber</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d3dd0a08399" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Developers Should Consider Kotlin Multiplatform/Compose Multiplatform Framework?]]></title>
            <link>https://medium.com/@mahdizareeii/why-developers-should-consider-kotlin-multiplatform-compose-multiplatform-framework-f74e7a969e3a?source=rss-7b76fe3714ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/f74e7a969e3a</guid>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[example]]></category>
            <category><![CDATA[compose-multiplatform]]></category>
            <category><![CDATA[benchmark]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Mahdi Zareei]]></dc:creator>
            <pubDate>Thu, 15 May 2025 22:36:00 GMT</pubDate>
            <atom:updated>2025-05-15T22:36:00.969Z</atom:updated>
            <content:encoded><![CDATA[<ol><li><strong>Real Performance Benefits Native Performance:</strong> Uses platform-specific implementations where it matters Small Binary Size: Only shared code is compiled for both platforms Direct Platform Access: Can still use native APIs when needed</li><li><strong>Development Efficiency Single Codebase:</strong> Write business logic once, use everywhere Faster Development: Changes in shared code automatically apply to both platforms Consistent Behavior: Same business logic means same behavior across platforms</li><li><strong>UI Development Jetpack Compose:</strong> Modern declarative UI toolkit Platform-Specific UI: Can use native UI components when needed Shared Components: Reuse UI logic across platforms</li><li><strong>Easy Integration Gradle Setup:</strong> Familiar build system CocoaPods: Standard iOS dependency management Platform-Specific Code: Can still write native code when needed</li><li><strong>Maintenance Benefits Single Source of Truth: </strong>Business logic in one place Easier Testing: Shared code means shared tests Consistent Updates: Update once, deploy everywhere</li><li><strong>Real Cost Benefits Reduced Development Time: </strong>Write once, run everywhere Smaller Team Size: One team can handle both platforms Faster Time to Market: Develop features once for both platforms</li><li><strong>Learning Curve Kotlin:</strong> Similar to Swift/Java Compose: Similar to SwiftUI Architecture: Similar to native patterns</li><li><strong>Production Ready:</strong> Used in real applications<br>Scalable: Can grow with your needs</li><li><strong>Community Support:</strong> Active development and support</li></ol><h3>✨ Want to Learn More?</h3><p>Check out these GitHub repositories for full examples, real implementations, This projects shows that KMP isn’t just a theoretical solution — it’s a practical approach that can save time and resources while maintaining the quality and performance that native developers expect.</p><ul><li>🔗 <a href="https://github.com/mahdizareeii/ComposeMultiplatform"><strong>ComposeMultiplatform</strong></a></li><li>🔗 <a href="https://github.com/mahdizareeii/KotlinMultiPlatform"><strong>KotlinMultiPlatform</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f74e7a969e3a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pagination in Jetpack Compose]]></title>
            <link>https://medium.com/@mahdizareeii/pagination-in-jetpack-compose-2df99a19ca92?source=rss-7b76fe3714ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/2df99a19ca92</guid>
            <category><![CDATA[compose-paging-3]]></category>
            <category><![CDATA[collectaslazypagingitems]]></category>
            <category><![CDATA[lazycolumn-pagination]]></category>
            <category><![CDATA[lazy-loading]]></category>
            <category><![CDATA[compose-pagination]]></category>
            <dc:creator><![CDATA[Mahdi Zareei]]></dc:creator>
            <pubDate>Thu, 28 Nov 2024 08:30:28 GMT</pubDate>
            <atom:updated>2024-11-28T08:33:34.731Z</atom:updated>
            <content:encoded><![CDATA[<p>I want to share a custom implementation for handling pagination in a scrollable list without using the Paging 3 library. This approach is helpful for those who prefer not to use Paging 3. 😊</p><p>If you’re already using Paging 3 or want to fetch and cache data using RemoteMediator, you should refer to the official <a href="https://developer.android.com/reference/kotlin/androidx/paging/compose/package-summary#(kotlinx.coroutines.flow.Flow).collectAsLazyPagingItems(kotlin.coroutines.CoroutineContext)">collectAsLazyPagingItems</a>() instead</p><p>Now, let’s dive into the implementation and understand how it works:</p><pre>@Composable<br>fun EndlessLazyColumn(<br>    modifier: Modifier = Modifier,<br>    loading: Boolean = false,<br>    listState: LazyListState = rememberLazyListState(),<br>    loadMore: () -&gt; Unit,<br>    loadingItem: @Composable () -&gt; Unit,<br>    content: LazyListScope.() -&gt; Unit<br>) {<br>    val reachedBottom: Boolean by remember { derivedStateOf { listState.reachedBottom() } }<br><br>    // load more if scrolled to bottom<br>    LaunchedEffect(reachedBottom) { if (reachedBottom &amp;&amp; !loading) loadMore() }<br><br>    LazyColumn(<br>        modifier = modifier,<br>        state = listState<br>    ) {<br>        content.invoke(this)<br>        if (loading) item { loadingItem() }<br>    }<br>}<br><br>fun LazyListState.reachedBottom(buffer: Int = 1): Boolean {<br>    val lastVisibleItem = this.layoutInfo.visibleItemsInfo.lastOrNull()<br>    return lastVisibleItem?.index != 0 &amp;&amp; lastVisibleItem?.index == this.layoutInfo.totalItemsCount - buffer<br>}</pre><p>The extension function LazyListState.reachedBottom determines whether the user has scrolled to the bottom of the list.</p><p>The reachedBottom value is tracked using a derivedStateOf block to ensure recomposition happens only when the state changes.</p><p>how to use it?</p><p>In my case, I stored the page number in the ViewModel and incremented it with every successful response. I also stored the fetched data in a MyUiState data class.</p><pre>val uiState by viewModel.uiState.collectAsState()<br>var myUiState by remember { mutableStateOf(MyUiState()) }<br><br>when (val state = uiState) {<br>    is BaseUiState.InitialUiState -&gt; LaunchedEffect(<br>        key1 = &quot;firstInitializing&quot;,<br>        block = {<br>            viewModel.nextPage()<br>        }<br>    )<br><br>    is BaseUiState.SuccessUiState -&gt; {<br>        myUiState = state.state<br>    }<br><br>    else -&gt; {}<br>}<br><br>EndlessLazyColumn(<br>    modifier = modifier.fillMaxSize(),<br>    loading = uiState is BaseUiState.LoadingUiState,<br>    loadMore = {<br>        viewModel.nextPage()<br>    },<br>    loadingItem = {<br>       MyCustomLoading()<br>    }<br>){<br>    items(<br>        key = { it.id },<br>        items = myUiState.items<br>    ) {<br>        MyComponent(<br>            data = it,<br>            onItemCliced = viewModel::onItemCliced<br>        )<br>    }<br>}</pre><p>Leave a comment if you have any questions or would like to discuss a specific point further.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2df99a19ca92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jetpack compose best practice part 1]]></title>
            <link>https://medium.com/@mahdizareeii/jetpack-compose-best-practice-part-1-a97d8befa286?source=rss-7b76fe3714ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/a97d8befa286</guid>
            <category><![CDATA[best-practice-advice]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Mahdi Zareei]]></dc:creator>
            <pubDate>Tue, 26 Jul 2022 12:23:58 GMT</pubDate>
            <atom:updated>2022-07-26T12:23:58.217Z</atom:updated>
            <content:encoded><![CDATA[<p>I want to introduce a new way to create a screen in jetpack compose,</p><p>I don’t know is one of the bests ways to create a screen or not, but I share it with you and I would like to get feedback about that :)</p><p>In jetpack compose we usually create a file that has some functions<br>for screens, but in this way I want to use a base class for screens and <br>we can create and use compose screens like fragments.</p><p>Here is your BaseScreen code :</p><pre>abstract class BaseScreen {<br><br>    protected lateinit var navController: NavHostController<br>    protected lateinit var context: Context<br><br>    @Composable<br>    open fun createScreen(navController: NavHostController) {<br>        this.navController = navController<br>        this.context = navController.context<br>        listenToComposableLifecycle(<br>            onEvent = <strong>{ </strong>lifecycleOwner, event <strong>-&gt;<br>                </strong>when (event) {<br>                    Lifecycle.Event.<em>ON_RESUME </em>-&gt;<br>                        onResume(lifecycleOwner)<br>                    Lifecycle.Event.<em>ON_PAUSE </em>-&gt;<br>                        onPause(lifecycleOwner)<br>                    Lifecycle.Event.<em>ON_STOP </em>-&gt;<br>                        onStop(lifecycleOwner)<br>                    Lifecycle.Event.<em>ON_DESTROY </em>-&gt;<br>                        onDestroy(lifecycleOwner)<br>                    else -&gt; {}<br>                }<br>            <strong>}<br>        </strong>)<br>        onScreenCreated()<br>    }<br><br>    @Composable<br>    protected abstract fun onScreenCreated()<br>    protected open fun onResume(lifeCycleOwner: LifecycleOwner) {}<br>    protected open fun onPause(lifeCycleOwner: LifecycleOwner) {}<br>    protected open fun onStop(lifeCycleOwner: LifecycleOwner) {}<br>    protected open fun onDestroy(lifeCycleOwner: LifecycleOwner) {}<br><br>    fun getArgument() = navController.previousBackStackEntry?.savedStateHandle<br><br>    fun putArgument(<br>        savedStateHandle: SavedStateHandle.() -&gt; Unit<br>    ) {<br>        navController.currentBackStackEntry?.savedStateHandle?.<em>let </em><strong>{<br>            </strong>savedStateHandle.invoke(<strong>it</strong>)<br>        <strong>}<br>    </strong>}<br><br>    @Composable<br>    private fun listenToComposableLifecycle(<br>        lifeCycleOwner: LifecycleOwner = <em>LocalLifecycleOwner</em>.current,<br>        onEvent: (LifecycleOwner, Lifecycle.Event) -&gt; Unit<br>    ) {<br>        <em>DisposableEffect</em>(lifeCycleOwner) <strong>{<br>            </strong>val observer = <em>LifecycleEventObserver </em><strong>{ </strong>source, event <strong>-&gt;<br>                </strong>onEvent(source, event)<br>            <strong>}<br>            </strong>lifeCycleOwner.<em>lifecycle</em>.addObserver(observer)<br>            onDispose <strong>{<br>                </strong>lifeCycleOwner.<em>lifecycle</em>.removeObserver(observer)<br>            <strong>}<br>        }<br>    </strong>}<br>}</pre><p>if you look at the BaseScreen code you will see there are some methods like</p><p>createScreen: must be call from instance creator of that like Activity or NavGraph (you will see how I used that in MainActivity).</p><p>onScreenCreated: will call in createScreen method and must be override in <br>subclasses.</p><p>Here is my SampleScreen that extends from BaseScreen class:</p><pre>class SampleScreen : BaseScreen() {<br><br>    @Composable<br>    override fun onScreenCreated() {<br>        showToast(&quot;onScreenCreated&quot;)<br>    }<br><br>    override fun onResume(lifeCycleOwner: LifecycleOwner) {<br>        super.onResume(lifeCycleOwner)<br>        showToast(&quot;onResume&quot;)<br>    }<br><br>    override fun onPause(lifeCycleOwner: LifecycleOwner) {<br>        super.onPause(lifeCycleOwner)<br>        showToast(&quot;onPause&quot;)<br>    }<br><br>    override fun onStop(lifeCycleOwner: LifecycleOwner) {<br>        super.onStop(lifeCycleOwner)<br>        showToast(&quot;onStop&quot;)<br>    }<br><br>    override fun onDestroy(lifeCycleOwner: LifecycleOwner) {<br>        super.onDestroy(lifeCycleOwner)<br>        showToast(&quot;onDestroy&quot;)<br>    }<br><br>    private fun showToast(message: String) {<br>        Toast.makeText(context, message, Toast.<em>LENGTH_SHORT</em>).show()<br>    }<br><br>}</pre><p>and here is my main activity:</p><pre>class MainActivity : AppCompatActivity() {<br>    private val sampleScreen = SampleScreen()<br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        <em>setContent </em><strong>{<br>            </strong>sampleScreen.createScreen(<em>rememberNavController</em>())<br>        <strong>}<br>    </strong>}<br>}</pre><p>we can have BaseNavGraph and BaseComponent(for composable components like Button, Text, …) and manage them better than before.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a97d8befa286" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling app lifecycle events in Jetpack Compose]]></title>
            <link>https://medium.com/@mahdizareeii/handling-app-lifecycle-events-in-jetpack-compose-d3b7f526514b?source=rss-7b76fe3714ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3b7f526514b</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[lifecycle]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Mahdi Zareei]]></dc:creator>
            <pubDate>Thu, 24 Mar 2022 14:08:25 GMT</pubDate>
            <atom:updated>2022-03-24T14:08:25.646Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*-TWezzfSPCu9h3Taj0UOwA.png" /><figcaption>Handling app lifecycle events in Jetpack Compose</figcaption></figure><p>With this function, we can listen to app <strong>lifecycles </strong>in composable function in <strong>Jetpack Compose</strong>, and decide to do something depending on the current lifecycle</p><pre>@Composable<br>fun ComposableLifecycle(<br>    lifeCycleOwner: LifecycleOwner = <em>LocalLifecycleOwner</em>.current,<br>    onEvent: (LifecycleOwner, Lifecycle.Event) -&gt; Unit<br>) {<br>    <em>DisposableEffect</em>(lifeCycleOwner) <strong>{<br>        </strong>val observer = <em>LifecycleEventObserver </em><strong>{ </strong>source, event <strong>-&gt;<br>            </strong>onEvent(source, event)<br>        <strong>}<br>        </strong>lifeCycleOwner.<em>lifecycle</em>.addObserver(observer)<br>        onDispose <strong>{<br>            </strong>lifeCycleOwner.<em>lifecycle</em>.removeObserver(observer)<br>        <strong>}<br>    }<br></strong>}</pre><p>how to use it?<br>for example, I used it in Video Player composable function:</p><pre>@Composable<br>fun VideoPlayer(<br>    videoUrl: String<br>) {<br>    val context = <em>LocalContext</em>.current<br><br>    val exoPlayer = <em>remember </em><strong>{<br>        </strong>ExoPlayer.Builder(context).build().<em>apply </em><strong>{<br>            </strong>addMediaItem(MediaItem.fromUri(videoUrl))<br>            prepare()<br>            <em>playWhenReady </em>= true<br>        <strong>}<br>    }<br><br>    </strong>val playerView = <em>remember </em><strong>{<br>        </strong>StyledPlayerView(context).<em>apply </em><strong>{<br>            </strong><em>player </em>= exoPlayer<br>        <strong>}<br>    }</strong></pre><pre><em>   /**<br>    * here we called that function and we decided to pause <br>    * the video player when app goes to onPause state<br>    */</em><strong><br>    </strong><em>ComposableLifecycle </em><strong>{ </strong>source, event <strong>-&gt;<br>        </strong>if (event == Lifecycle.Event.<em>ON_PAUSE</em>) {<br>            exoPlayer.pause()<br>        }<br>    <strong>}<br><br>    </strong><em>Surface</em>(color = Color.Black) <strong>{<br>        </strong><em>AndroidView</em>(<br>            modifier = Modifier.<em>fillMaxSize</em>(),<br>            factory = <strong>{<br>                </strong>playerView<br>            <strong>}<br>        </strong>)<br>    <strong>}<br></strong>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3b7f526514b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>