Posted by Jolanda Verhoef, Android Developer Relations Engineer
At the moment, as a part of the Compose March ‘23 Invoice of Supplies, we’re releasing model 1.4 of Jetpack Compose, Android’s fashionable, native UI toolkit that’s utilized by apps reminiscent of Reserving.com, Pinterest, and Airbnb. This launch comprises new options like Pager and Move Layouts, and new methods to model your textual content, reminiscent of hyphenation and line-break habits. It additionally improves the efficiency of modifiers and fixes various bugs.
Swipe by way of content material with the brand new Pager composable
Compose now consists of out-of-the-box assist for vertical and horizontal paging between completely different content material. Utilizing VerticalPager or HorizontalPager allows related performance to the ViewPager within the view system. Nevertheless, similar to the advantages of utilizing LazyRow and LazyColumn, you not must create an adapter or fragments! You possibly can merely embed a composable contained in the Pager:
These composables substitute the implementation within the Accompanist library. If you happen to already use the Accompanist implementation, take a look at the migration information. See the Pager documentation for extra info.
Get your content material flowing with the brand new Move Layouts
FlowRow and FlowColumn present an environment friendly and compact means to put out gadgets in a container when the dimensions of the gadgets or the container are unknown or dynamic. These containers enable the gadgets to stream to the subsequent row within the FlowRow or subsequent column within the FlowColumn after they run out of area. These stream layouts additionally enable for dynamic sizing utilizing weights to distribute the gadgets throughout the container.
Right here’s an instance that implements a listing of filters for an actual property app:
Efficiency enhancements in Modifiers
The main inside Modifier refactor we began within the October launch has continued, with the migration of a number of foundational modifiers to the brand new Modifier.Node structure. This consists of graphicsLayer, decrease stage focus modifiers, padding, offset, and extra. This refactoring ought to deliver efficiency enhancements to those APIs, and you do not have to vary your code to obtain these advantages. Work on this continues, and we count on much more positive aspects in future releases as we migrate Modifiers outdoors of the ui module. Be taught extra concerning the rationale behind the modifications within the ADS discuss Compose Modifiers deep dive.
Elevated flexibility of Textual content and TextField
Together with numerous efficiency enhancements, API stabilizations, and bug fixes, the compose-text 1.4 launch brings assist for the newest emoji model, together with backwards compatibility with older Android variations 🎉🙌. Supporting this requires no modifications to your software. If you happen to’re utilizing a customized emoji answer, be certain to take a look at PlatformTextStyle(emojiSupportMatch).
As well as, we’ve addressed one of many primary ache factors of utilizing TextField. In some situations, a textual content area inside a scrollable Column or LazyColumn could be obscured by the on-screen keyboard after being targeted. We re-worked core elements of scroll and focus logic, and added key APIs like PinnableContainer to repair this bug.
Lastly, we added loads of new customization choices to Textual content and its TextStyle:
- Draw outlined textual content utilizing TextStyle.drawStyle.
- Enhance textual content transition and legibility throughout animations utilizing TextStyle.textMotion.
- Configure line breaking habits utilizing TextStyle.lineBreak. Use built-in semantic configurations like Heading, Paragraph, or Easy, or assemble your individual LineBreak configuration with the specified Technique, Strictness, and WordBreak values.
- Add hyphenation assist utilizing TextStyle.hyphens.
- Outline a minimal variety of seen strains utilizing the minLines parameter of the Textual content and TextField composables.
- Make your textual content transfer by making use of the basicMarquee modifier. As a bonus, as a result of this can be a Modifier, you may apply it to any arbitrary composable to make it transfer in an identical marquee-like trend!
|Marquee textual content utilizing define with shapes stamped on it utilizing the drawStyle API.
Enhancements and fixes for core options
In response to developer suggestions, we now have shipped some notably in-demand options & bug fixes in our core libraries:
- Check waitUntil now accepts a matcher! You need to use this API to simply synchronize your take a look at together with your UI, with particular situations that you simply outline.
- animatedContent now accurately helps getting interrupted and returning to its earlier state.
- Accessibility providers focus order has been improved: the sequence is now extra logical in widespread conditions, reminiscent of with prime/backside bars.
- AndroidView is now reusable in LazyList should you present an non-obligatory onReset lambda. This enchancment allows you to use complicated non-Compose-based Views inside LazyLists.
- Colour.lerp efficiency has been improved and now does zero allocations: since this technique is known as at excessive frequency throughout fade animations, this could cut back the quantity of rubbish assortment pauses, particularly on older Android variations.
- Many different minor APIs and bug fixes as a part of a basic cleanup. For extra info, see the launch notes.
We’re grateful for all the bug stories and have requests submitted to our concern tracker – they assist us to enhance Compose and construct the APIs you want. Proceed offering your suggestions, and assist us make Compose higher!
Questioning what’s subsequent? Try our up to date roadmap to see the options we’re presently desirous about and dealing on. We will’t wait to see what you construct subsequent!
Completely happy composing!