Android Weekly Issue #484
Don't let ViewModel know about framework level dependencies
ViewModel不應(yīng)該有framework的依賴.
文章里測試的寫法是那種嵌套的, 跟iOS很像的.
代碼: https://github.com/PatilShreyas/ViewModelGoodPractice
Testing Hybrid Jetpack Compose Apps
如何測試XML和Compose混合的UI.
Lift on scroll in Jetpack Compose
Top app bar在下面的內(nèi)容滾動上來以后, 會有一個(gè)高度提升顯示陰影的效果.
如何在Compose上實(shí)現(xiàn)這種liftOnScroll的效果呢.
val LazyListState.elevation: Dp
get() = if (firstVisibleItemIndex == 0) {
// For the first element, use the minimum of scroll offset and default elevation
// i.e. a value between 0 and 4.dp
minOf(firstVisibleItemScrollOffset.toFloat().dp, AppBarDefaults.TopAppBarElevation)
} else {
// If not the first element, always set elevation and show the shadow
AppBarDefaults.TopAppBarElevation
}
Composing palettes
Compose的調(diào)色板.
可以從Bitmap提取顏色.
demo: https://github.com/tkuenneth/android-demos/tree/master/misc/PaletteDemo
Effective Kotlin Item 50: Eliminate obsolete object references
我們要注意不要持有已經(jīng)不用的對象的引用.
尤其是這個(gè)對象很大或者很多的時(shí)候.
Exact alarm improvements-Android12
Android 12對鬧鐘的改進(jìn).
How to master Swipeable and NestedScroll modifiers in Jetpack Compose
要實(shí)現(xiàn)一個(gè)bottom sheet, 展開后是parent的全部高度, 內(nèi)容可以滾動, 但是header保持不動.
整體的實(shí)現(xiàn):
https://gist.github.com/arcadefire/7fe138c0ded1a36bee6dd57acdfa3d18
Using WorkManager on Android 12
Android 12加了前臺服務(wù)的啟動限制:
https://developer.android.com/about/versions/12/foreground-services
也就是說, 除了一些特殊情況, Android 12上不允許從后臺啟動前臺服務(wù).
所以在WorkManager 2.7開始, 對緊急的任務(wù)( expedited jobs)做了處理.
val request = OneTimeWorkRequestBuilder<HighPriorityWorker>()
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
.build()
WorkManager.getInstance(context).enqueue(request)
Controlling TextView MinWidth
關(guān)于TextView的最小寬度控制.
Seeing What Talkback Sees
可以查看Talkback看到的文字, debug accessibility的信息.
Code
- https://github.com/kojofosu/Quantitizer
- https://github.com/microsoft/surface-duo-window-manager-samples/tree/main/TravelPlanner
- https://github.com/manueldidonna/waves-timer-animation 倒計(jì)時(shí), 有一個(gè)水流向下的動畫.
- https://github.com/sarnavakonar/Gamebaaz 一個(gè)用kotlin做前后端的完整應(yīng)用.
- https://github.com/square/workflow-kotlin 狀態(tài)機(jī).