It's been almost a year since the official release of Jetpack Compose 1.0 , and we're seeing the community adopting and using Compose with great enthusiasm: the simplicity of Kotlin syntax and the declarative approach to development that makes the development interface faster and easier It has been appreciated by the majority of developers.
Compose response in the community
We're seeing companies adopting Compose at scale to develop the latest and most creative features for their apps. For example, the Play Store team we work closely with has been using Compose early on , and through them we've learned that using Compose is not only more fun, but also a huge benefit to their team's productivity. The Play Store team also told us that "all of the new Play Store features are built on top of this framework, and Compose helps unlock faster and smoother releases for apps". Meanwhile, Twitter has benefited from using Jetpack Compose in different parts of the app because "Compose makes it easier for us to define our own components and makes their APIs more explicit, flexible, and intuitive." The Airbnb team also uses Compose: "Jetpack Compose is an important part of our technology strategy, resulting in a significant increase in productivity."
We are pleased to see that these teams carefully evaluate and use Compose in large-scale and complex production environments, and the result is not only clearer and more interesting interface development, but also more engineering benefits. . These are just a few examples, as more than 100 of the top 1,000 apps on the Play Store are using Compose.
We've worked closely with these teams throughout the development process and continuously listened to feedback from the wider Android community, which is key to advancing our roadmap . Today, we're focused on delivering new APIs and feature improvements to support your more advanced needs, which, along with new tools, make it easier to build apps with Compose. Compose fundamentally changes the way interfaces are built, and to help you make the necessary mindset shift, we'll be publishing more guides, talks, and codelabs on advanced topics, as well as more in-depth videos so you can write that looks and performs just as well Applications. Here are the new features in Compose 1.2 Beta:
Compose 1.2 Beta
We released the first beta version of Compose 1.2 at this year's Google I/O conference with many features and improvements:
text improvements
font margins
We located one of the top voted issues in the issue tracker and solved it by setting includeFontPadding
as a custom parameter. We recommend that you set this value to false
, as this will result in more precise alignment of the text in the layout. We plan to make false
the default in a future release. If setting the value to false
causes problems with your app, please let us know in the above bug report. Also, when includeFontPadding
is set to false
, you can adjust the line height of Text composables by setting the lineHeightStyle
parameter. The effect of using the two parameters in combination is as follows:
△ Take a multi-line Text combinable item as an example: the picture on the left shows the effect of setting includeFontPadding to true (the current default value), and the picture on the right shows the effect of setting includeFontPadding to false and lineHeightStyle
Text(
text = myText,
style = TextStyle(
lineHeight = 2.5.em,
platformStyle = PlatformTextStyle(
includeFontPadding = false
),
lineHeightStyle = LineHeightStyle(
alignment = Alignment.Center,
trim = Trim.None
)
)
)
Downloadable fonts
Compose 1.2 also adds downloadable fonts . You can use Compose's new API to access Google Fonts asynchronously and even define alternate fonts without any complicated configuration. With downloadable fonts, you can keep your APK file size small and improve your users' system health because multiple apps can share the same fonts through a provider.
text magnifying glass
Android Text provides a magnifying glass component that makes selecting text easier. Compose now supports text magnifiers.
A magnifying glass appears when you drag the selection icon, so you can see what's under your fingertips. Compose 1.1.0 already supports magnifying glass in selected text fields, Compose 1.2.0 supports magnifying glass in both text fields and SelectionContainer l). The Compose magnifier has also been enhanced to match the precise behavior of the magnifier in View.
Layout features and improvements
lazy layout
Lazy Layout is constantly evolving, and as the grid APIs LazyVerticalGrid and LazyHorizontalGrid successfully passed the experimental use phase, we have added an experimental API - LazyLayout , which allows developers to implement custom lazy layouts. To learn more about these APIs, watch the I/O Conference talk: Lazy Layout in Compose .
Interop with CoordinatorLayout
From now on, when you nest a scroll-enabled composable in the View system CoordinatorLayout
you can ensure that their scrolling behavior is interoperable. This makes the configuration of collapsible toolbars much easier. You can call the new experimental API rememberNestedScrollInteropConnection
and pass the result of the call to the nestedScroll
modifier to enable this behavior, see this sample code to learn more:
window inset
The insets library in Accompanist has now been upgraded to the Compose Foundation library, use the WindowInsets class instead. To learn more, see the Integrating Compose with Existing Interfaces technical documentation.
window size class
To make it easier to design, develop, and test resizable layouts, we've released Window Size Classes - a subjective set of window breakpoints. They are now available in the alpha version of the new library material3-window-size-class as part of the Material 3 series of libraries. For more information on window size classes, see Supporting Different Screen Sizes and Example Implementations in Crane .
Focus on performance
We've put a lot of effort into bringing you new performance tools and guides to help you understand and improve your app's performance. These can help you more easily understand why and where your app may freeze.
Starting with Android Studio Dolphin, you can use the Layout Inspector to inspect how often composables are reorganized. Unexpectedly large reorganizations can point you to composables that can be optimized. Additionally, Android Studio Electric Eel now includes a reorganization highlight indicator, a visual aid to see which composables are reorganized and when. For more information about the new tool, check out the blog What's New in Android Studio .
△ Layout Inspector shows reorganization count and reorganization highlight indicator
Compose fundamentally changes the way you write interfaces, and you can follow our published best practices to ensure high performance in your applications. For example, you can use this document for advice on how to write and configure your Compose application for optimal performance. In the I/O talk Common performance issues in Jetpack Compose, the Compose team covers common performance mistakes and how to fix them.
Performance is an area that requires ongoing attention, and we are working to improve and expand related tools and guidelines. In the meantime, we really appreciate your feedback on all of our work to date. You can ask your development questions in the issue tracker or in the KotlinLang Slack group.
new tool
In addition to improving Compose, we've added new tools to help you use Compose more efficiently. Android Studio Dolphin is currently in beta and brings very exciting features to Compose development. In addition to reorganizing counts, the new tools include Animation Coordination, which helps you view and browse all animations at once, and MultiPreview annotations, which help you build apps for multiple screen sizes. In addition, to help you iterate quickly, Android Studio Electric Eel (Canary Edition) also brings a new feature called LiveEdit.
Check out the I/O talk: What's new in Android Dev Tools for all the details, and we'd love to get your feedback to shape Compose tools that better fit your needs.
Compose for Wear OS Beta Released
If there's anything better than Compose, it's more and more comprehensive Compose. So, we're excited to see Compose for Wear OS enter the beta stage. Following the same principles as other Jetpack libraries, Beta means it's fully functional and has a stable API, and you can start preparing to build your app for production. For more information, check out this blog post .
A better guide
We've added and revised a series of guides on Compose for your reference and study:
- Workshop and revamped codelab on working with states in Compose
- Workshop and revamped codelab on basic layouts in Compose
- New Compose Performance Documentation
- Updated custom input documentation
- I/O talk video: Common performance issues in Jetpack Compose and lazy layout in Compose
- For novice developers, check out the Android Fundamentals course: Using Compose
Happy Composing!
We expect you to be as excited about these new features as we are, and if you haven't already, now is a great time to learn about Jetpack Compose and see how it fits into your team and development process so you can experience increased productivity and developer productivity benefits. Happy Composing!
You are welcome to click here to submit feedback to us, or to share what you like and problems you find. Your feedback is very important to us, thank you for your support!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。