jetc.dev Newsletter Issue #213

Published: 2024-05-07

Not only did we get a Compose Compiler update, but we learned that it is changing homes, becoming part of the Kotlin ecosystem!

We also look at other updates in the world of Compose, including pre-fetching support for lazy containers and official type safe, non-stringified parameter passing in Navigation for Compose. We tailor our previews with LocalInspectionMode and add custom drop shadows. And we peek at a Compose Multiplatform drop-down menu implementation.

Ooooo… What Did We Get?

Reviewing the release notes for the latest Jetpack Compose update!

Compose Compiler 1.5.13 is available, with a couple of bug fixes, plus removing the experimental annotation from “strong skipping” mode.

The Compose BOM is up to 2024.05.00, mapping to 1.6.7 of the main Compose libraries and 1.2.1 of the Material3 libraries. This is mostly a set of bug fixes, especially in Material3.

The main Compose libraries also got a 1.7.0-alpha08 release, adding:

  • Support for mutable shape implementations

  • Support for pre-fetching items in lazy containers like LazyColumn(), including indicating ones as “urgent”

  • A “right-click” context menu for BasicTextField() and SelectionContainer() with cut/copy/paste/select-all actions

The Compose Material3 family is up to 1.3.0-alpha06, including:

  • Revisions to the pull-to-refresh APIs

  • Better edge-to-edge support for ModalBottomSheet()

  • Pressed-state support for text links

Wear Compose is up to 1.4.0-alpha08, with a few renamed items in the rotary and SplitSelectableChip() APIs. Wear Compose Material3 is up to 1.0.0-alpha22, with changes to ColorScheme and how it is applied to Switch().

TV Compose Material got a bump to 1.0.0-beta01, though the main TV Compose artifact did not. Mostly, this release renames some things and marks others as stable.

In terms of Compose-adjacent libraries, we got:

  • androidx.fragment:fragment-compose:1.7.0
  • androidx.lifecycle:lifecycle-runtime-compose:2.8.0-rc01
  • androidx.lifecycle:lifecycle-runtime-compose-android:2.8.0-rc01
  • androidx.lifecycle:lifecycle-runtime-compose-desktop:2.8.0-rc01
  • androidx.lifecycle:lifecycle-viewmodel-compose:2.8.0-rc01
  • androidx.lifecycle:lifecycle-viewmodel-compose-android:2.8.0-rc01
  • androidx.lifecycle:lifecycle-viewmodel-compose-desktop:2.8.0-rc01
  • androidx.navigation:navigation-compose:2.8.0-alpha08
  • androidx.navigation:navigation-fragment-compose:2.8.0-alpha08
  • androidx.paging:paging-compose:3.3.0-rc01
  • androidx.paging:paging-compose-android:3.3.0-rc01

Also, Room is starting to support Kotlin Multiplatform, making it a candidate for Compose Multiplatform projects.

One Off the Stack, One Off the Slack

You’ve got questions. That’s understandable!

Why Can I Not Supply Text and Icons to My Tabs?

One of the downsides of the Compose API is that it relies heavily on overloaded function names, such as Tab(). Which Tab() implementation is used is implied by the parameter list, which means if you screw up your parameter types, you could be working with a different function than what you might expect. See how a rogue trailing lambda causes Tab() confusion in this week’s highlighted Stack Overflow question.

Why Does Compose for Desktop Not Like My Library?

Compose for Desktop prefers JetBrains’ own forked JVM (called JBR), which supports Java 17. Libraries compiled with newer versions of Java might generate bytecode that the JBR does not support, leading to “has been compiled by a more recent version of the Java Runtime” errors. Learn more in this week’s highlighted Kotlinlang #compose Slack thread.

Composable Commentary

Posts, videos, and other new information related to Jetpack Compose!

Medium: Navigation Compose meet Type Safety

Google’s Ian Lake discusses Google’s approach for adding type safety to Navigation for Compose routes, by way of Kotlin Serialization. This looks really quite slick, and I look forward to trying it out!

Jetpack Compose compiler moving to the Kotlin repository

Google’s Ben Trengrove announces that the Compose Compiler will move to JetBrains’ Kotlin repository. In other words, each Kotlin release will get a corresponding Compose Compiler release, so you can always update those in tandem. Ben also points out a new Compose Compiler Gradle plugin, which also matches Kotlin’s versioning scheme.

Medium: Only Show the Tip of the Iceberg

Katie Barnett explains how to use LocalInspectionMode.current to have your composables distinguish being in the IDE versus being in a real app. This helps avoid unnecessary rendering issues in the IDE previews when your composables are stuck with dependencies on unavailable configuration locals, etc.

Medium: Conscious Compose optimization 2: Tackling composition

Andrey Bogomolov brings us a lengthy post on various optimization techniques and their results. The post covers the costs of derivedStateOf(), employing deferred composition, dealing with Painter for icons, and more.

Apply SwipeToDismissBox in Android Jetpack Compose

Shiva Thapa explores SwipeToDismissBox(), which exposes content under a box based on a swipe gesture. This UX is typical for power users in lists, such as for “swipe to delete” or “swipe to archive” options.

Medium: Custom Drop Shadow from Figma in Jetpack Compose: For Any Shape

Medium user Kappdev walks us through a custom dropShadow() modifier that allows you to configure the shape, color, blur, spread, and offset for a shadow. This is useful for cases where designers do not adhere to Android’s opinionated shadow system.

Medium: Simplifying TomTom Maps Integration with a Jetpack Compose Wrapper

Ezichi Amarachi shows how to wrap a TomTom SDK MapFragment in a composable.

Resource Roundup

100% pure code!

Compose Menu (Dropdown)

Alex Styl added a Menu() composable to his collection, implementing a well-documented drop-down menu for Compose Multiplatform.

Gist: Sal7one / HeartShape.kt

Saleh Alanazi demonstrates three variations of a heart-shaped composable, including two showing an animation along the path.

Notable Releases

Horologist — the Accompanist equivalent for Wear Compose — is out with a 0.6.10 release. This contains a new AnimatedLabel composable, FontScaleIndependent, and other fixes and improvements.

Maps for Compose is up to 4.4.2, with a few bug fixes.