<?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 Alen on Medium]]></title>
        <description><![CDATA[Stories by Alen on Medium]]></description>
        <link>https://medium.com/@alen.siljan?source=rss-1bad70b6b687------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Gb0e_msR8NQKqoenVGUY4w.jpeg</url>
            <title>Stories by Alen on Medium</title>
            <link>https://medium.com/@alen.siljan?source=rss-1bad70b6b687------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 01:27:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alen.siljan/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[XML -> Jetpack Compose — should we migrate?]]></title>
            <link>https://medium.com/greypbikes/xml-jetpack-compose-should-we-migrate-99ba8c4a60f5?source=rss-1bad70b6b687------2</link>
            <guid isPermaLink="false">https://medium.com/p/99ba8c4a60f5</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[greyp-tech]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Alen]]></dc:creator>
            <pubDate>Thu, 24 Nov 2022 07:24:24 GMT</pubDate>
            <atom:updated>2022-12-05T08:30:26.291Z</atom:updated>
            <content:encoded><![CDATA[<h3>XML -&gt; Jetpack Compose — should we migrate?</h3><p>Since the dawn of time, Android apps have used XML notation to describe UI. In May 2019, Google announced Jetpack Compose, the first stable version (1.0) was released in July 2021 and the current stable version is 1.2. The first stable version (1.0) was released in July 2021 and the current stable version is 1.2.</p><p>Jetpack Compose is a relatively new way of building native UI on the Android platform. The idea is to simplify and accelerate development by describing UI rather than writing separate .xml layouts for each screen, or even multiple .xml files if you have to have a fragment with a recycler view. From Google documentation: “Compose is Android’s modern toolkit for building native UI.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ocyf19OK13JPnqHUJLS8zg.jpeg" /></figure><p>From this year, Compose 1.0 for wearables is out. You can read more about <a href="https://android-developers.googleblog.com/2022/07/compose-for-wear-os-10-stable.html">here</a></p><p>Some quotes from companies using Compose for some time now:</p><blockquote>Compose <strong>increased our productivity</strong> dramatically. It’s much <strong>easier and faster</strong> to write a Composable function than to create a custom view, and it’s also made it much easier to fulfill our designers’ requirements.<em> [Twitter]</em></blockquote><blockquote>There’s also a significant reduction for any screen built with a RecyclerView, which the majority of our screens are.<em> [Monzo]</em></blockquote><p>What prompted us to try Compose is that our application uses a lot of custom views and we don’t use predefined components for the UI from the material components library so we wanted to check if Compose could really fasten our development effort for building UI, reduce boilerplate code etc.</p><h3>Comparison and examples</h3><p>Compared to XML, Compose is Declarative UI which means that the state of the screen is pre-defined and the UI elements will reload upon any change made to this state. A really simple example is hiding the view. With the current UI toolkit, you would typically use a method like findViewById() to get a reference to the View you want to hide, then call setVisibility() on it. Instead, in a declarative UI, you describe the UI as being visible or not. When you want to change the visibility, you re-run the code describing the UI.</p><p>Our idea was to try Compose in a ‘Proof Of Concept’ project and then possibly decide whether we should start building UI for the new app with Compose or we should stick with XML. We have spent a few sprints ‘playing’ with Compose and will try to give examples of why we believe Compose is better alternative to the standard XML.</p><p>If we want to implement profile section as is shown in the picture below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*V6e5FjUeZt5RfpYzm5PsKw.png" /></figure><p>We could just write a @Composable function and within few lines of code describe UI to achieve design like in the picture above:</p><pre>Column(<br>    modifier = modifier<br>        .verticalScroll(rememberScrollState())<br>        .fillMaxSize()<br>        .padding(8.dp, 16.dp, 8.dp, 16.dp),<br>    horizontalAlignment = Alignment.CenterHorizontally<br>) {<br>    SettingsCard(<br>        title = &quot;Account&quot;,<br>        subtitle = &quot;Antonio&quot;,<br>        items = listOf(<br>            Item(<br>                title = &quot;Change email&quot;,<br>                endItem = EndItem.Icon(R.drawable.ic_arrow_right),<br>                action = {}<br>            ),<br>            Item(<br>                title = &quot;Change password&quot;,<br>                endItem = EndItem.Icon(R.drawable.ic_arrow_right),<br>                action = onClickChangePassword<br>            ),<br>            Item(<br>                title = &quot;Subscription Membership&quot;,<br>                subtitle = &quot;Monthly&quot;,<br>                endItem = EndItem.Icon(R.drawable.ic_arrow_right),<br>                action = {}<br>            )<br>        )<br>    )<br>  }</pre><p>One of the biggest improvements to reducing boilerplate code is when it comes the need to use RecyclerView. Instantiating RecyclerView in XML had a lot of boilerplate code. We needed to have a layout for the item, the ViewHolder and the Adapter and the configuration in the Activity/Fragment. The old way of doing this is:</p><ul><li>Declare your RecyclerView in XML.</li><li>Create your custom views which will be shown in your RecyclerView cell.</li><li>Create an adapter, add OnCreate, OnBind, and other methods to display your cell.</li><li>Finally, bind your RecyclerView with an adapter in your .kt/java file.</li></ul><p>With Jetpack Compose, the need for the boilerplate code is no longer required.</p><pre>@Composable<br> fun SampleContent() {<br>     val data = remember { DataProvider.dummyList }<br>     LazyColumn(<br>         contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp)<br>     ) {<br>         items(<br>             items = data,<br>             itemContent = {<br>                 SampleListItem(it)<br>             })<br>     }<br> }</pre><ul><li>LazyColumn composable is a replacement for RecyclerView and with LazyColumn params we can define padding.</li><li>items() function of LazyColumn Composable takes our data list as first param, and a composable itemContent that takes our list item composable to populate with each item in the list. We just need to create SampleListItem Composable function:</li></ul><pre>@Composable<br> fun SampleListItem(data: SampleData) {<br>     Row {<br>         Column {<br>             Text(text = data.title, style = typography.h6)<br>             Text(text = &quot;VIEW DETAIL&quot;, style = typography.caption)<br>         }<br>     }<br> }</pre><h3>Interoperability</h3><p>It is easily possible to start working with Compose even if the whole project is written in XML. <a href="https://developer.android.com/jetpack/compose/interop/adding">Adding Jetpack Compose to your app | Android Developers</a></p><p>To create a new, entirely Compose-based screen in your activity/fragment call the setContent() method in onCreate() / onCreateView() method, and pass whatever composable functions you like.</p><p>Also, you can add XML views in Composable methods. Add AndroidView() to your composable method and define factory and update parameters. Those define how the XML view behaves.</p><p>More on: <a href="https://developer.android.com/jetpack/compose/interop/interop-apis">Interoperability APIs | Jetpack Compose | Android Developers</a></p><p>Even if you don’t want to start with Compose from the ground up, it is even possible to try to compose on screens that are already written in XML. All we need to do is to insert androidx.compose.ui.platform.ComposeView in the XML layout. Add id to that view and after that find it in your activity/fragment and apply setContent() method.</p><h3>Conclusion</h3><p>Two notes to summarise this story:</p><ul><li><strong>Single source of truth ℹ️ </strong>In Jetpack compose, you can pass the state to your composable functions, and it will observe and update itself accordingly. You don’t need to make any changes to the UI.</li><li><strong>Kotlin friendly 😃 </strong>Jetpack Compose uses Kotlin. So with the help of it, you can easily create your own UI. You can simply decide what to display using if/else or display a list of filtered users using advanced functions of collections. Also, it becomes easier to learn and understand the process.</li></ul><p>Personally, we don’t think XML will be deprecated, but since Google introduced UI toolkit to run just in Kotlin, most likely, within a few years, Compose will be the preferred way of dealing with the UI. Furthermore, Google’s public roadmap for developing Compose is quite positive. In focus for the next release is performance, tooling improvement (such as preview and live edit), etc. Find more information here: <a href="https://developer.android.com/jetpack/androidx/compose-roadmap">Jetpack Compose Roadmap | Android Developers</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99ba8c4a60f5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/greypbikes/xml-jetpack-compose-should-we-migrate-99ba8c4a60f5">XML -&gt; Jetpack Compose — should we migrate?</a> was originally published in <a href="https://medium.com/greypbikes">greypbikes</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>