jetc.dev Newsletter Issue #59
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!
A popular UI pattern involves horizontally-scrolling carousels in a vertically-scrolling
container. One approach that developers have used for that is having nested
instances. A similar solution in Compose UI is to have a
LazyRow() nested in a
as we see in this week’s highlighted Stack Overflow question.
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.
Posts, videos, and other new information related to Jetpack Compose!
Zach Klippenstein examines what really happens when we change some
in a composable. What all gets recomposed when this happens? Along the way, Zach
inline functions, recompose scopes, and why being wrong is just fine.
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 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
The associated GitHub project
contains the complete example.
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?
Carlos Mota walks us through the adjustments that we need to make to our
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.
Other Interesting Links
- Jetpack Compose — Pendulum Effect
- Animating the Compose Galaxy
- The evolution of writing modern mobile apps
- Video: Creating Your First Jetpack Compose App - Android Jetpack Compose - Part 1
100% pure code!
Siddhesh Patil brings us a library of stock colors implemented as
GradientMixer family of functions that simplify applying colors to standard
gradient fills (e.g.,
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!
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
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.
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
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.
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.
- 2021-07-20: rc02! Preview and ViewModel, together again! Coil supports Compose! MVI! @dequesystems on accessibility! Screenshots of composables! D-pad support! And... Context code smells?!?
- 2021-07-13: Focus! Viewports! Navigation! @divyajain2405 talks about architecture! Screenshot testing! Sliders! Reorderable lists!
- 2021-07-06: RC01! Navigation! Phones *and* tablets! Cards! Timers! Barcodes! And... the