Android Weekly Notes

Android Weekly Notes #486

2021-11-09  本文已影响0人  圣骑士wind

Android Weekly Issue #486

All About Opt-In Annotations

Kotlin中的opt-in机制.

有一些api直接使用, 会有警告, 加上这些标记表明自己是故意为之.

This can guarantee that there has been a conscious decision made about using the API on the use site.

本文示例了:

还有java, android, api verification.

Measure, measure, measure

如何测量Android的build time.

Jetpack Compose Side-Effects III— rememberUpdatedState

rememberUpdatedState保持一个更新的引用.

@Composable
fun Timer(
    buttonColour: String
) {
    val timerDuration = 5000L
    println("Composing timer with colour : $buttonColour")
    val buttonColorUpdated by rememberUpdatedState(newValue = buttonColour)
    LaunchedEffect(key1 = Unit, block = {
        startTimer(timerDuration) {
            println("Timer ended")
            println("[1] Last pressed button color is $buttonColour")
            println("[2] Last pressed button color is $buttonColorUpdated")
        }
    })
}

如果不用这个rememberUpdatedState, composable的参数变了, 但是launchedeffect不会重新进, 永远是第一次的值.

Compose Destinations: a simpler, safer way to navigate in Jetpack Compose

一个用于Compose导航的代码生成库: compose-destinations

讨论了传参数的方式.

代码生成是KSP, 比较先进.

How to Share Composable as Bitmap

从Composable生成Bitmap.

Exception handling in Kotlin Coroutines

协程中的异常处理.

Repository Pattern with Jetpack Compose

Repository pattern和Compose一起, 做了一个搜索单词的sample.

Speed up your build: Non-transitive R files

可以使build更快, 包体积更小.

Code

上一篇下一篇

猜你喜欢

热点阅读