jetc.dev Newsletter Issue #249
Published: 2025-01-14
This week, we look at composables and lifecycles, plus font differences between platforms. We dive into using CameraX in Compose, centering things, and using OTP values. Plus, we see an aspect-ratio-aware grid and some editors.
One Off the Stack, One Off the Slack
You’ve got questions. That’s understandable!
Why Am I Seeing Lifecycle Changes In My Composable?
If you use LocalLifecycleOwner
to register a LifecycleEventObserver
inside a
DisposableEffect()
in a composable, you will see it react to whether or not the
current composable is in a composition. That is because while we normally think of
LifecycleOwner
in the context of an activity or fragment, that’s not always the
case, as we see in this week’s highlighted Stack Overflow question.
Why Do My Fonts Look Different?
Font rendering is highly platform-specific, even with Compose Multiplatform. As such,
the same font might render differently by default, requiring some work to get them to
look the same across platforms. This is especially the case with variable-weight
fonts, as we see in this week’s highlighted Kotlinlang #compose
Slack thread.
Composable Commentary
Posts, videos, and other new information related to Jetpack Compose!
Medium: Getting Started with CameraX in Jetpack Compose
Google’s Jolanda Verhoef
(Mastodon, Bluesky)
brings us the first of a four-part series on how
to integrate CameraX in a Compose for Android app, by way of the
camera-compose
library. This post focuses on a basic preview UI,
after first using Accompanist Permissions to request the right to use
the camera.
Medium: Tap to focus: Mastering CameraX Transformations in Jetpack Compose
Google’s Jolanda Verhoef’s second CameraX-on-Compose post, adding tap-to-focus capability,
by means of the detectTapGestures()
function in the pointerInput()
Compose DSL.
Medium: Jetpack Compose Demystified: Key Concepts Unveiled Through Sharing ViewModels Across Screens
Marian Jureczko explores recomposition, snapshots, and navigation, all through the
lens of shared ViewModel
instances.
Medium: Cheatsheet for centering items in Jetpack Compose
Sherry Yuan has posted a cheatsheet to remind us how to center items, horizontally
and vertically, in Row()
, Column()
, and Box()
composables.
Retaining beyond ViewModels
Chris Banes
(Mastodon, Bluesky)
recounts the limitations of the Jetpack ViewModel
in the Compose realm
and reviews how Circuit’s rememberRetained()
can also be used to hold onto data
across both recompositions and configuration changes.
Medium: Implementing SMS OTP Retrieval with Jetpack Compose
Android has dedicated APIs for retrieving an OTP code from an SMS message, for apps that use these for two-factor authentication but otherwise do not need SMS access. Enes Kayıklık examines how to use this from composables, including how to respond to broadcasts from within a composable.
Medium: Using dp as a Text Unit in Jetpack Compose
In an ideal world, we would use sp
everywhere for text sizes. As I tend to point out
, in an ideal world, I would have hair. 👴🏻
Since this is not an ideal world, sometimes we have legit reasons for wanting to use
dp
for text sizes. Medium user Quokkaman explains how we can do that.
Other Interesting Links
- Expandable Text in Jetpack Compose
- Kotlin — Functional (SAM) interfaces VS Function-Type Performance
- Medium: How to convert any Composable into an image
- Medium: How to Create a Jumpy Row Layout in Jetpack Compose
- Medium: Jetpack Compose Kotlin: Best Practices for Handling Side Effects in Android
- Medium: Pagination in Jetpack Compose: With and Without Paging 3 Library
- Using Koin in Compose Multiplatform
Resource Roundup
100% pure code!
GitHub: vipulasri / aspecto
Vipul Asri
(Mastodon)
released an AspectoGrid()
composable that is a grid that
better maintains its items aspect ratios, designed for use with
a collection of images. This multiplatform library supports Android
and iOS.
GitHub: taha-cmyk / exposed
GitHub user taha-cmyk wrote a SyntaxHighlightedTextField()
composable
that provides syntax highlighting in an editor, with support for custom
programming languages/highlighting rules and color schemes.
GitHub: sunny-chung / bigtext
GitHub user sunny-chung also is working on an editor, but in this case the focus is on larger blocks of text, up to 100MB. While the library is multiplatform, at the present time only Compose for Desktop is supported.
Other Interesting Links
- GitHub: chizhanov / EcoEngine (game engine)
- GitHub: KvColorPallet / kv-android-color-pallet (generate a theme from a color)
- GitHub: Sagar0-0 / neopop-compose (NeoPOP design system)
Notable Releases
The Google Pay team released 1.1.0
of the Compose edition of the Pay Button,
with a bit more graceful degradation.
Also, Appyx is up to 1.6.0
,
with support for shared element transitions.
Or, you can subscribe to the Atom feed or follow Mark Murphy in the Fediverse.
Recent Issues:
- 2025-01-07: Responsive grids! Styled strings! Design systems! Pickers! Render composables to PDFs! And... this then or this?!?
- 2024-12-31: Scaffold panes! Weights and FlowRow()! TV Compose! PDF rendering! Drop shadows! And... is it time to take action?!?
- 2024-12-24: Compose Multiplatform update! Type-safe navigation! Camera! Hot reload! @Preview generator! And... a library of libraries?!?