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()
, andRadioButton()
options for use withToggleChip()
andSplitToggleChip()
-
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.
Other Interesting Links
- Medium: Chip Group in Jetpack Compose
- Medium: Custom Compose Layout with limited scope and modifiers inside
- Slides: Molecule: Using Compose for presentation logic
- Medium: Building A Jetpack Compose Window With AbstractComposeView
- Medium: The missing pieces of text alignment in Compose Text
- Medium: Jetpack Compose Activity for result handling mechanism for viewModel
- Medium: Auto-Spaced Text in Jetpack Compose
- Normal Variable vs remember vs remember mutabableStateOf Comparisons
- Medium: Jetpack compose: Cool Button Click Effects
- Navigation Compose
- Medium: Jetpack Compose Clean Navigation
- Medium: Type-safe arguments in JetPack Navigation Compose
- Medium: Jetpack Compose for Wear OS - Building Weather App
- Jetpack Compose Side Effects – With Examples
- Medium: Advanced work with the Snackbar in the Jetpack Compose
- Medium: Jetpack Compose Animations
- Medium: Easy animation on splash screen In android using jetpack compose
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.
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?!?