[HTML payload içeriği buraya]
28.3 C
Jakarta
Friday, April 24, 2026

What’s new within the Jetpack Compose April ’26 launch


Posted by Meghan Mehta, Android Developer Relations Engineer

In the present day, the Jetpack Compose April ‘26 launch is steady. This launch accommodates model 1.11 of core Compose modules (see the full BOM mapping), shared aspect debug instruments, trackpad occasions, and extra. We even have a number of experimental APIs that we’d love you to check out and provides us suggestions on.

To make use of at the moment’s launch, improve your Compose BOM model to:

implementation(platform("androidx.compose:compose-bom:2026.04.01"))

Modifications in Compose 1.11.0

Coroutine execution in assessments

We’re introducing a significant replace to how Compose handles check timing. Following the opt-in interval introduced in Compose 1.10, the v2 testing APIs are actually the default, and the v1 APIs have been deprecated. The important thing change is a shift within the default check dispatcher. Whereas the v1 APIs relied on UnconfinedTestDispatcher, which executed coroutines instantly, the v2 APIs use the StandardTestDispatcher. Because of this when a coroutine is launched in your assessments, it’s now queued and doesn’t execute till the digital clock is superior.

This higher mimics manufacturing situations, successfully flushing out race situations and making your check suite considerably extra sturdy and fewer flaky.

To make sure your assessments align with customary coroutine habits and to keep away from future compatibility points, we strongly advocate migrating your check suite. Take a look at our complete  migration information for API mappings and customary fixes.

Shared aspect enhancements and animation tooling

We’ve additionally added some helpful visible debugging instruments for shared parts and Modifier.animatedBounds. Now you can see precisely what’s occurring beneath the hood—like goal bounds, animation trajectories, and what number of matches are discovered—making it a lot simpler to identify why a transition won’t be behaving as anticipated. To make use of the brand new tooling, merely encompass your SharedTransitionLayout with the LookaheadAnimationVisualDebugging composable.

LookaheadAnimationVisualDebugging(
    overlayColor = Coloration(0x4AE91E63),
    isEnabled = true,
    multipleMatchesColor = Coloration.Inexperienced,
    isShowKeylabelEnabled = false,
    unmatchedElementColor = Coloration.Pink,
) {
    SharedTransitionLayout {
        CompositionLocalProvider(
            LocalSharedTransitionScope supplies this,
        ) {
            // your content material
        }
    }
}

Trackpad occasions

We’ve revamped Compose help for trackpads, like built-in laptop computer trackpads, attachable trackpads for tablets, or exterior/digital trackpads. Primary trackpad occasions will now typically be thought of PointerType.Mouse occasions, aligning mouse and trackpad habits to raised match person expectations. Beforehand, these trackpad occasions had been interpreted as pretend touchscreen fingers of PointerType.Contact, which led to complicated person experiences. For instance, clicking and dragging with a trackpad would scroll as a substitute of choosing. By altering the pointer sort these occasions have within the newest launch of Compose, clicking and dragging with a trackpad will not scroll.

We additionally added help for extra sophisticated trackpad gestures as acknowledged by the platform since API 34, together with two finger swipes and pinches. These gestures are robotically acknowledged by parts like Modifier.scrollable and Modifier.transformable to have higher habits with trackpads.

These modifications enhance habits for trackpads throughout built-in parts, with redundant contact slop eliminated, a extra intuitive drag-and-drop beginning gesture, double-click and triple-click choice in textual content fields, and desktop-styled context menus in textual content fields.

To check trackpad habits, there are new testing APIs with performTrackpadInput, which permit validating the habits of your apps when getting used with a trackpad. You probably have customized gesture detectors, validate habits throughout enter varieties, together with touchscreens, mice, trackpads, and styluses, and guarantee help for mouse scroll wheels and trackpad gestures.

Earlier thanAfter

Composition host defaults (Compose runtime)

We launched HostDefaultProvider, LocalHostDefaultProvider, HostDefaultKey, and ViewTreeHostDefaultKey to produce host-level companies immediately by compose-runtime. This removes the necessity for libraries to rely upon compose-ui for lookups, higher supporting Kotlin Multiplatform. To hyperlink these values to the composition tree, library authors can use compositionLocalWithHostDefaultOf to create a CompositionLocal that resolves defaults from the host.

Preview wrappers

Android Studio customized previews is a brand new characteristic that permits you to outline precisely how the contents of a Compose preview are displayed.

By implementing the PreviewWrapperProvider interface and making use of the brand new @PreviewWrapper annotation, you’ll be able to simply inject customized logic, comparable to making use of a selected Theme. The annotation might be utilized to a operate annotated with @Composable and @Preview or @MultiPreview, providing a generic, easy-to-use resolution that works throughout preview options and considerably reduces repetitive code.

class ThemeWrapper: PreviewWrapper {

    @Composable

    override enjoyable Wrap(content material: @Composable (() -> Unit)) {

        JetsnackTheme {

            content material()

        }

    }

}

@PreviewWrapperProvider(ThemeWrapper::class)

@Preview

@Composable

non-public enjoyable ButtonPreview() {

    // JetsnackTheme in impact

    Button(onClick = {}) {

        Textual content(textual content = "Demo")

    }

}

Deprecations and removals

  • As introduced within the Compose 1.10 weblog publish, we’re deprecating Modifier.onFirstVisible(). Its title typically led to misconceptions, significantly inside lazy layouts, the place it could set off a number of instances throughout scrolling. We advocate migrating to Modifier.onVisibilityChanged(), which permits for extra exact guide monitoring of visibility states tailor-made to your particular use case necessities.
  • The ComposeFoundationFlags.isTextFieldDpadNavigationEnabled flag was eliminated as a result of D-pad navigation for TextFields is now all the time enabled by default. The brand new habits ensures that the D-pad occasions from a gamepad or a TV distant first transfer the cursor within the given route. The main focus can transfer to a different aspect solely when the cursor reaches the tip of the textual content.

Upcoming APIs

Within the upcoming Compose 1.12.0 launch, the compileSdk shall be upgraded to compileSdk 37, with AGP 9 and all apps and libraries that rely upon Compose inheriting this requirement. We advocate preserving updated with the most recent launched variations, as Compose goals to promptly undertake new compileSdks to supply entry to the most recent Android options. Make sure to try the documentation right here for extra info on which model of AGP is supported for various API ranges.

In Compose 1.11.0, the next APIs are launched as @Experimental, and we stay up for listening to your suggestions as you discover them in your apps. Be aware that @Experimental APIs are supplied for early analysis and suggestions and should endure vital modifications or elimination in future releases.

Types (Experimental)

We’re introducing a brand new experimental basis API for styling. The Model API is a brand new paradigm for customizing visible parts of parts, which has historically been carried out with modifiers. It’s designed to unlock deeper, simpler customization by exposing an ordinary set of styleable properties with easy state-based styling and animated transitions. With this new API, we’re already seeing promising efficiency advantages. We plan to undertake Types in Materials parts as soon as the Model API stabilizes.

A primary instance of overriding a pressed state model background:

@Composable
enjoyable LoginButton(modifier: Modifier = Modifier) {
    Button(
        onClick = {
            // Login logic
        },
        modifier = modifier,
        model = {
            background(
                Brush.linearGradient(
                    listOf(lightPurple, lightBlue)
                )
            )
            width(75.dp)
            top(50.dp)
            textAlign(TextAlign.Middle)
            externalPadding(16.dp)

            pressed {
                background(
                    Brush.linearGradient(
                        listOf(Coloration.Magenta, Coloration.Pink)
                    )
                )
            }
        }
    ){
        Textual content(
            textual content = "Login",
        )
    }
}

MediaQuery (Experimental)

The brand new mediaQuery API supplies a declarative and performant strategy to adapt your UI to its setting. It abstracts complicated info retrieval into easy situations inside a UiMediaScope, making certain recomposition solely occurs when wanted.

With help for a variety of environmental alerts—from machine capabilities like keyboard varieties and pointer precision, to contextual states like window measurement and posture—you’ll be able to construct deeply responsive experiences. Efficiency is baked in with derivedMediaQuery to deal with high-frequency updates, whereas the flexibility to override scopes makes testing and previews seamless throughout {hardware} configurations.

Beforehand, to get entry to sure machine properties — like if a tool was in tabletop mode — you’d want to jot down a whole lot of boilerplate to take action:

@Composable
enjoyable isTabletopPosture(
    context: Context = LocalContext.present
): Boolean {
    val windowLayoutInfo by
        WindowInfoTracker
            .getOrCreate(context)
            .windowLayoutInfo(context)
            .collectAsStateWithLifecycle(null)

    return windowLayoutInfo.displayFeatures.any { displayFeature ->
        displayFeature is FoldingFeature &&
            displayFeature.state == FoldingFeature.State.HALF_OPENED &&
            displayFeature.orientation == FoldingFeature.Orientation.HORIZONTAL
    }
}

@Composable
enjoyable VideoPlayer() {
    if(isTabletopPosture()) {
        TabletopLayout()
    } else {
        FlatLayout()
    }
}

Now, with UIMediaQuery, you’ll be able to add the mediaQuery syntax to question machine properties, comparable to if a tool is in tabletop mode:

@OptIn(ExperimentalMediaQueryApi::class)
@Composable
enjoyable VideoPlayer() {
    if (mediaQuery { windowPosture == UiMediaScope.Posture.Tabletop }) {
        TabletopLayout()
    } else {
        FlatLayout()
    }
}

Take a look at the documentation and file any bugs right here.

Grid (Experimental)

Grid is a robust new API for constructing complicated, two-dimensional layouts in Jetpack Compose. Whereas Row and Column are nice for linear designs, Grid provides you the structural management wanted for screen-level structure and complex parts with out the overhead of a scrollable record.

Grid permits you to outline your structure utilizing tracks, gaps, and cells, providing acquainted sizing choices like Dp, percentages, intrinsic content material sizes, and versatile “Fr” items.

@OptIn(ExperimentalGridApi::class)

@Composable

enjoyable GridExample() {

    Grid(

        config = {

            repeat(4) { column(0.25f) }

            repeat(2) { row(0.5f) }

            hole(16.dp)

        }

    ) {

        Card1(modifier = Modifier.gridItem(rowSpan = 2)

        Card2(modifier = Modifier.gridItem(colmnSpan = 3)

        Card3(modifier = Modifier.gridItem(columnSpan = 2)

        Card4()

    }

}

You may place objects robotically or explicitly span them throughout a number of rows and columns for precision. Better of all, it’s extremely adaptive—you’ll be able to dynamically reconfigure your grid tracks and spans to answer machine states like tabletop mode or orientation modifications, making certain your UI appears to be like nice throughout kind components.

Take a look at the documentation and file any bugs right here.

FlexBox (Experimental)

FlexBox is a structure container designed for prime efficiency, adaptive UIs. It manages merchandise sizing and house distribution based mostly on obtainable container dimensions. It handles complicated duties like wrapping (wrap) and multi-axis alignment of things (justifyContent, alignItems, alignContent). It permits objects to develop (develop) or shrink (shrink) to fill the container.

@OptIn(ExperimentalFlexBoxApi::class)
enjoyable FlexBoxWrapping(){
    FlexBox(
        config = {
            wrap(FlexWrap.Wrap)
            hole(8.dp)
        }
    ) {
        RedRoundedBox()
        BlueRoundedBox()
        GreenRoundedBox(modifier = Modifier.width(350.dp).flex { develop(1.0f) })
        OrangeRoundedBox(modifier = Modifier.width(200.dp).flex { develop(0.7f) })
        PinkRoundedBox(modifier = Modifier.width(200.dp).flex { develop(0.3f) })
    }
}

Take a look at the documentation and file any bugs right here.

New SlotTable implementation (Experimental)

We’ve launched a brand new implementation of the SlotTable, which is disabled by default on this launch. SlotTable is the inner information construction that the Compose runtime makes use of to trace the state of your composition hierarchy, monitor invalidations/recompositions, retailer remembered values, and monitor all metadata of the composition at runtime. This new implementation is designed to enhance efficiency, primarily round random edits.

To attempt the brand new SlotTable, allow ComposeRuntimeFlags.isLinkBufferComposerEnabled.

Begin coding at the moment!

With so many thrilling new APIs in Jetpack Compose, and lots of extra developing, it is by no means been a greater time to migrate to Jetpack Compose. As all the time, we worth your suggestions and have requests (particularly on @Experimental options which are nonetheless baking) — please file them right here. Comfortable composing!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles