jetc.dev Newsletter Issue #128
Published: 2022-08-16
Releases are getting more complicated, where we got 1.2.1, 1.3.0, and 1.3.0-alpha03
all at the same time!
Beyond that, we look at text in a Canvas()
spend a lot of time on performance,
including the use (or non-use) of @Stable
. We examine consuming flows, implementing
effects, and how Live Literals work. And we see how, with an annotation and a library,
we can even get rid of having an Activity
in our Compose UI apps.
Release Roundup and Alpha Analysis
Reviewing the release notes for the latest Jetpack Compose update!
Compose Compiler 1.3.0 is now stable, mostly for getting us up to Kotlin 1.7.10.
We also got 1.2.1 patch versions for the rest of the Compose artifacts. Those fix memory leaks and other bugs.
Plus, 1.3.0-alpha03
is out!
-
LayoutCoordinates
got a bunch of changes, includingfindRootCoordinates()
andtransformFrom()
-
Font support was improved with
FontVariation
Note that Paragraph
is now a sealed interface
, mostly to help with implementing
it for both Compose for Android and Compose for Desktop.
One Off the Stack, One Off the Slack
You’ve got questions. That’s understandable!
How Do We Center Text in a Canvas()?
We now have drawText()
in Canvas()
. However, controlling the positioning is
not as straightforward as it might be in a Box()
. Learn how to use a TextMeasurer
to center the text in this week’s highlighted Stack Overflow question!
Do We Really Need @Stable?
@Stable
and @Immutable
are recommended for Compose, to help guide where
we can skip recompositions. But, how awful is it to have never used them?
Learn more in this week’s highlighted Kotlinlang #compose
Slack thread!
Composable Commentary
Posts, videos, and other new information related to Jetpack Compose!
Medium: Consuming flows safely in Jetpack Compose
Google’s Manuel Vivo walks us through the use of the new collectAsStateWithLifecycle()
to convert a Flow
into a State
for use in a Compose app. As one might
expect, collectAsStateWithLifecycle()
is also lifecycle-aware, defaulting to
only collecting while the associated lifecycle is at least STARTED
.
Medium: Comparing Jetpack Compose performance with XML
Compose performance is a recurring concern for developers. Pratham Arora did some
performance analysis of two screens implemented both in the classic View
system and in Compose UI, using FrameMetricsAggregator
for measuring results.
Medium: Quick Note on Jetpack Compose Recomposition
OK, so, what can we do about performance? One common area of poor performance is over-composition, where we recompose again and again and again unnecessarily. Radhika S’s post reminds us of how recomposition works and points out some common mistakes one can make when dealing with recomposition.
Medium: Optimizing Recomposition in Jetpack Compose: Stability System
Ji Sungbin then looks at a specific aspect of recomposition: stability. Proper use of stable/immutable data types can greatly enhance Compose’s ability to optimize recompositions, ignoring branches that should be unchanged because the inputs have not changed.
Medium: Exploring Jetpack Compose’s Hot-Reload Feature
Ji Sungbin also looked at how Live Literals work, indicating that the build process
is converting literals (of some types) into State
wrappers around those literals,
so they can be updated on the fly by the IDE. Ji also points out the @NoLiveLiterals
annotation to block this code generation for places where it is unnecessary and
adds bloat.
Jetpack Compose Effect Handlers
Jorge Castillo has a new edition of his post reviewing the different types of effects
(LaunchedEffect
, DisposableEffect
, SideEffect
, etc.), reviewing their distinct
roles and use cases.
Medium: AutoSize TextField in Android Jetpack Compose
Auto-sizing text is used to help ensure everything fits in a given space… but
frequently it is only for static text. Ban Markovic wanted auto-sizing text in
a field. Ban accomplished this using BoxWithConstraints()
as a wrapper around
a TextField()
.
Other Interesting Links
- Video: Animating Your Way Into Jetpack Compose
- How to use Downloadable Fonts with Jetpack Compose
- How To Build a Custom Pager Indicator In Jetpack Compose
- Medium: Accompanist — the first chord. A Jetpack Compose library reviewed
- Medium: Why We Adopted Jetpack Compose
- Medium: Is Jetpack Compose Ready for You?
- Medium: Appyx vs Jetpack Compose Navigation
- Medium: How to Do Runtime Permission Handling in Jetpack Compose
- Medium: How to use Palette API with Jetpack Compose
- Medium: Android Jetpack Compose Permissions
- Lazy Layouts in Jetpack Compose
- Build a Real-Time Android WhatsApp Clone With Jetpack Compose
- Jetpack Compose 101: The Basics
- Medium: Jetpack Compose and the conundrum of selecting a suitable architecture
- Medium: Getting Started With MVVM in Jetpack Compose
- Medium: Basic Android Compose - Dynamic Lazy Column
- How to create GridView using Jetpack Compose
Resource Roundup
100% pure code!
GitHub: Mori-Atsushi / compose-launcher
Mori Atsushi noticed that our Compose UI activities tend to be rather boilerplate,
so Mori created a library that code-generates them for us. Simply add @Entry
annotations to composables that represent the content for activities, and Mori’s
KSP-based generator will set up the activity class and the manifest entry for you.
GitHub: jaikeerthick / Composable-Graphs
Jai Keerthick created a library offering composables for rendering line and bar graphs, with some flexibility in terms of colors, labels, 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?!?