jetc.dev Newsletter Issue #153

Published: 2023-02-14

This week, we look at the latest updates to Compose, including the rarely-mentioned TV project.

We also explore modifier order and coding styles. We cope with wonky touch events, work with effects, and secure our dialogs against screenshots. And we capture signatures, perhaps as part of an overall form.

Ooooo… What Did We Get?

Reviewing the release notes for the latest Jetpack Compose update!

Compose Compiler is up to 1.4.2, with support for Kotlin 1.8.10.

Compose Runtime Tracing is up to 1.0.0-alpha02, though it is unclear if any tooling exists to use it.

In terms of Compose itself, we are up to 1.4.0-beta01, which suggests that we will get a 1.4.0 stable release well before the traditional Google I|O timeframe. We now have access to a ComposeNodeLifecycleCallback to find out the lifecycle of composition nodes. However, beyond that, the changes were mostly some minor renames of things and a few new experimental test APIs.

Wear Compose got a 1.4.2 patch release to fix an optimization issue with ScalingLazyListState.centerItemIndex. We also got a 1.2.0-alpha04 release, with a new PickerGroup() to, um, group pickers.

Also, the slowly-simmering TV project is up to 1.0.0-alpha04. It appears as though this library is focused on Material3, as androidx.tv.material was renamed to androidx.tv.material3.

One Off the Stack, One Off the Slack

You’ve got questions. That’s understandable!

How Can I Have Both a Border and Padding?

A general rule in Compose UI work: if you aren’t getting what you want, try shuffling the order of modifiers around. In this case, the order of applying a border and applying padding matters a great deal, as we see in this week’s highlighted Stack Overflow question.

Why Do Compose Coding Styles Differ from Kotlin’s?

Coding styles are not just a product of a programming language — sometimes, frameworks have their own styles that differ from the language norm. In Compose’s case, that is best illustrated with the role of the trailing lambda. See why Compose’s “this is where the child composables go” style differs from the “this is my primary event listener” style you might use elsewhere in this week’s highlighted Kotlinlang #compose Slack thread.

Composable Commentary

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

Video: From data to UI: Compose phases - MAD Skills

Google’s Jolanda Verhoef looks at the three phases of Compose UI rendering: composition, layout, and drawing. Jolanda explains the role of each phase, what goes on in that phase, and how your composables and modifiers fit in. This is also covered in the associated Medium post

Hundreds of thousands of developers are learning Jetpack Compose

This is a promotional piece put out by the Android team, describing the Compose Camp series and how it helped developers get up to speed on Compose UI.

Space Hoisting: Should I use the padding Modifier or the Spacer composable?

Vinay Gaba is back, gazing into the depths of space… er, sorry, make that Spacer(). Vinay compares and contrasts Spacer() with using the padding() modifier, showing the differences between them. Vinay also describes his approach of “space hoisting”, moving decisions of the space between screen components to the screen itself, rather than having components be aware of inter-component spacing.

Medium: Beware of this pitfall in Jetpack Compose!

While the title is rather clickbait-y, The Android Developer has written an interesting post. The pitfall in question is the impact of overlapping composables on touch events. Creating a screen that overlays another screen is easy enough… until you realize that your touch events are passing through gaps in the top screen to the bottom one.

Writing cleaner Jetpack Compose code with the Twitter Compose Ruleset

Tristan Elliott looks at applying Twitter’s ktlint rules to your Compose project, and what sorts of coding mistakes they catch.

Everything you need to know about Side Effects in Jetpack Compose with examples

Alex Styl returns, looking at effects, from LaunchedEffect() through SideEffect() and DisposableEffect(). Alex also points out how you might be able to avoid the need for an effect, plus how to get your hands on a suitable CoroutineScope for use in your composables.

Jetpack Compose: Converting Traditional Android Views into Reusable Composables

Skyler De Francesca looks at leveraging AndroidView() to turn a legacy View into a composable. While the samples explore wrapping TextView(), the same techniques can be applied to more likely candidates, such as video players (e.g., ExoPlayer).

Medium: Securing Sensitive Information on Jetpack Compose’s AlertDialog: Preventing Screenshots

Kamran Shahid covers a topic near and dear to me: how to secure composables against screenshots. Compose windows and dialogs can employ a SecureFlagPolicy, which maps to the venerable FLAG_SECURE approach in Compose for Android.

Resource Roundup

100% pure code!

GitHub: JoelKanyi / ComposeSignature

Joel Kanyi is back, this time with a library to help you collect written signatures in a drawing area, then capturing the result as an ImageBitmap for later use.

GitHub: alessiocameroni / pixely-components

Alessio Cameroni is assembling a library to fill in Material3 components that are missing from Compose Material3 or are limited in some way. Right now, the library includes things like SectionTitle(), DropDownMenuTitle(), and SupportInfoText().

GitHub: benjamin-luescher / compose-form

Benjamin Lüscher created a library to simplify the creation of typical vertically-oriented forms, complete with form validation. See this Medium post for more!

GitHub: ningyuv / CircularSeekBar

GitHub user ningyuv created a circular seek bar, with control over colors, start/end angles, line weight, dot size, and more!