Android Weekly Notes #486 Android Weekly Issue #486

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章