Newsletter Issue #123

Published: 2022-07-05

Two sets of releases came out this week for Compose, including one with support for Kotlin 1.7.0!

Beyond that, we look at what droidcon SF 2022 had to offer, what “stability” means in the world of Compose, and how to apply AnimatedContent(). We explore shared element transitions and permission flows. And I’m grateful for the new stable Compose Compiler and what that means for Compose development going forward.

NOTE: This newsletter will not be published next week, as I take a week off for the summer (Northern Hemisphere edition). The next issue after this one will be out in two weeks (July 19/20, depending on where you are).

RC Reflections

Reviewing the release notes for the latest Jetpack Compose update!

The updates this week were complicated.

Compose Compiler is out with a 1.2.0 stable release. That contrasts with the rest of Compose, which is on 1.2.0-rc03. This is because Compose library versions are starting to become independent — more on this later in the newsletter. Of note, Compose Compiler 1.2.0 supports Kotlin 1.7.0.

While 1.2.0-rc03 seems to contain only a few bug fixes, we also got 1.3.0-alpha01 of the Compose libraries. Of note:

  • LookaheadLayout adds a “lookahead” pass through the composition before the regular measure-and-layout pass. This can help with animations, such as shared element transitions.

  • AnnotatedString now supports a UrlAnnotation, with an eye towards accessibility for links.

  • WindowInfo.keyboardModifiers lets us observe a flow of states for keyboard modifiers (e.g., Shift)

Also, Wear Compose has 1.1.0-alpha01, with some improvements for Picker() accessibility and Chip gradients.

One Off the Stack, One Off the Slack

You’ve got questions. That’s understandable!

How Do We Both Rotate and Fill?

TL;DR: rotate() does not do what you might think, and that can cause problems.

Where Do Composables Get Drawn?

If you have ever looked at Compose Material composables, they are composables calling composables calling composables calling yet more composables. At some point, though, something somewhere has to be drawing some pixels, right? Learn where that code resides in this week’s highlighted Kotlinlang #compose Slack thread.

Droidcon San Francisco 2022

A bunch of great Compose and Compose UI presentations were included as part of droidcon San Francisco 2022, including:

Composable Commentary

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

Independent versioning of Jetpack Compose libraries

Google’s Jolanda Verhoef wrote the announcement post about how the Compose artifacts will now be independently versioned for make it easier for you to incrementally update your app. The first such independently-versioned artifact is the Compose Compiler, where you can use 1.2.0 (and its support for Kotlin 1.7.0) while using 1.1.0 of other Compose artifacts.

Jetpack Compose Stability Explained

Google’s Ben Trengrove walks us through the concept of “stability” in Compose, including using compiler reports to help identify stability gaps and how to replace unstable types with stable counterparts. The net result: Compose can do a better job of skipping unnecessary recompositions, improving your app’s performance.

Customizing AnimatedContent in Jetpack Compose

Google’s Rebecca Franks contributed another post on animation, this time examining the experimental AnimatedContent() composable for things like transitions between two screens and a custom transitionSpec to tailor how those transitions get animated.

Video: How to add a map to Android apps with Jetpack Compose

The Google Maps team created a short video to introduce you to their Maps Compose library and show you how to use it in your Compose UI apps.

Get String resources in Jetpack Compose Tests

Alex Zhukovich explains how we can use createAndroidComposeRule() to write tests where we have ways of getting the values of string resources in test code, for use in comparing with text rendered by our composables.

How to Customize Status Bar in Jetpack Compose?

The SemicolonSpace team looks at using Accompanist’s SystemUiController to get at our system bars and use that to customize the color of the system bar and the navigation bar. They also explore hiding those bars and displaying content behind those bars.

Building Accessible Android Apps with Jetpack Compose: Real-Time Examples

Devanshu Chandra walks us through using role, semantics(), label, contentDescription, and more to add accessibility information to your Compose UI apps.

Medium: Schedule Image Displaying In Glance Widget With Work Manager API

Frequently, our app widgets need to be updated in the background periodically. Ahmed Samir demonstrates how to accomplish this with a Glance-powered composable app widget, using WorkManager for periodically hitting a Web service using Retrofit.

Improving shared architecture for a Kotlin Multiplatform, Jetpack Compose and SwiftUI app

Marco Gomiero has been experimenting with Kotlin/Multiplatform; he wrote a couple of years ago about setting up the shared architecture. In this new post, Marco reports on efforts to improve the implementation, including how to use Flow in Swift and how that simplified the shared use case and the platform-specific viewmodels.

Resource Roundup

100% pure code!

GitHub: skydoves / Orbitary

Jaewoong Eum brings us a library to help simplify shared element transitions and other animations, via rememberContentWithOrbitaryScope() and an Orbitrary() composable.

GitHub: PatilShreyas / permission-flow-android

Shreyas Patil is back, this time with a library that allows you to subscribe to updates to permission availability via StateFlow, to make it easier to write composables that render differently depending on whether or not you have a particular permission.

GitHub: magneto3572 / Magotp

Bishal Singh brings us another composable implementation of a PIN or OTP code entry widget. This one supports both filled and outlined styles, along with a variety of other look-and-feel customizations.

…And One More Thing

This week’s announcement that Compose libraries will be versioned independently on the whole should be a positive development. In particular, decoupling the Compose compiler version from the runtime library versions will help with the ever-present “hey, when will Compose support such-and-so Kotlin version” — we see the first example of that with this announcement.

Ordinary developers will need to keep track of which library versions work with which other library versions. That will be particularly important for those who use pre-release versions, as they might not necessarily work well with stable releases of other Compose libraries. While transitive dependency declarations mean that you should get the right versions of the libraries automatically most of the time, you might find that you wound up with newer versions of some Compose libraries than you expected.

Hopefully, this will not impact developers of third-party libraries too much. It will be important that they document their Compose version expectations, particularly where they are unusual. For example, Jaewoong Eum did that with Orbitary, noting how it relies it relies on some pre-release library versions.

Overall though, independent versioning, particularly of the Compose compiler, is a sign that the Compose system is maturing, IMHO. I’m sure that the Compose developers would have loved to have been at this state with the initial stable release, but we don’t always get what we want. And while we may stub our toes from time to time with changes like this, that’s a price we pay with any transition, and one that experienced developers are very used to.