Newsletter Issue #79

Published: 2021-08-24

1.1.0-alpha02 is out with a few changes!

We also look at modifiers and what happens when one depends on another. We take a deeper look at Compose performance, validate some input, and auto-size some text. And, I am worried about Compose-curious developers being able to get the support that they need.

Alpha Announcements

Reviewing the release notes for the latest Jetpack Compose update!

Among other improvements, 1.1.0-alpha02 brings us:

  • The ability for PointerEvent to capture the state of mouse buttons and keyboard modifiers (e.g., Shift)

  • A new DpSize class, used with a new DpRect() constructor and new variants of the size() and requiredSize() modifiers

  • New scale-based enter and exit transition support

One Off the Stack, One Off the Slack

You’ve got questions. That’s understandable!

Where Did My Modifier Go?

Copying and pasting Compose code from before the 1.0.0 stable release is especially risky, as the API changed quite a bit over the preceding 18 months. One developer learned that lesson the hard way, when dealing with the old preferredSize() and preferredHeight() modifiers, in this week’s highlighted Stack Overflow question.

Issues with Dependent Modifiers

Modifiers are applied in a sequence. This poses an issue if one modifier depends on another modifier having already been applied — if those modifiers are used out of sequence, you might run into problems. focusable() and focusOrder() exhibit this dependent behavior, as we see in this week’s highlighted Kotlinlang #compose Slack thread.

Composable Commentary

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

Measuring Render Performance with Jetpack Compose

Will Shelor wanted to know whether using Compose UI was faster or slower at runtime than was equivalent View-based code. As we saw in last week’s issue, Compose’s performance is dependent both on using R8 and on having the app’s code be compiled ahead of time (AOT). Will’s analysis shows how you can perform those sorts of measurements for your own Compose UI scenarios.

Video: State and Performance in Jetpack Compose

Ivan Morgillo and Sebastiano Poggi have been livestreaming some Compose UI experiments under the “Code with the Italians” moniker. In this episode, they are joined by Google’s Leland Richardson. Among other things, Leland takes a deep dive into measuring performance, in particular examining the results reported by Will Shelor in the blog post from the previous entry and emphasizing what one needs to get a good picture of how your composables are performing.

Medium: Input Validation in Jetpack Compose

Denis Rudenko returns with an overview of how to apply validation logic to what the user enters into a TextField(), how to display those errors to the user, and how to ensure that the error information and the user-entered text survives configuration changes and short-term background process termination.

Medium: Jetpack Compose Canvas

Vikas Kamur gives us a series of demonstrations of drawing custom artwork on a Canvas(), giving us composables that reproduce the icons of Google Photos, Instagram, and more!

Medium: Animation on LazyColumn the RecyclerView Equivalent

Alex Briano examines how we can perform animated changes of a LazyColumn() item from one state to another, replacing the typical “smash cut” transition that most apps settle for.

Build Live Text on Android

Peng Jiang wanted a UX akin to iOS’ Live Text: from an input field, you can request to grab an image off the camera, use OCR to identify text from that image, and paste that into the field. To accomplish this, Peng used CameraX and a Huawei OCR library, along with Compose UI.

Resource Roundup

100% pure code!

Gist: bmc08gt / AutoSizeText.kt

Brandon McAnsh created an AutoSizeText() composable that wraps a Text() composable and decreases the font size as needed to allow the text to fit either the requested width or height.

Gist: Aidanvii7 / NavGraph.kt

Aidan McWilliams brings us an example of how to use Parcelable arguments when implementing navigation using Navigation for Compose, by automatically putting those arguments into the Bundle associated with the NavBackStackEntry.

GitHub: emenjivar / credit-card-compose

Carlos Menjivar implemented a nice CreditCard() composable, to render the front or back of a virtual credit card, using information like the issuing bank, card number, and more.

…And One More Thing

Now that Compose has a stable release, there will be a steady influx of developers who wish to use it. The challenge that poses is: where will they get help?

Right now, the best source of help for developers is Kotlinlang Slack’s #compose channel. That was set up shortly after Google released the first developer preview of Compose, and Google engineers and developer advocates have spent a lot of time there. Many developers have received deep and excellent advice there.

However, there are problems with the solution.

Some of those problems are endemic to Slack. Slack is like Las Vegas: what happens in Slack, stays in Slack. Slack’s search facility is nearly useless, and Slack’s “walled garden” approach means that it is not indexed by public search engines. This means that the value of any advice decays rapidly: mostly, it helps people who happen to be following the #compose channel at the time the advice is given. That is why I have been “rescuing” a thread per week in the “One Off the Slack” series — I am simply trying to ensure that some of the great advice gets into public search engines.

Beyond that, there is the risk that Google’s involvement may tail off. This would not be that surprising — getting two years of near-real-time official support was a minor miracle. With luck, the developer ecosystem can help fill in. However, this sort of transition from company-led support to community-led support is risky. This is exacerbated by Slack’s limitations — if community members tire of dealing with duplicate questions caused by lousy search options, it is possible that the channel will fade into obscurity.

If you know of Compose support sites, beyond the #compose Slack channel and Stack Overflow, please let me know. I would love to be able to promote other options, so developers have more choices for where they can get the answers that they need.