Android Weekly Issue #465
Learning Live Templates for Jetpack Compose
如何创建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切换的效果实现.
最终代码有一个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