Android Weekly Issue #500
Screen templates — using Compose, SwiftUI & KMM
KMM下Compose和SwiftUI的跨平臺解決方案.
ViewModel和State是同一份. 但是UI模板代碼是各個平臺各一份.
Detect text overflow in Jetpack Compose
一個超出后顯示末尾badge count的compose實現(xiàn).
Tiny things on big screens
在平板上顯示空間太大了怎么辦?
有時候可能沒有master detail的需求.
不想展示很大的button, 也不想隔很遠(yuǎn)的距離.
首先用BoxWithConstraints
把內(nèi)容居中, 并且設(shè)置最大寬度.
有劉海怎么辦? 用WindowManager
. 需要添加依賴.
Automatic screenshot testing for all your Compose @Previews
- airbnb的Showkase library: https://github.com/airbnb/Showkase
- facebook的: https://github.com/facebook/screenshot-tests-for-android
- Shot: https://github.com/pedrovgs/Shot
截圖測試:
@ShowkaseScreenshot(rootShowkaseClass = ShowkaseRoot::class)
abstract class ComposeTests : ShowkaseScreenshotTest {
override fun onScreenshot(
id: String,
name: String,
group: String,
styleName: String?,
screenshotType: ShowkaseScreenshotType,
screenshotBitmap: Bitmap
) {
val view = ImageView(InstrumentationRegistry.getInstrumentation().context)
view.setImageBitmap(screenshotBitmap)
ViewHelpers.setupView(view).setExactWidthPx(screenshotBitmap.width).setExactHeightPx(screenshotBitmap.height).layout()
Screenshot.snap(view).setName("$group - $name").record()
}
}
這個居然是把Compose轉(zhuǎn)為View來測.
Things you should know about Coroutines. Part 4
協(xié)程的異常處理, 文章配圖不錯.
WorkManager multi-process for libraries
LeakCanary用了WorkManager.