jetc.dev Newsletter Issue #52
Published: 2021-02-16
alpha12
is out… and there may be a beta just around the corner!
So, this week, we look at the wave of changes dumped on us via alpha12
, including
some undocumented adjustments that we need to make. We peek at
typography, action bars, and scaffolds. We see another image-loading library and place a (fake)
order at McDonald’s. And, you might be interested in a petition for changing some package names.
Also, thanks to those of you who responded to my call for feedback in the previous issue!
One Off the Stack, One Off the Slack
You’ve got questions. That’s understandable!
Ack! setContent() Is Broken!
This past week’s Compose release was a bit bumpy. They told us to switch to
setContent()
from androidx.activity:activity-compose:1.3.0-alpha01
… and then things immediately
broke. Google’s Ian Lake steers us to 1.3.0-alpha02
in this week’s highlighted
Stack Overflow question.
How Big Are We?
Sometimes, your composable’s size will dictate what you want in terms of its contents. Depending on your scenario, there are a few possible solutions for this, as we see in this week’s highlighted Kotlinlang Slack thread!
Alpha Analysis
Reviewing the release notes for the latest Jetpack Compose update!
Compose Runtime alpha12 Release Notes
setContent()
on Activity
was moved out of the main Compose dependencies and
into androidx.activity:activity-compose
. Ambient
is now CompositionLocal
,
and anything prefixed with Ambient
(e.g., AmbientContext
) is now Local
(e.g.,
LocalContext
). Similarly, ambientOf()
is now compositionLocalOf()
. Also,
Recomposer.current()
was removed outright.
Compose Foundation alpha12 Release Notes
If you were using savedInstanceState(...)
or rememberSavedInstanceState()
,
they are now changing to rememberSaveable { mutableStateOf(...) }
. This includes
an artifact change from androidx:compose:runtime:runtime-saved-instance-state
to
androidx:compose:runtime:runtime-saveable
.
ImagePainter
is now BitmapPainter
. LazyColumn()
and LazyRow()
now have an
option for custom keys for helping to remember()
state even after rows/columns change
position. imageResource()
, loadImageResource()
, vectorResource()
, and loadVectorResource()
were all deprecated, replaced by painterResource()
. If you were using the
clickable()
modifier for long clicks, check out combinedClickable()
. The
dragGestureFilter()
modifier was deprecated, replaced by either draggable()
or
pointerInput()
. The scaleGestureFilter()
modifier has been removed, replaced by
either zoomable()
or pointerInput()
. ConstraintLayout
has been moved from
a main Compose dependency to androidx.constraintlayout:constraintlayout-compose
.
The tapGestureFilter()
, doubleTapGestureFilter()
, longPressGestureFilter()
, and
pressIndicaitonGestureFilter()
modifiers have been deprecated, replaced by
pointerInput()
.
From a testing standpoint, note that hasText()
now checks both the input value
and any hint or label in a text field.
There is a lot more in the release notes — be sure to review them for things that you might be using!
Compose UI alpha12 Release Notes
Bounds
is now DpRect
and IntBounds
is now IntRect
.
viewModel()
has been moved out of a main Compose
dependency and into androidx.lifecycle:lifecycle-viewmodel.compose
. If you were
still using BaseTextField()
, that was removed — switch to BasicTextField()
.
Compose Material alpha12 Release Notes
DropdownMenu()
was overhauled. TabDefaults
is now TabRowDefaults
. Tab()
and BottomNavigationItem()
now support enabled/disabled states.
Composable Commentary
Posts, videos, and other new information related to Jetpack Compose!
droidcon Online Webinar: Exploring Advanced Jetpack Compose Features
On 18 February (two days away!), droidcon will be holding a webinar on Compose and Compose UI, delivered by Filip Babić. Registration is free!
Petition: Rename Compose Packages
Louis CAD set up a Change.org petition, asking Google to remove androidx
from
the package names for Compose and Compose UI. The argument is that these will
be used in other platforms besides Android, such as for Compose for Desktop,
and that the Android-y package name might put off some developers.
Jetpack Compose: Theme and Typography
Alex Zhukovich is back, this time with a look at MaterialTheme()
and how it
implements the Material Design patterns for colors and font sizes and families.
On (De)composing Action Bars
Thomas Künneth continues his Compose UI explorations, this time looking at Scaffold()
and TopAppBar()
for implementing an action bar/app bar, including dealing with
the dueling bars that you might get courtesy of your Android theme selection.
Video: Composables Under the Hood
Thomas Künneth also delivered a presentation for DevFest DACH, giving us a deeper
dive in how to render custom widgets and effects in Compose UI, using Canvas
,
custom modifiers, and similar techniques.
Building a User Interface with the Backdrop Scaffold
While Scaffold()
dominates Compose UI samples, it is not the only scaffold option.
Here, Joe Birch takes a look at BackdropScaffold()
, a scaffold that offers two
layers: a back layer for actions and a front layer for content.
Parallax Effect Made it Simple with Jetpack Compose
A parallax effect is where the foreground scrolls more rapidly than does the
background. Julien Salvi experimented with implementing that sort of
effect in Compose UI, eventually settling upon the graphicsLayer()
modifier
to achieve the desired effect.
Loading Image in Android Jetpack Compose Made Easy
Elye returns with a look at the various options for getting an image into an
Image()
. Unfortunately, alpha12
already broke some of the recommendations
(e.g., imageResource()
is now deprecated), though the general concepts in this
post are still useful.
Video: Compose by Example
Google’s Nick Butcher presented at droidcon Italy 2020 about Compose, reprising one of his presentations from earlier in 2020. Note that while the video is new, droidcon Italy was held in late November 2020, and Compose/Compose UI has evolved since then. The general advice in the presentation remains good, but the API details will be a bit off in spots.
Notes on the Jetpack Compose alpha11 to alpha12 Upgrade Process
Upgrading from alpha11
to alpha12
is more awkward than are a lot of Compose
alpha updates. In this post, I review the steps that I took to upgrade some samples
and get them working with alpha12
, including the annoying “only available since Kotlin 1.4.30 and cannot be used in Kotlin 1.4”
IDE warning.
Resource Roundup
100% pure code!
GitHub: alialbaali / Kamel
Ali Albaali brings us another contender for image loading in Compose UI. This one happens to work with Kotlin/Multiplatform and so might be a candidate for Compose for Desktop apps.
GitHub: carotkut94 / ScrcpyUI
scrcpy is a popular “projector” app, one that shows the contents of an Android device in a window on your desktop OS. This utility is great for demos and presentations, and it has a dizzying array of command-line switches to configure its operation. Sidhant Rajora is working on a Compose for Desktop client for identifying connected devices and launching scrcpy for you.
GitHub: hitanshu-dhawan / McCompose
Hitanshu Dhawan has created a fairly elaborate demonstration of an app for McDonald’s, rendered using Compose, complete with light and dark themes and adding items to an order. Alas, it uses hard-coded fake data, so you will not be ordering a Shamrock Shake using it.
…And One More Thing
Issue #27, back on August 18th,
pointed out a Gerrit entry that set a Compose version of 1.0.0-alpha02
. Two
weeks later, I was writing about the first alpha release.
This past week, we got another Gerrit entry,
bumping a future version to 1.0.0-beta02
. This suggests that, before the end
of February, we will get 1.0.0-beta01
.
That feels rushed.
Google’s long-standing statement, across all sorts of libraries, is that “beta = production-grade”,
just with a bit more API fluidity. Yet, as we see in the alpha12
release, we are still deep
in major renaming and refactoring and are still making other fundamental API changes.
There are over 250 outstanding bug reports, just in the public issue tracker, including around 20 added in the past week. That is on top of the confusion we are seeing in other channels.
Personally, upgrading to alpha12
was aggravating.
This still feels like an alpha. So, why the apparent rush to brand it as beta?
We know that an Android 12 developer preview/beta/whatever is likely to come out shortly. Frequently, in the past, this has also coincided with releasing new IDE versions.
So, my guess is that Compose is moving to beta to be a part of all of this launch stuff.
Perhaps the Gerrit entry is not a “leading indicator” of a pending beta release, and Compose will get a few months more of alphas first. Or, perhaps Google will backpedal from their standard “beta = production-grade” claims with respect to Compose and recommend that developers wait for a stable release.
But, as the saying goes, “you only get one chance to make a first impression”, unless you have a neuralyzer in your jacket pocket. My fear is that if Google puts out a major initiative to get developers to start using Compose in its current state, that first impression will not be good.
Compose is the long-term direction for Android UIs — that much is clear. However, there should be no rush to get to that long-term direction.
Get it right, then get it popular. The other way around probably does not work.
Or, you can subscribe to the Atom feed or follow Mark Murphy in the Fediverse.
Recent Issues:
- 2024-11-12: @cbruegg@mastodon.green on Compose 1.7 and compatibility! @eevis@mas.to on rendering text in a Canvas! @sinasamaki@androiddev.social and a centered slider! @touchlab@mastodon.social with a Compose-Swift bridge! And... is NavigationSuiteScaffold() FAB?!?
- 2024-11-05: Compose patch release! Compose alpha! 2025 Compose Multiplatform plans! Glance! Side panels! @theapache64@androiddev.social on performance! Tables! And... reacting to a broadcast from a composable?!?
- 2024-10-29: Relay! Paparazzi! droidcon Lisbon 2024! Server-defined UI! And... desktop OS trays?!?