
作者 / Android 開發者關係工程師 Florina Muntenescu
我們一如既往地搭建產品路線圖,現在已經發布了 Jetpack Compose 的 1.1 版本,這是 Android 的現代原生界面工具包。此版本新增了一些功能,比如經過優化的焦點處理、觸摸目標值、ImageVector 緩存,和對 Android 12 拉伸滾動的支持。Compose 1.1 還讓許多之前的實驗性 API 過渡到了穩定階段,並支持新版 Kotlin。我們已經更新了示例、Codelab 和 Accompanist 開發庫,以便您與 Compose 1.1 搭配使用。產品路線圖https://developer.android.google.cn/jetpack/androidx/compose-roadmap
Jetpack Composehttps://developer.android.google.cn/compose
示例https://github.com/android/compose-samples
Codelabhttps://developer.android.google.cn/courses/pathways/compose
Accompanist 開發庫https://github.com/google/accompanist
Compose 1.1 引入了圖像矢量 (Image vector) 緩存,帶來了巨大的性能改進。我們為 painterResource API 添加了緩存機制,以緩存所有使用給定資源 ID 和主題解析的 ImageVectors 實例。緩存將在配置更改時失效。相對於 Compose 1.0,Material 組件將擴展其布局空間來滿足 Material 無障礙指南的觸摸目標值要求。例如,即使您調低 RadioButton 的大小,RadioButton's 觸摸目標的尺寸仍將擴展為至少 48x48dp。這將使得 Compose Material 與 Material Design 組件的行為保持一致,以便在混合使用 View 和 Compose 時提供一致的行為。此更改還可確保當您使用 Compose Material 組件創建界面時,能夠滿足觸摸目標無障礙功能的最低要求。無障礙指南https://material.io/design/usability/accessibility.html
觸摸目標值https://material.io/design/usability/accessibility.html#layout-and-typography
如果您發現此更改破壞了現有的布局邏輯,請將 LocalMinimumTouchTargetEnforcement 設置為 false 來禁用此行為,但此操作可能會降低應用的可用性,因此需要您格外注意,並謹慎使用。https://developer.android.google.cn/reference/kotlin/androidx/compose/material3/package-summary#LocalMinimumTouchTargetEnforcement()

△RadioButton 觸摸目標更新
左: Compose 1.0,右:Compose 1.1一些 API 從實驗版過渡到了穩定版。主要包括:
動畫相關 API,例如:EnterTransition、ExitTransition、一些 AnimatedVisibility API
矢量相關 API:rememberVectorPainter、VectorProperty、VectorConfig 和 RenderVectorGroup
EnterTransitionhttps://developer.android.google.cn/reference/kotlin/androidx/compose/animation/EnterTransitionExitTransitionhttps://developer.android.google.cn/reference/kotlin/androidx/compose/animation/ExitTransitionAnimatedVisibilityhttps://developer.android.google.cn/reference/kotlin/androidx/compose/animation/package-summary#AnimatedVisibility(kotlin.Boolean,androidx.compose.ui.Modifier,androidx.compose.animation.EnterTransition,androidx.compose.animation.ExitTransition,kotlin.String,kotlin.Function1)rememberVectorPainterhttps://developer.android.google.cn/reference/kotlin/androidx/compose/ui/graphics/vector/package-summary#rememberVectorPainter(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp,kotlin.Float,kotlin.Float,kotlin.String,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.BlendMode,kotlin.Function2)VectorPropertyhttps://developer.android.google.cn/reference/kotlin/androidx/compose/ui/graphics/vector/VectorPropertyVectorConfighttps://developer.android.google.cn/reference/kotlin/androidx/compose/ui/graphics/vector/VectorConfigRenderVectorGrouphttps://developer.android.google.cn/reference/kotlin/androidx/compose/ui/graphics/vector/package-summary#RenderVectorGroup(androidx.compose.ui.graphics.vector.VectorGroup,kotlin.collections.Map)我們一直在為 Compose 添加新功能,包括以下亮點:您使用 rememberSaveable 的同時,可以保存和恢復 AnimatedContent。您可以使用 Modifier.animateItemPlacement() 為 LazyColumn/LazyRow 項目位置進行動畫處理。您可以使用全新 BringIntoView API 向父級發送請求,以便父級滾動,將項目引入視圖。Modifier.animateItemPlacement()https://developer.android.google.cn/reference/kotlin/androidx/compose/foundation/lazy/LazyItemScope#(androidx.compose.ui.Modifier).animateItemPlacement(androidx.compose.animation.core.FiniteAnimationSpec)您可以使用 @OptIn 以試用這些全新的 API,並向我們提供反饋!https://developer.android.google.cn/reference/kotlin/androidx/annotation/OptIn注意:使用 Compose 1.1 需要使用 Kotlin 1.6.10。如需了解更多信息,您可以查看 Compose 與 Kotlin 的兼容性對應關係:https://developer.android.google.cn/jetpack/androidx/releases/compose-kotlin想知道未來計劃?您可以查看最新路線圖,了解我們目前正在評估和開發的功能,比如延遲加載項目動畫、可下載的字體、可移動的內容等等!https://developer.android.google.cn/jetpack/androidx/compose-roadmap
Jetpack Compose 現已推出穩定版本,供大家在生產環境中使用,並且會繼續添加您想要的功能。我們很高興看到成千上萬的應用已經開始在生產環境中使用 Jetpack Compose,我們迫不及待想看到您將構建的應用!我們很感激開發者們在 Alpha 版和 Beta 版期間,通過問題跟蹤頁提交的錯誤報告和功能請求,幫助我們改進了 Compose 並構建您需要的 API。歡迎您繼續與我們分享您的反饋,幫助我們讓 Compose 變得更好!也歡迎您持續關注 "Android 開發者" 微信公眾號了解更多最新內容。問題跟蹤頁https://issuetracker.google.com/issues/new?component=612128
您也可以通過下方二維碼向我們提交反饋,或分享您喜歡的內容、發現的問題。您的反饋對我們非常重要,感謝您的支持!

點擊屏末|閱讀原文|即刻了解 Jetpack Compose 更多內容
除了通過觸摸進行交互外,大屏幕設備還支持其他交互形式。設備的屏幕尺寸越大,用戶就越有可能使用鍵盤、手寫筆、鼠標、遊戲手柄或其他外接設備。如果您想提高應用在這些情況下的易用性,可以計劃支持其中一些輸入方式,如需了解更多詳情,請參閱文章:是時候為各式設備適配完善的輸入支持了