Erik Westenius | KotlinConf 2024, May 22–24, Copenhagen
all speakers

Erik Westenius

Erik Westenius

Senior Android Engineer at Bontouch

Senior Android engineer at Bontouch with over 10 years of professional Android Experience. In love with Jetpack Compose since early alpha! Currently working as Android Lead in the SJ (Swedish Railways) App Team.

Jetpack Compose beyond the UI using Molecule

With the advent of Jetpack Compose UI, it has become easier than ever to create elegant, dynamic user interfaces for our applications. However, Jetpack Compose's capabilities extend beyond UI creation. This talk aims to show how you can harness the power of Jetpack Compose for other parts of your applications using a framework called Molecule. Molecule is a framework that lets you build Flow streams using Jetpack Compose. This may not sound like much but it opens up a whole new frontier for using Jetpack Compose.

In this talk we will explore our learnings of using Molecule in a major refactoring of the Swedish Railways (SJ) app during the past year.

We will start off with an introduction to molecule and then move on to exploring how we can leverage Jetpack Compose and Molecule in our presentation layers. This part will show how to combine multiple reactive streams in a manner that is more maintainable and easier to test than the common flow combine function. We will also explore using LaunchedEffect for side effects and periodic updates using real world scenarios. We will end this section by discussing gotchas related to handling hot flows.

Next, we will push the boundaries and test the limits of Molecule by trying to rewrite a repository. Can you represent a network request by a composable? How would you handle errors and retries? How do you share data between Molecule flows? This talk will be concluded by discussing some architectural pitfalls we stumbled upon during our adventures.