The latest release of Jetpack Compose, as usual named after its introduction month, adds new APIs for rendering shadows, 2D scrolling, improved list performance, and more.
Two new modifiers, Modifier.dropShadow()
and Modifier.innerShadow()
, enable rendering box-shadow effects either below or on top of a composable, such as an image or a rectangle. They extend Jetpack Compose’s shadowing capabilities beyond the existing Modifier.shadow()
, used to render elevation-based shadows according to a lighting model.
To improve tracking of elements’ on-screen location, Jetpack Compose introduces two new visibility modifiers, onVisibilityChanged
and onFirstVisible
. The first fires when an element becomes visible or invisible, like automatically playing and pausing videos, while the second triggers when an element becomes visible for the first time.
The latest Jetpack Compose release also improves lazy components, that is components that are laid out and rendered only when necessary rather than all at once. Both lazy lists and grids now offer better prefetch performance thanks to a new LazyLayoutCacheWindow
, which lets developers specify how many items to prefetch. The default behavior is to prefetch one item at a time.
A significant new feature for apps implementing more complex scrollable experiences like spreadsheets or image viewers is the new Scrollable2D modifier, which enables scrolling and flinging in both dimensions and extends the existing Scrollable
modifier which only works in one direction. Additionally, several bug fixes and new features improve scroll and nested scroll interoperability with Views.
On the tooling side, the new Jetpack Compose release introduces an opt-in API for richer crash reports, which will include composable names and crash locations. This is a major improvement over previous reports that showed only internal stack frames with little useful information. Google says the new API should help developers identify and fix crashes more efficiently by making it easier to isolate and reproduce them. It is worth noting that the new API has a performance impact and is not recommended for use in release builds.
As a final note, Google has introduced a new runtime-annotation library to exposes compiler and linter annotations, allowing non-Compose classes and functions to use them without depending on the Compose runtime. The release also adds two new lint annotations: @RememberInComposition
, which flags functions, constructors, and getters that must not be called directly in composition without being remembered; and @FrequentlyChangingValue
, which warns against direct calls in composition that may trigger frequent recompositions.