jetc.dev Newsletter Issue #116
Published: 2022-05-17
Google I|O 2022 happened, and we have the pictures (well, OK, videos) to prove it!
Beyond that, we peek at what’s new in the beta01
releases for Compose and Wear Compose.
We look at the underpinnings of the state system and how to leverage drawBehind()
for performance. We see libraries for credit card fields and app intros. And, we learn
what a “horologist” is, at least from the standpoint of Wear Compose.
Beta Breakdown
Reviewing the release notes for the latest Jetpack Compose update!
1.2.0-beta01
was released in time for Google I|O 2022. Of note:
-
We got several changes to the line height APIs, mostly types being renamed, plus
LineHeightBehavior
(to control what happens with the top and bottom lines of text) -
LazyLayoutItemsProvider
received several changes -
TextStyle
andSpanStyle
now have access to aBrush
for gradient fills -
We got a new platform-independent test API, in the form of
ComposeUiTest
interface — implementations (AndroidComposeUITest
andDesktopComposeUiTest
) can run Compose tests without aTestRule
Wear Compose also went to a beta (1.0.0-beta01
). Of note there:
-
CurvedModifier.padding...()
functions are now available to provide more space around a curved component -
AppCard()
andTitleCard()
now have anenabled
parameter
One Off the Stack, One Off the Slack
You’ve got questions. That’s understandable!
Why Does My Layout() Ignore My Size?
Layout()
works a bit differently than do simpler container composables like
Box()
or Column()
when it comes to sizing its contents. Learn more in this
week’s highlighted Stack Overflow question.
Is Mutating State From a ViewModel Constructor OK?
In short: no, it is not OK. However, this is a subtle issue and one that you might
easily miss… until you get an inscrutable error message and massive stack trace.
Learn more in this week’s highlighted Kotlinlang #compose
Slack thread.
Composable Commentary
Posts, videos, and other new information related to Jetpack Compose!
What’s new in Jetpack Compose
This official blog post was released as part of Google I|O 2022 and mostly covers what is included in Compose 1.2. Note that this post covers items new since Compose 1.1, not just what is new in the Compose 1.2 beta.
Airbnb uses Jetpack Compose to empower devs to do their best work
This is another official “puff piece” from Google about Compose UI, this time looking at the work being done by Airbnb.
Implementing snapshot-aware data structures
Google’s Zach Klippenstein continues a deep dive into how snapshots work “under the hood”. This time, Zach explores the details behind “state objects” and how the snapshot system uses a version control system to keep state atomic within a snapshot but mutable between snapshots. As Zach puts it, “these details are not at all necessary to use Compose even for many advanced use cases, and you can have a whole successful career as a Compose developer without knowing any of it. It’s just really, really cool.”
Compose phases and optimizations
James Shvarts continues a tour of Compose concepts, this time looking at the three phases of Compose UI rendering: composition, layout, and drawing. In particular, James looks at how we can skip one (or more) of those phases for a frame, to improve performance.
Video: Strategies for Migrating to Jetpack Compose
Mohit Sarveiya delivered a presentation for Android Worldwide reviewing many aspects of migrating large code bases to Compose UI. Mohit covers everything from testing and interop with legacy code to language support and issues with Kotlin version compatibility.
Other Interesting Links
- Medium: TLDR — Parallax Scrolling with Jetpack Compose
- Medium: Jetpack Compose Theming: Colors
- Medium: Animated grid in Jetpack Compose
- Medium: Glassmorphism in Jetpack Compose for scrolling item
- Medium: Detect Swipe Direction on Jetpack Compose to trigger BottomSheetScaffold
- Simple Jetpack Compose Navigation Example
- Medium: Collapsing Toolbar in Jetpack Compose (‘Column’ version)
- Image Slider with the indicator Using Jetpack compose
- Jetpack Compose for Late Adopters
Resource Roundup
100% pure code!
Horologist
Just as Accompanist is Google’s extension library for Compose UI, Horologist is Google’s extension library for Compose for Wear (and other Wear OS development). It is possible that some of these things will be promoted into Compose for Wear in the future.
GitHub: android / nowinandroid
Google also released an app for Now In Android, the weekly blog / podcast / video covering official Android news. The app was written in Compose Material and is designed to serve as a first-class demonstration of Compose techniques, in addition to being directly useful for obtaining Android content.
GitHub: AndroidPoet / App-intro
Ranbir Singh created a Compose UI-based framework for creating those step-at-a-time app introduction wizards, where you supply composables for what goes on each page and the framework handles transitions.
GitHub: SteliosPapamichail / CreditCardHelper
Stelios Papamichail created a handful of utility functions for working with
credit card numbers in Compose UI, including CardNumberMask
and ExpirationDateMask
visual transformations for fields.
GitHub: JamalMulla / ComposePrefs3
Jamal Mulla is back, this time with a Material3 implementation of a preference UI, following up on his earlier Compose Material preference UI.
…And One More Thing
Google I|O 2022 is in the books, and remarkably few ground-breaking improvements came out of it for Compose developers. Admittedly, the Live Edit experience added to Android Studio Electric Eel was shocking to see.
(and, if you didn’t expect that awful pun, you don’t know me very well…)
Tooling improvements like that are very welcome. But if you were expecting Compose for Stoves, or a new “Material Us” design language with Compose support, you may have been disappointed. We got new betas, and some more Google libraries and samples, but that was about it. IMHO, going a bit slow this cycle is not a bad thing, in that it helps the broader Android ecosystem catch up. While many developers love a cycle of continuous change, many other developers deeply resent the “hamster wheel” that continuous change represents.
Here are YouTube links for the I|O 2022 sessions that specifically called out Compose in their descriptions, from my roster from two weeks ago.
Or, you can subscribe to the Atom feed or follow Mark Murphy in the Fediverse.
Recent Issues:
- 2024-12-10: A Compose Multiplatform alpha! Hot reload! Presentation! Sprites! Calendars!
- 2024-12-03: Rebecca Franks on clipping and masking! Stefano Natali on graphicsLayer()! FunkyMuse on type-safe nav results! And... if we have enough maps, do we need to store our maps in a Map?!?
- 2024-11-26: Math! Shared element transitions! Custom modifiers! Macrobenchmark! Adapting to platform-specific design systems! And... why does wrapContentSize() not wrap my content size?!?