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

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