Android Weekly Notes #500

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实现.

Tiny things on big screens

在平板上显示空间太大了怎么办?

有时候可能没有master detail的需求.
不想展示很大的button, 也不想隔很远的距离.

首先用BoxWithConstraints把内容居中, 并且设置最大宽度.

有刘海怎么办? 用WindowManager. 需要添加依赖.

Automatic screenshot testing for all your Compose @Previews

截图测试:

@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转为View来测.

Things you should know about Coroutines. Part 4

协程的异常处理, 文章配图不错.

WorkManager multi-process for libraries

LeakCanary用了WorkManager.

Code

推荐阅读更多精彩内容