What’s new in Jetpack Compose



Posted by Jolanda Verhoef, Android Developer Relations Engineer

It has been virtually two years since we launched the primary steady model of Jetpack Compose, and since then, we’ve seen its adoption and have set develop spectacularly. Whether or not you write an utility for smartphones, foldables, tablets, ChromeOS gadgets, smartwatches, or TVs, Compose has bought you coated! We advocate you to make use of Compose for all new Put on OS, telephone and large-screen apps. With new tooling and library options, prolonged Materials Design 3, giant display, and Put on OS help, and alpha variations of Compose for homescreen widgets and TV… That is an thrilling time!

Compose in the neighborhood

Within the final 12 months, we’ve seen many firms investigating and selecting Compose to construct new options and migrate screens of their manufacturing functions. 24% of the highest 1000 apps on Google Play have already chosen to undertake Compose! For instance, Dropbox engineers informed us that they rewrote their search expertise in Compose in only a few weeks, which was 40% much less time than anticipated, and fewer than half the time it took the workforce to construct the function on iOS. Additionally they shared that they have been thinking about adopting Compose “due to its first-class help for design programs and tooling help”. Our Google Drive workforce minimize their growth time practically in half when utilizing Compose mixed with structure enhancements.

It’s nice to see how these groups expertise sooner growth cycles, and in addition really feel their UI code is extra testable. Impressed? Begin by studying our information The right way to Undertake Compose on your Group, which outlines how and the place to start out, and exhibits the areas of growth the place Compose can carry large added worth.

Library options & growth

Since we launched the primary Compose Invoice of Supplies in October final 12 months, we’ve been engaged on new options, bug fixes, efficiency enhancements, and bringing Compose to in all places you construct UI: telephones, tablets, foldables, watches, TV, and your property display. Yow will discover all modifications within the Could 2023 launch and the newest alpha variations of the Compose libraries.

We’ve heard from you that efficiency is one thing you care about, and that it’s not all the time clear create performant Compose functions. We’re constantly bettering the efficiency of Compose. For instance, as of final October, we began migrating modifiers to a brand new and extra environment friendly system, and we’re beginning to see the outcomes of that migration. For textual content alone, this work resulted in a mean 22% efficiency achieve that may be seen within the newest alpha launch, and these enhancements apply throughout the board. To get these advantages in your app, all it’s a must to do is replace your Compose model!

Textual content and TextField bought many upgrades prior to now months. Subsequent to the efficiency enhancements we already talked about, Compose now helps the most recent emoji model 🫶 and consists of new textual content options similar to outlining textual content, hyphenation help, and configuring line breaking habits. Learn extra within the launch notes of the compose-foundation and compose-ui libraries.

The brand new pager element means that you can horizontally or vertically flip by means of content material, which has similarities to ViewPager2 in Views. It permits deep customization choices, making it doable to create visually beautiful results:

Moving image showing Hoizontal Pager composable
Select a tune utilizing the HorizontalPager composable. Learn to implement this and different fancy results in Rebecca Franks’ weblog submit.

The brand new stream layouts FlowRow and FlowColumn make it straightforward to rearrange content material in a vertical or horizontal stream, very like strains of textual content in a paragraph. Additionally they allow dynamic sizing utilizing weights to distribute the gadgets throughout the container.

Image of search filters in a real estate app created with flow layouts
Utilizing stream layouts to point out the search filters in an actual property app

To study extra in regards to the new options, efficiency enhancements, and bug fixes, see the launch notes of the most recent steady and latest alpha launch of the Compose libraries.

Instruments

Creating your app utilizing Jetpack Compose is far simpler with the brand new and improved instruments round it. We added tons of recent options to Android Studio to enhance your workflow and effectivity. Listed below are some highlights:

Android Studio Flamingo is the most recent steady launch, bringing you:

  • Undertaking templates that use Compose and Materials 3 by default, reflecting our beneficial practices.
  • Materials You dynamic colours in Compose previews to rapidly see how your composable responds to otherwise coloured wallpapers on a person system.
  • Compose features in system traces whenever you use the System Hint profiler that can assist you perceive which Compose features are being recomposed.

Android Studio Giraffe is the most recent beta launch, containing options similar to:

  • Reside Edit, permitting you to rapidly iterate in your code on emulator or bodily system with out rebuilding or redeploying your app.
  • Assist for brand spanking new animations APIs in Animation preview so you possibly can debug any animations utilizing animate*AsStateCrossFaderememberInfiniteTransition, and AnimatedContent.
  • Compose Preview now helps reside updates throughout a number of recordsdata, for instance, when you make a change in your Theme.kt file, you possibly can see all Previews updates robotically in your UI recordsdata.
  • Enhancing auto-complete habits. For instance, we now present icon previews whenever you’re including Materials icons, and we preserve the @Composable annotation when operating “Implement Members”.

Android Studio Hedgehog comprises canary options similar to:

  • Displaying Compose state info within the debugger. Whereas debugging your app, the debugger will inform you precisely which parameters have “Modified” or have remained “Unchanged”, so you possibly can extra effectively examine the reason for the recomposition.
  • You possibly can check out the brand new Studio Bot, an experimental AI powered conversational expertise in Android Studio that can assist you generate code, repair points, and study finest practices, together with all issues Compose. That is an early experiment, however we might love so that you can give it a strive!
  • Emulator help for the newly introduced Pixel Fold and Pill Digital Gadgets, so that you could check your Compose app earlier than these gadgets launch later this 12 months.
  • A brand new Espresso Machine API that permits you to apply rotation modifications, folds, and different synchronous configuration modifications to your digital gadgets below check.

We’re additionally actively engaged on visible linting and accessibility checks for previews so you possibly can robotically audit your Compose UI and verify for points throughout completely different display sizes, and on multipreview templates that can assist you rapidly add frequent units of previews.

Materials 3

Materials 3 is the beneficial design system for Android apps, and the most recent 1.1 steady launch provides plenty of nice new options. We added new parts like backside sheets, date and time pickers, search bars, tooltips, and others. We additionally graduated most of the core parts to steady, added extra movement and interplay help, and included edge-to-edge help in lots of parts. Watch this video to learn to implement Materials You in your app:

Extending Compose to extra surfaces

We wish Compose to be the programming mannequin for UI wherever you run Android. This implies together with first-class help for big screens similar to foldables and tablets and publishing libraries that make it doable to make use of Compose to put in writing your homescreen widgets, smartwatch apps, and TV functions.

Massive display help

We’ve continued our efforts to make growth for big screens straightforward whenever you use Compose. The pager and stream layouts that we launched are frequent patterns on giant display gadgets. As well as, we added a brand new Compose library that permits you to observe the system’s window dimension class so you possibly can simply construct adaptive UI.

When attaching a mouse to an Android system, Compose now accurately modifications the mouse cursor to a caret whenever you hover the cursor over textual content fields or selectable textual content. This helps the person to know what components on display they will work together with.

Moving image of Compose adjusting the mouse cursor to a caret when the mouse is hovering over text field

Look

Immediately we publish the primary beta model of the Jetpack Look library! Look allows you to develop widgets optimized for Android telephone, pill, and foldable homescreens utilizing Jetpack Compose. The library offers you the most recent Android widget enhancements out of the field, utilizing Kotlin and Compose:

  • Look simplifies the implementation of interactive widgets, so you possibly can showcase your app’s prime options, proper on a person’s dwelling display.
  • Look makes it straightforward to construct responsive widgets that look nice throughout kind components.
  • Look allows sooner UI Iteration along with your designers, guaranteeing a top quality person expertise.
Image of search filters in a real estate app created with flow layouts

Put on OS

We launched Compose for Put on OS 1.1 steady final December, and we’re working laborious on the brand new 1.2 launch which is at the moment in alpha. Right here’s among the highlights of the continual enhancements and new options that we’re bringing to your wrist:

  • The placeholder and placeholderShimmer add elegant loading animations that can be utilized on chips and playing cards whereas content material is loading.
  • expandableItems make it doable to fold lengthy lists or lengthy textual content, and solely increase to point out their full size upon person interplay.
  • Rotary enter enhancements out there in Horologist add intuitive snap and fling behaviors when a person is navigating lists with rotary enter.
  • Android Studio now allows you to preview a number of watch display and textual content sizes whereas constructing a Compose app. Use the Annotations that we have now added right here.

Compose for TV

Now you can construct pixel good front room experiences with the alpha launch of Compose for TV! With the brand new AndroidX TV library, you possibly can apply all the advantages of Compose to the distinctive necessities for Android TV. We labored intently with the group to construct an intuitive API with highly effective capabilities. Engineers from Soundcloud shared with us that “because of Compose for TV, we’re in a position to reuse parts and transfer a lot sooner than the outdated Leanback View APIs would have ever allowed us to.” And Plex shared that “TV focus and scrolling help on Compose has enormously improved our developer productiveness and app efficiency.”

Compose for TV comes with quite a lot of parts similar to ImmersiveList and Carousel which are particularly optimized for the lounge expertise. With only a few strains of code, you possibly can create nice TV UIs.

Moving image of TVLazyGrid on a screen

TvLazyColumn {
 
gadgets(contentList) { content material ->
    TvLazyRow {
gadgets(content material) { cardItem ->
Card(cardItem)
}
  }
}

Be taught extra in regards to the launch on this weblog submit, take a look at the “What’s new with TV and intro to Compose” discuss, or see the TV documentation!

Compose help in different libraries

It’s nice to see increasingly more internally and externally developed libraries add help for Compose. For instance, loading photos asynchronously can now be performed with the GlideImage composable from the Glide library. And Google Maps launched a library which makes it a lot simpler to declaratively create your map implementations.

GoogleMap(

) {
Marker(
state = MarkerState(place = LatLng(-34, 151)),
title = "Marker in Sydney"
)
Marker(
state = MarkerState(place = LatLng(35.66, 139.6)),
title = "Marker in Tokyo"
)
}

New and up to date steering

Irrespective of the place you’re in your studying journey, we’ve bought you coated! We added and revamped plenty of the steering on Compose:

Glad Composing!

We hope you are as excited by these developments as we’re! If you have not began but, it is time to study Jetpack Compose and see how your workforce and growth course of can profit from it. Prepare for improved velocity and productiveness. Glad Composing!



Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles