Android Weekly Issue #465
Learning Live Templates for Jetpack Compose
如何創(chuàng)建live templates.
一個有用的快捷鍵: alt + cmd + j
.
會彈出來讓你選擇包圍控件.
Jetpack Compose的一些有用的live templates.
Bottom Navigation and Navigation Drawer Using Scaffold from Jetpack Compose
這個例子既有BottomNavigation又有側面的Drawer.
ViewModel記住了當前Screen:
class MainViewModel : ViewModel() {
private val _currentScreen = MutableLiveData<Screens>(Screens.DrawerScreens.Home)
val currentScreen: LiveData<Screens> = _currentScreen
fun setCurrentScreen(screen: Screens) {
_currentScreen.value = screen
}
}
BottomBar的部分:
@Composable
fun BottomBar(modifier: Modifier = Modifier, screens: List<Screens.HomeScreens>, navController: NavController) {
BottomNavigation(modifier = modifier) {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry?.arguments?.getString(KEY_ROUTE)
screens.forEach { screen ->
BottomNavigationItem(
icon = { Icon(imageVector = screen.icon, contentDescription = "") },
label = { Text(screen.title) },
selected = currentRoute == screen.route,
onClick = {
navController.navigate(screen.route) {
popUpTo = navController.graph.startDestination
launchSingleTop = true
}
}
)
}
}
}
Back的處理:
setContent {
NavigationDrawerTheme {
CompositionLocalProvider(LocalBackPressedDispatcher provides this.onBackPressedDispatcher) {
AppScaffold()
}
}
}
How I built an "Asteroids" game using Jetpack Compose for Desktop
用Jetpack Compose Desktop搭建游戲.
全部代碼:
https://github.com/SebastianAigner/asteroids-compose-for-desktop
Jetpack Compose — Reveal effect
一個明暗Theme切換的效果實現(xiàn).
最終代碼有一個gist: https://gist.github.com/bmonjoie/8506040b2ea534eac931378348622725
Migrating From Python to Kotlin for Our Backend Services
把后端從Python遷移到kotlin了.
幾個protobuffers相關的庫:
- https://github.com/marcoferrer/kroto-plus
- https://github.com/daviddenton/protokruft
- https://github.com/grpc/grpc-kotlin
Android Lifecycle
Android的生命周期.
Supporting different screen sizes on Android with Jetpack Compose
關于不同屏幕的支持.
PS: 其實我覺得把尺寸放在xml里就好.
Things to know about Flow’s shareIn and stateIn operators
比較這兩個操作符:
例子是一個location的callback flow.
- shareIn -> SharedFlow
- stateIn -> StateFlow
舉了幾個實際的例子來說明用法, 好文章, 推薦閱讀.
Code
- KMMT 模板工程.
- asteroids-compose-for-desktop Compose桌面游戲.
- DailyDoc Compose做的note應用.
- https://github.com/mitchtabian/Food2Fork-KMM
- https://github.com/Hamza417/Inure
- https://github.com/android/compose-samples