<?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 Bruno Wieczorek on Medium]]></title>
        <description><![CDATA[Stories by Bruno Wieczorek on Medium]]></description>
        <link>https://medium.com/@bruno.wieczorek?source=rss-1bb07a907334------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Co_KHbKu3tIS__QaQ0dndw.jpeg</url>
            <title>Stories by Bruno Wieczorek on Medium</title>
            <link>https://medium.com/@bruno.wieczorek?source=rss-1bb07a907334------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 07:38:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bruno.wieczorek/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[Two-way data binding in Jetpack Compose]]></title>
            <link>https://proandroiddev.com/two-way-data-binding-in-jetpack-compose-1be55c402ec6?source=rss-1bb07a907334------2</link>
            <guid isPermaLink="false">https://medium.com/p/1be55c402ec6</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[data-binding]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[Bruno Wieczorek]]></dc:creator>
            <pubDate>Sun, 10 Apr 2022 12:42:51 GMT</pubDate>
            <atom:updated>2022-04-10T18:47:20.635Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bRTD8lPxBMnV1rCyv33awA.png" /><figcaption>One-way and two-way data binding in Jetpack Compose</figcaption></figure><p>Jetpack Compose uses a pattern called state hoisting to make stateless composables and move state managing to its parent. The state is being represented by two parameters:</p><ul><li><strong>value: T:</strong> the current value</li><li><strong>onValueChange: (T) -&gt; Unit:</strong> an event that requests the value to change, where T is proposed as the new value</li></ul><p>To bind values to ViewModel, it is common to use libraries that follow Observer pattern (such as Flow in Kotlin). Jetpack Compose offers extension functions that convert Observable into State type supported in composables:</p><ul><li>Flow.collectAsState()</li><li>LiveData.observeAsState()</li><li>Observable.subscribeAsState()</li></ul><h3>One-way binding</h3><p>The typical ViewModel with binding may look as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29350156752e2a75d5c82496c6661719/href">https://medium.com/media/29350156752e2a75d5c82496c6661719/href</a></iframe><p>Composable functions can use such ViewModel to get current value and notify it about value changes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/075b64df2af609c64aeebb4c5271b6c0/href">https://medium.com/media/075b64df2af609c64aeebb4c5271b6c0/href</a></iframe><p>It is nice but requires 3 class members to support binding: callback function, public observable field, and backing field. This type of data binding is called one-way binding, as both callback function and public observable communicate one way — can only read value or change it. I thought that it can be improved by implementing extensions that will allow using two-way data binding similar to Google’s <a href="https://developer.android.com/topic/libraries/data-binding">Data Binding Library</a>, which works for XML files.</p><h3>Solution: Two-way binding</h3><p>I’ve implemented MutableStateAdapter class that allows to convert State&lt;T&gt; to MutableState&lt;T&gt; by adding mutate function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0932fe733a8ef3c9420aa1d6e5197b7/href">https://medium.com/media/c0932fe733a8ef3c9420aa1d6e5197b7/href</a></iframe><p>By using this class, creating any MutableState extensions is very easy. For MutableStateFlow&lt;T&gt; :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81b01ae259f0eb39db4241580f77051a/href">https://medium.com/media/81b01ae259f0eb39db4241580f77051a/href</a></iframe><blockquote>LiveData and RxJava extensions can be found <a href="https://gist.github.com/burnoo/730902ddb31a5b6db5cda65ff0d46fe5">here</a></blockquote><p>Let’s go back to the example. Now 3 class members can be replaced with only one MutableStateFlow&lt;String&gt; field:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3191eb2ca6316c6ceeb75f6c6451c74/href">https://medium.com/media/a3191eb2ca6316c6ceeb75f6c6451c74/href</a></iframe><p>In a composable, the new extension can be used to add two-way binding. It works perfectly with Kotlin’s destructing declarations:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c4a52a4daa3b78c06b8b9c75b989355/href">https://medium.com/media/5c4a52a4daa3b78c06b8b9c75b989355/href</a></iframe><p>As a result, boilerplate code responsible for data binding is greatly reduced in a ViewModel.</p><h3>Next steps</h3><p>I thought about releasing code as a library, but as Adapter and extension are less than 20 lines, I think it would be overkill. If you prefer using a library, let me know in the comments — I could release it ;) It would be nicer though to have those extensions included in androidx.compose.runtime:runtime* artifacts in my opinion.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1be55c402ec6" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/two-way-data-binding-in-jetpack-compose-1be55c402ec6">Two-way data binding in Jetpack Compose</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Koin for Compose proposal (Jetpack and Multiplatform)]]></title>
            <link>https://blog.insert-koin.io/cokoin-injection-library-for-compose-jetpack-and-multiplatform-b041b36cac42?source=rss-1bb07a907334------2</link>
            <guid isPermaLink="false">https://medium.com/p/b041b36cac42</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[koin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Bruno Wieczorek]]></dc:creator>
            <pubDate>Wed, 15 Dec 2021 10:03:05 GMT</pubDate>
            <atom:updated>2021-12-15T11:15:29.190Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UPnOZiAXDrWLjw8J_--61w.png" /><figcaption><em>Graphic by </em><a href="https://www.instagram.com/alechlabicz/"><em>@alechlabicz</em></a></figcaption></figure><p>Jetpack Compose introduced a declarative UI to Android programming. In this framework, each @Composable function is a description of how to display a certain UI. It has inputs (as function parameters) and can manage its state. Each function can be treated as a standalone entity, which can be composed in different places. This behavior is not entirely consistent with modern injection libraries (Hilt, Koin). On Android, injection libraries are initialized in the Application class. Therefore, @Composable functions can only use injection when the Android application is running and not with the @Preview annotation.</p><p>I thought this could be changed and implemented a solution that would allow DI configuration using the @Composable function. Initially, I created a Pull Request to Koin with such an implementation. However, while working on additional elements of the proposed solution, I realized the changes went beyond the size of a single Pull Request. I contacted the creator of the Koin library <a href="https://medium.com/u/9ad99ca649d4">Arnaud Giuliani</a> to ask what to do next, and we decided it would be a good idea to release my implementation as a separate library for now (<a href="https://github.com/burnoo/cokoin">cokoin</a>). This way, it will be possible to collect feedback from users and release quick updates based on that. If the library is accepted by the community, cokoin could become the official Koin solution for Compose.</p><p><a href="https://github.com/burnoo/cokoin">GitHub - burnoo/cokoin: Injection library for Compose (Multiplatform and Jetpack), Koin wrapper.</a></p><h3>Proposal</h3><p>Koin already has a dedicated artifact that allows its usage with Jetpack Compose — io.insert-koin:koin-androidx-compose . Cokoin proposes additional features:</p><ul><li>allows using Koin in a @Preview</li><li>Jetbrains’ Compose Multiplatform support</li><li>@Composable configuration</li><li>@Composable Koin’s Scope support</li><li>separate artifacts for androidx ViewModel and Navigation</li></ul><h3>Setup</h3><p>Cokoin is hosted on MavenCentral. Add the following dependency to your module build.gradle (advanced up-to-date Gradle setup can be found in the <a href="https://github.com/burnoo/cokoin#readme">README of the library</a>):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c5ac5af560005880bb5c700c79bdeb8/href">https://medium.com/media/0c5ac5af560005880bb5c700c79bdeb8/href</a></iframe><h3>Basics</h3><p>Cokoin uses @Composable Koin function to set up Koin :</p><pre>@Composable<br>fun Koin(<br>    appDeclaration: KoinAppDeclaration? = null,<br>    content: @Composable () -&gt; Unit<br>)</pre><p>The first parameter is used to configure KoinApplication . The second parameter is @Composable content within which the injection works.</p><p>@Composable Koin uses <a href="https://developer.android.com/reference/kotlin/androidx/compose/runtime/CompositionLocal">CompositionLocal</a> — Compose’s mechanism to pass data to its children implicitly. It makes the@Composable get function work inside the content:</p><pre>@Composable<br>inline fun &lt;reified T&gt; get(/* ... */): T</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bcf52cb44c33cf34c3596c34ce95f111/href">https://medium.com/media/bcf52cb44c33cf34c3596c34ce95f111/href</a></iframe><blockquote>Note: To learn more about Koin and modules visit <a href="https://insert-koin.io/">Koin documentation</a>.</blockquote><h3>Scopes</h3><p>One of the core functionalities of Koin is <a href="https://insert-koin.io/docs/reference/koin-core/scopes/">Scopes</a> support. In cokoin, Scopes are handled with @Composable wrappers:</p><pre>@Composable<br>fun KoinScope(<br>    getScope: Koin.() -&gt; Scope,<br>    content: @Composable () -&gt; Unit<br>)</pre><p>The getScope parameter uses the current Koin instance as a function receiver, which allows creating a scope using Koin’s function createScope :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3320138f292c3d0bff4c06242d3acd4/href">https://medium.com/media/a3320138f292c3d0bff4c06242d3acd4/href</a></iframe><h3>Backward compatibility</h3><p>The get function uses the context of the nearest @Composable Koin parent. In case it is not there, it uses the global Koin instance. It is useful for adding Jetpack Compose to an existing application where Koin is already configured using the startKoin function in the Application class. This allows Koin modules to be shared between new screens and old ones.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f219d02dfd2efde12e8a5918b3eabc47/href">https://medium.com/media/f219d02dfd2efde12e8a5918b3eabc47/href</a></iframe><h3>Android’s ViewModel and Navigation</h3><p>Cokoin supports androidx ViewModel in dev.burnoo:cokoin-android-viewmodel artifact. The library contains the following function:</p><pre>@Composable<br>inline fun &lt;reified T : ViewModel&gt; getViewModel(/* ... */): T</pre><p>It works very similar to get function. Here is an example usage:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e16c89416e2c2dc21db07682faffdb6c/href">https://medium.com/media/e16c89416e2c2dc21db07682faffdb6c/href</a></iframe><p>Additionally getViewModel has a viewModelStoreOwner parameter that allows scoping ViewModel to a specific graph route from the Navigation Compose library:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b4afe9ebb51e5cf8ea9be069570d83f/href">https://medium.com/media/9b4afe9ebb51e5cf8ea9be069570d83f/href</a></iframe><p>Moreover, cokoin contains the dev.burnoo:cokoin-android-navigation artifact which makes working with Navigation Compose even easier. By replacing NavHost with KoinNavHost one can use two functions:</p><ul><li>getNavViewModel — which returns the ViewModel scoped to the Navigation root, and</li><li>getNavController, which returns the nearest NavHostController .</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e94406af3c4c4c2c296aa8633f6ca89/href">https://medium.com/media/9e94406af3c4c4c2c296aa8633f6ca89/href</a></iframe><p>What do you think about this romance between Koin and Jetpack Compose? Do you like it? Who knows, maybe we’ll see <a href="http://twitter.com/Composable">@</a>Composable fun Hilt(…) one day… ;)</p><blockquote>Note: After writing this article, I discovered that similar Compose support is included in the <a href="https://docs.kodein.org/kodein-di/7.6/framework/compose.html">Kodein-DI library</a>. Check it out!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b041b36cac42" width="1" height="1" alt=""><hr><p><a href="https://blog.insert-koin.io/cokoin-injection-library-for-compose-jetpack-and-multiplatform-b041b36cac42">Koin for Compose proposal (Jetpack and Multiplatform)</a> was originally published in <a href="https://blog.insert-koin.io/">Koin Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java HarmonyOS API for Android developers — cheatsheet]]></title>
            <link>https://medium.com/huawei-developers/java-harmonyos-api-for-android-developers-cheatsheet-9de077561732?source=rss-1bb07a907334------2</link>
            <guid isPermaLink="false">https://medium.com/p/9de077561732</guid>
            <category><![CDATA[huawei]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[harmony-os]]></category>
            <dc:creator><![CDATA[Bruno Wieczorek]]></dc:creator>
            <pubDate>Fri, 15 Oct 2021 10:41:27 GMT</pubDate>
            <atom:updated>2021-10-15T10:41:27.692Z</atom:updated>
            <content:encoded><![CDATA[<h3>Java HarmonyOS API for Android Developers — Cheatsheet</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*naSCCu1g5SmC4N2C6jG8SQ.png" /></figure><p>The HarmonyOS SDK allows you to create an application’s UI in JS and Java. The Java SDK is based on the Android SDK but it differs in multiple places, e.g. in component names. Being an experienced Android developer, you may feel lost among the new API names and subtly changed behaviours. That’s why I decided to list the corresponding components of SDK for Android and HarmonyOS Java in one place. This will allow you to use your Android knowledge while programming your HarmonyOS application.</p><p>Examples are presented in the form of a cheatsheet as thematically divided comparison tables for different parts of the ecosystem.</p><blockquote>The following code is available as a repository:<a href="https://github.com/burnoo/HarmonyOSAndroidCheatsheet"> https://github.com/burnoo/HarmonyOSAndroidCheatsheet</a>. You can report Issues and PRs with missing elements or suggestions there.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01a2da8c20807b83c5678596c1eb5496/href">https://medium.com/media/01a2da8c20807b83c5678596c1eb5496/href</a></iframe><p>As you can see in the tables, programming for both platforms is very similar. Using the search option (ctrl+f or cmd+f) you can find familiar elements from Android and the corresponding HarmonyOS SDK components. I hope this cheatsheet will help you with the development.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9de077561732" width="1" height="1" alt=""><hr><p><a href="https://medium.com/huawei-developers/java-harmonyos-api-for-android-developers-cheatsheet-9de077561732">Java HarmonyOS API for Android developers — cheatsheet</a> was originally published in <a href="https://medium.com/huawei-developers">Huawei Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>