This commit is contained in:
SOR
2026-09-21 14:36:26 +08:00
parent 323ec8732b
commit ddd4b1a481
2 changed files with 9 additions and 4 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
[从 Kotlin 到 Kotlin Multiplatform](https://git.itouc.cn/ITStudio_OUC/From_Kotlin_to_Kotlin-Multiplatform) [从 Kotlin 到 Kotlin Multiplatform](https://git.itouc.cn/ITStudio_OUC/From_Kotlin_to_Kotlin-Multiplatform)
完全掌握:引入 Kotlin,进入 KMP 完全掌握:引入 Kotlin,第一个 KMP 应用
简单了解:深入 Kotlin 简单了解:深入 Kotlin
@@ -25,7 +25,7 @@ import kotlin.random.Random
fun App() { fun App() {
MaterialTheme { MaterialTheme {
var showContent by remember { mutableStateOf(false) } var showContent by remember { mutableStateOf(false) }
val r by remember(showContent) { mutableStateOf(Random.nextInt()) } var randomInt by remember { mutableStateOf(Random.nextInt()) }
Column( Column(
modifier = Modifier modifier = Modifier
@@ -34,7 +34,12 @@ fun App() {
.fillMaxSize(), .fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
) { ) {
Button(onClick = { showContent = !showContent }) { Button(
onClick = {
showContent = !showContent
if (showContent) randomInt = Random.nextInt()
}
) {
Text("Click me!") Text("Click me!")
} }
AnimatedVisibility(showContent) { AnimatedVisibility(showContent) {
@@ -43,7 +48,7 @@ fun App() {
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
) { ) {
Image(painterResource(Res.drawable.compose_multiplatform), null) Image(painterResource(Res.drawable.compose_multiplatform), null)
Text("a random int: $r") Text("a random int: $randomInt")
} }
} }
} }