jetc.dev Newsletter Issue #59

Published: 2021-04-06

This week, we explore carousels and ColorStateList counterparts, snackbars and search bars, plus navigation and news. We see an easy color/gradient composable library, and I try to put deprecation fears in their place.

Plus, Zach Klippenstein answers the question that we all have: what the heck is going on here?

One Off the Stack, One Off the Slack

You’ve got questions. That’s understandable!

What is the Nested RecyclerView Equivalent?

A popular UI pattern involves horizontally-scrolling carousels in a vertically-scrolling container. One approach that developers have used for that is having nested RecyclerView instances. A similar solution in Compose UI is to have a LazyRow() nested in a LazyColumn(), as we see in this week’s highlighted Stack Overflow question.

What Replaces ColorStateList?

Sometimes, you want to control colors based on interactions, such as controlling the color used for the pressed state of a button. That is one of those places where Compose UI offers flexibility at the cost of complexity. But, we cut through the options to get to a likely solution, in this week’s highlighted Kotlinlang #compose Slack thread.

Composable Commentary

Posts, videos, and other new information related to Jetpack Compose!

Scoped Recomposition in Jetpack Compose — What Happens When State Changes?

Zach Klippenstein examines what really happens when we change some State in a composable. What all gets recomposed when this happens? Along the way, Zach looks at inline functions, recompose scopes, and why being wrong is just fine.

Implementing Snackbar to Undo Actions in Jetpack Compose

The standard Material Design “snackbar” component offers the option of having an associated action, typically “undo” to revert whatever just occurred that triggered the snackbar. Igor Escodro takes a look at how to add an action to a Compose Material snackbar, including how we use coroutines to find out when the user clicks on the action, so we can react accordingly.

Using Compose Beta on AS 4.1

Using canary builds of Android Studio can be aggravating. For a while, we had no choice if we wanted to experiment with Compose UI. Marcello Galhardo decided to do something about that, writing up the recipe to get basic Compose development (sans previews) going in Android Studio 4.1.x.

One thing that we are going to need as we start to apply Compose UI are next-level composables, ones that wrap up popular patterns, beyond those supplied by Compose Material. Paulo Pereira explores one such pattern: the search bar. Specifically, Paulo looks into what it will take to add an auto-complete drop-down, using an animated LazyColumn(). The associated GitHub project contains the complete example.

Video: Unidirectional Dataflow

Alexander Koufatzis delivered a presentation on unidirectional data flow architectures and how they can drive UI, both in iOS (with Swift UI) and Android (with Compose UI).

Modular Navigation with Jetpack Compose

Joe Birch is back, with a deep dive at how Navigation for Compose works when you have your composables spread across modules. How do you set up your nav graph, its routes, and its viewmodels when your composables might need to navigate across your modules?

Video: Firebase with Jetpack Compose - Cloud Firestore

All Techies returns, this time with a brief screencast on using Firestore to drive the content of a Compose UI-based app.

Re-gaining orientation #4

Thomas Künneth wraps up his look at screen orientation and foldables, this time exploring how to avoid rendering content in non-displayable areas, such as the hinge region in a foldable.

Getting Your BottomSheetScaffold Working on Jetpack Compose Beta 03

Carlos Mota walks us through the adjustments that we need to make to our BottomSheetScaffold() to get it to work in the first few Compose Material beta releases. As with many recent changes, the problems boil down to applying animations via coroutines and getting those scoped properly.

Resource Roundup

100% pure code!

GitHub: patilsiddhesh / Holi

Siddhesh Patil brings us a library of stock colors implemented as Color constants, plus a GradientMixer family of functions that simplify applying colors to standard gradient fills (e.g., topRightToBottomLeft(), radial()).

GitHub: rooparsh / DarkNews

Rooparsh Kalia created a sample Kotlin/Multiplatform news-reader project, with Swift UI and Compose UI front ends, backed by Ktor and coroutines.

Gist: bmonjoie / CircularRevealAnimation.kt

Benjamin Monjoie created a CircularReveal() composable that animates a state change (for whatever state you like) using, well, a circular reveal. See this tweet for a screencast!

GitLab: compose1 / livecanvas-poc

Timo Drick is experimenting with compiling composables from source in real time. This demo Compose for Desktop project allows you to replace the body of a LiveCanvas() composable, with the modified Kotlin script compiled and re-executed on the fly to update a desktop window.

…And One More Thing

Google has a long and convoluted history with deprecations.

Starting with AbsoluteLayout – deprecated a scant year after Android’s launch – Google wields the deprecation hammer strangely. Sometimes, they deprecate things without the replacements being ready, such as when they deprecated startActivityForResult() when the ActivityResult API was still in alpha. Sometimes, they deprecate things, then keep revising them, such as AnalogClock getting new methods in Android 12 Developer Preview 2.

So, when gag images claiming that Jetpack Compose was deprecated started making the rounds on April 1… well, let’s just say that we could not completely rule out the possibility.

Note that there is no sign that Compose is deprecated… yet.

However, when you step back and think about it, there is no question that at some point, Jetpack Compose is going to be deprecated or otherwise discontinued. It is possible that we will be writing Compose-based UIs in 25 years, but I would not count on it. Change is all but inevitable, and while Compose could be “the end of the line” in terms of user interface development evolution, it seems unlikely.

Will Compose be deprecated in, say, five years’ time? Probably not. There is ample flexibility in the system to adapt to change, and Google has invested a ton in its development. Combine that with JetBrains’ nascent adoption of Compose (see: Compose for Desktop), and it is likely that Compose is “too big to fail” any time soon.

Besides, you have to take into account which gets deprecated first: Compose… or your own app. Many apps have short “shelf life” and get discontinued or abandoned quickly. Compose has a good chance of outliving whatever it is that you are working on right now. Such as, say, a newsletter issue.

However, if you are working in a domain where software is expected to be maintained over decades, then you need to take care to plan ahead to a time when Compose is no longer being maintained. Perhaps some firm will offer to maintain Compose on behalf of paying clients. Perhaps the open source community will be able to keep up with Compose for a while. Or perhaps you will need to consider alternative UI implementations, whether still using Kotlin or as a port to whatever is the “flavor of the month” in software development at that time.

Just because Jetpack Compose was not deprecated this April Fool’s Day does not mean that it is deprecation-proof. Its time will come, just not very soon. Probably.