Posted by Jolanda Verhoef, Android Developer Relations Engineer
At present, as a part of the Compose March ‘23 Invoice of Supplies, we’re releasing model 1.4 of Jetpack Compose, Android’s trendy, native UI toolkit that’s utilized by apps resembling Reserving.com, Pinterest, and Airbnb. This launch comprises new options like Pager and Move Layouts, and new methods to fashion your textual content, resembling hyphenation and line-break conduct. It additionally improves the efficiency of modifiers and fixes a lot of bugs.
Swipe via 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 comparable 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’ll be able to merely embed a composable contained in the Pager:
|
These composables substitute the implementation within the Accompanist library. In the event you 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 approach 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 once they run out of house. 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 most important 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 degree focus modifiers, padding, offset, and extra. This refactoring ought to carry efficiency enhancements to those APIs, and you do not have to alter your code to obtain these advantages. Work on this continues, and we count on much more positive factors in future releases as we migrate Modifiers outdoors of the ui module. Be taught extra concerning the rationale behind the adjustments within the ADS speak 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 adjustments to your software. In the event you’re utilizing a customized emoji resolution, be sure that 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 can be obscured by the on-screen keyboard after being targeted. We re-worked core components of scroll and focus logic, and added key APIs like PinnableContainer to repair this bug.
Lastly, we added quite a lot 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 conduct 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 traces 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 it is a Modifier, you possibly can apply it to any arbitrary composable to make it transfer in an analogous marquee-like style!
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 have now shipped some significantly in-demand options & bug fixes in our core libraries:
- Check waitUntil now accepts a matcher! You should utilize this API to simply synchronize your check together with your UI, with particular situations that you just outline.
- animatedContent now appropriately 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, resembling with high/backside bars.
- AndroidView is now reusable in LazyList when you present an elective onReset lambda. This enchancment helps you to use advanced non-Compose-based Views inside LazyLists.
- Shade.lerp efficiency has been improved and now does zero allocations: since this methodology is named at excessive frequency throughout fade animations, this could scale back the quantity of rubbish assortment pauses, particularly on older Android variations.
- Many different minor APIs and bug fixes as a part of a common cleanup. For extra info, see the launch notes.
Get began!
We’re grateful for all the bug studies 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? Take a look at our up to date roadmap to see the options we’re presently serious about and dealing on. We are able to’t wait to see what you construct subsequent!
Pleased composing!