jetc.dev Newsletter Issue #133

Published: 2022-09-20

This week, Google warns us that we may be using TextField() wrong. 😮

Google also suggests that we should be thinking in Compose but… what if that leads us to use TextField() wrong?!? 😱

Beyond that, we look at accessibility and paging, we draw some waveforms, and we look at an undo system for letting users correct errors!

(really, though, that seems superfluous — I, for one, nevre maek typose 😁)

One Off the Stack, One Off the Slack

You’ve got questions. That’s understandable!

How Do We Recompose When Clipboard Contents Change?

There are lots of ways to map platform callbacks to State that can trigger recomposition. See two approaches — using DisposableEffect() and using a viewmodel — for recomposing on clipboard changes in this week’s highlighted Stack Overflow question.

Are State Holders Useful?

Some developers really dislike composables with lots of parameters, which is understandable. Sometimes, they try bundling a bunch of would-be-parameters into more coarse-grained objects, to reduce the parameter count. See an example, and arguments against the approach, in this week’s highlighted Kotlinlang #compose Slack thread.

Composable Commentary

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

Medium: Effective state management for TextField in Compose

Google’s Alejandra Stamato points out that BasicTextField() and its design system wrappers (e.g., OutlinedTextField()) suffer from some fairly significant synchronization problems, especially when using reactive data sources… and reactive data sources are fairly important nowadays. Alejandra’s primary recommendation is to mutate the text state synchronously or via a MutableState. Arkadii Ivanov separately suggests using Dispatchers.Main.immediate to safely collect a MutableStateFlow.

Medium: Thinking in Compose

Google’s Chris Arriola focuses on the declarative UI pattern: describing what the UI should be instead of how to get to that UI from whatever starting point you happen to be in at the moment. Google also published a video on the same subject.

Learn Jetpack Compose at a Compose Camp near you!

Google is offering a series of “Compose Camp” events in concert with Google Developer Groups and Google Developer Student Clubs.

Medium: Compose Component Builders

Tim Rijckaert discusses how to avoid too many overloads of the same function by using the builder pattern. In a nutshell, Tim advocates for writing a composable that takes a builder that in turn offers a DSL-style way to provide the input data for the composable.

Improving app accessibility with Jetpack Compose

Kristen Halper looks at how we can identify accessibility concerns in our Compose UI apps and how to help address them. Specifically, Kristen applies this to Microsoft’s Surface Duo Compose UI samples.

Medium: How to Use the Android Paging3 Library With Jetpack Compose

Daniel Dimovski demonstrates conumsing the Google Books API within a Compose UI app. Specifically, Daniel looks at using paging-compose to supply data page-at-a-time to a LazyColumn(), leveraging collectAsLazyPagingItems() to map a Pager-backed Flow to a LazyPagingItems that can be used with the lazy containers.

Medium: Custom ExoPlayer Controls in Jetpack Compose

Ruben Quadros wanted to use ExoPlayer in a Compose UI app. Specifically, Ruben wanted to use composables for the controls overlay (play, pause, etc.). Ruben’s post focuses on how to create composables that interact with ExoPlayer to control playback and to respond to events (e.g., update a SeekBar() position as the video plays).

Resource Roundup

100% pure code!

GitHub: lincollincol / compose-audiowaveform

Andrew Linc brings us an AudioWaveform() composable that renders a waveform from a collection of amplitudes. The resulting UI is clickable, SeekBar-style, to choose a particular offset in the waveform.

GitHub: sagar-viradiya / koreography

Sagar Viradiya created a DSL for describing animations, via a rememberKoreography() top-level function that offers DSL operations like parallelMoves() and move().

GitHub: zach-klippenstein / compose-undo

Google’s Zach Klippenstein created a proof-of-concept universal undo system for Compose. As Zach notes, “this is a very unconventional and probably unsupported use case of the StateObject and StateRecord APIs”, so be careful in using this approach in production. Still, it represents an approach that might get first-class support in the future.