jetc.dev Newsletter Issue #136

Published: 2022-10-11

The Android Developer Summit will return later this month! 🎉

Beyond that, we look at the latest Compose updates, including an intriguing new TV-specific pair of libraries. We examine performance (again), replacing the “single live event” pattern, and getting a composified ExoPlayer to react to the activity lifecycle. And we see an implementation of ssp units for Compose, to size things scaled based on screen size, font scale, and screen density.

(personally, I am holding out for SSPaaS — scalable SPs as a service — so we can scale our sizes… at scale)

Ooooo… What Did We Get?

Reviewing the release notes for the latest Jetpack Compose update!

This was an interesting week for releases.

First, we got Compose Compiler 1.3.2, with official support for Kotlin 1.7.20.

We also got a 1.3.0-rc01 release for the rest of the core Compose artifacts. Besides your usual round of bug fixes, we also got an experimental API for automatic hyphenation in text composables.

Wear Compose got a bump to 1.1.0-alpha07, with a bunch of new things, including:

  • Better font customization for CurvedTextStyle

  • New Checkbox(), Switch(), and RadioButton() options for use with ToggleChip() and SplitToggleChip()

  • An experimental placeholder() modifier implementation

To me, though, the most interesting development is one without Compose in the name. We got a 1.0.0-alpha01 release of androidx.tv:tv-foundation and androidx.tv:tv-material. Google does not appear to have announced anything about them. However, from the release notes, it is clear that these libraries form the basis of a TV-centric set of composables, including carousels, TV-specific lazy containers, and more. I hope that we will hear more about Google’s plans in this area in the coming months!

One Off the Stack, One Off the Slack

You’ve got questions. That’s understandable!

How Can I Change Images Without Changing State?

If we are not over-composing, we are under-composing. Sometimes, your state might not be represented by in-memory information, such as a Uri pointing to an image where the image content is new but the Uri stays the same. You will need to leverage some other state that changes in tandem to trigger recomposition, as we see in this week’s highlighted Stack Overflow question.

Are Flows OK For Composable Performance?

Articles — such as the ones referenced in newsletters like this — sometimes make broad-brush statements like “Use [flows] only if absolutely necessary”. Those statements are not always accurate for all situations. Learn why Flow is not intrinsically bad, and the “tools not rules” philosophy, in this week’s highlighted Kotlinlang #compose Slack thread.

Composable Commentary

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

Medium: Compose Tooling

Google’s Chris Arriola continues an introductory tour of Compose and Compose UI, this time looking at Android Studio features of use to composable developers, from Live Templates and Live Edit through various preview options. This material is also covered in an associated video.

Todoist adopted Compose for Wear OS and increased its growth rate by 50 percent

This is another official “puff piece” regarding Compose UI adoption, this time by the Todoist team for their Wear OS app.

Medium: Performance in Jetpack Compose

Denis Rudenko spent a lot of time exploring performance tuning your composables and wrote a massive post explaining the findings. The “TL;DR/Summary” section is practically a post in itself. Denis explores stability/immutability, the use of lambdas, cross-module stability impacts, and more!

Video: Recomposition in Jetpack Compose

Jonathan Johnson delivered a presentation for GDG Cincinnati, focusing on state management, its effects on recomposition, and steps to take to try to improve performance.

Medium: Exploring Compose’s Remember and Recomposition Step by Step

Elye is back with a pair of posts regarding remember(). In the post linked to above, Elye reviews the basics of recomposition and the impact of remember(), exploring some common scenarios for how composables get constructed. In a follow-on Medium post Elye examines some far less common scenarios, such as holding a composable lambda in a local variable, and sees how remember() and recomposition play out for those.

Medium: How To Handle ViewModel One-Time Events In Jetpack Compose

One-time events have bedeviled Android developers for years. With Compose being strongly state-driven, we have been advised to merge our events into our view states. In this post, Yanneck ReiĂź reviews a library for trying to accomplish that, by means of a StateEvent and EventEffect pair.

Medium: How to Make ExoPlayer Lifecycle Aware in Jetpack Compose

ExoPlayer is fairly critical in modern Android media app development, so there will be continued work on figuring out how best to have ExoPlayer work with Compose UI. Tobias Wissmueller continues an exploration of this subject, this time looking at how a composable wrapper around ExoPlayer’s StyledPlayerView can leverage LocalLifecycleOwner to forward play/pause events to the player as the app is moved to and from the background. \

Using Java Beans in a composed UI

Thomas KĂĽnneth returns, this time looking at how to blend JavaBeans and PropertyChangeSupport with Compose states. This is with an eye toward Compose for Desktop, where you might be migrating legacy Swing-based UIs to using Compose and needing to work with JavaBeans as part of that migration.

Resource Roundup

100% pure code!

GitHub: Kaaveh / sdp-compose

Intuit published a library that lets you measure sizes in “ssp” units, which take into account screen size, density, and font scaling. Kaaveh Mohamedi created an equivalent for Compose UI, with sdp and ssp extension properties to let you specify sizes that take into account screen size as well as screen density and (optionally) font scaling.

GitHub: SmartToolFactory / Compose-RatingBar

The SmartToolFactory team brings us a RatingBar() composable, with lots of customizable options: what the rating images are (filled and empty), what their tints are, how large the images are, etc.