jetc.dev Newsletter Issue #227

Published: 2024-08-13

The 1.7.0 betas for Compose never seem to end, as we peek at the last round of updates!

We also look at state management, navigation, and biometrics in Compose Multiplatform, along with Multiplatform libraries for sticky headers and YouTube video playback.

Ooooo… What Did We Get?

Reviewing the release notes for the latest Jetpack Compose update!

The major Compose artifacts are up to 1.7.0-beta07, as we continue on the beta train. As expected, these just contain a smattering of bug fixes.

In terms of Compose-adjacent libraries, we got:

  • androidx.constraintlayout:constraintlayout-compose:1.1.0-alpha14
  • androidx.constraintlayout:constraintlayout-compose-android:1.1.0-alpha14
  • androidx.lifecycle:lifecycle-runtime-compose:2.9.0-alpha01
  • androidx.lifecycle:lifecycle-runtime-compose-android:2.9.0-alpha01
  • androidx.lifecycle:lifecycle-runtime-compose-desktop:2.9.0-alpha01
  • androidx.lifecycle:lifecycle-viewmodel-compose:2.9.0-alpha01
  • androidx.lifecycle:lifecycle-viewmodel-compose-android:2.9.0-alpha01
  • androidx.lifecycle:lifecycle-viewmodel-compose-desktop:2.9.0-alpha01
  • androidx.navigation:navigation-compose:2.8.0-beta07
  • androidx.navigation:navigation-fragment-compose:2.8.0-beta07
  • androidx.paging:paging-compose:3.3.2
  • androidx.paging:paging-compose-android:3.3.2

One Off the Stack, One Off the Slack

You’ve got questions. That’s understandable!

Do I Need to remember() an Activity Property?

In a composable, most of the time if we use mutableStateOf(), we then remember() it, to preserve that State across recompositions. But, what if we use mutableStateOf() in a property of the Activity hosting our composition — do we need to use remember()? Learn more in this week’s highlighted Stack Overflow question.

State or Flow?

One of the conundrums for viewmodels is whether you should expose state via State or Flow properties. Flow can be problematic, and so State probably is a safer answer, 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: CMP for Mobile Native Developers — Part. 3: State Holders

Santiago Mattiauda is writing a series of posts introducing newcomers to Compose Multiplatform some of the core concepts. In this post, Santiago reviews the concept of state and what holds that state. Santiago also reviews several implementations of viewmodels for CMP and reminds us to use collectAsStateWithLifecycle() when consuming flows.

Medium: Android Jetpack Compose Image Crop Simply

Image cropping is a reasonably common UI operation, and there are many libraries for it. Alparslan Güney shows how to implement it directly, without requiring a third-party library.

Medium: Exploring Safe Navigation in Jetpack Compose Multiplatform

Kerry Bisset takes a look at JetBrains’ adoption of Navigation for Compose and how to use it for a Compose Multiplatform project, alongside Koin for dependency inversion. Along the way, Kerry describes how to use interfaces to describe navigable destinations, wrapping a navigation route along with details of how it gets rendered (e.g., as an entry in a navigation rail).

Medium: Biometric Authorization in Compose Multiplatform App

Medium user Mohitsoni describes how to implement biometric authentication for both Android and iOS in a Compose Multiplatform project. This includes both the actual authentication and leveraging an authenticated keystore for signing data to be sent to a (theoretical) backend.

Medium: Open Source a Compose Picture viewer library ImageViewer, supporting multiple gestures

Medium user ZhangKe published an image viewer library and walks us through its use. The library supports both double-click and pinch gestures for zooming, etc.

Problems with Glance

Lyubomir Ganev (@luboganev@androiddev.social) is less than completely impressed with Glance and explains why in a series of Mastodon posts.

Resource Roundup

100% pure code!

GitHub: nxoim / decomposite

GitHub user nxoim created a Compose Multiplatform navigation library, based on Decompose, supporting Android and desktop platforms. It offers viewmodel management and transition animations.

GitHub: adamglin0 / compose-shadow

GitHub user adamglin0 brings us implementations of drop shadows for composables in Compose Multiplatform, supporting Android, iOS, and desktop. You control the shape, color, offset, and additional properties of the shadow, via a dropShadow() modifier.

GitHub: gregkorossy / lazy-sticky-headers

Gergely Kőrössy published a Compose Multiplatform library implementing the “sticky headers” UI pattern, for all platforms. It ties into rememberLazyListState(), so your list and your headers remain synchronized.

GitHub: KhubaibKhan4 / MediaPlayer-KMP

Muhammad Khubaib Imtiaz implemented a Compose Multiplatform library for playing YouTube videos and audio clips, supporting all platforms.