diff --git a/README.md b/README.md index 62e8531..3840a36 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [从 Kotlin 到 Kotlin Multiplatform](https://git.itouc.cn/ITStudio_OUC/From_Kotlin_to_Kotlin-Multiplatform) -完全掌握:引入 Kotlin,进入 KMP +完全掌握:引入 Kotlin,第一个 KMP 应用 简单了解:深入 Kotlin diff --git a/shared/src/commonMain/kotlin/cn/itouc/git/diceroller/App.kt b/shared/src/commonMain/kotlin/cn/itouc/git/diceroller/App.kt index 25f5b1d..b596ffd 100644 --- a/shared/src/commonMain/kotlin/cn/itouc/git/diceroller/App.kt +++ b/shared/src/commonMain/kotlin/cn/itouc/git/diceroller/App.kt @@ -25,7 +25,7 @@ import kotlin.random.Random fun App() { MaterialTheme { var showContent by remember { mutableStateOf(false) } - val r by remember(showContent) { mutableStateOf(Random.nextInt()) } + var randomInt by remember { mutableStateOf(Random.nextInt()) } Column( modifier = Modifier @@ -34,7 +34,12 @@ fun App() { .fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally, ) { - Button(onClick = { showContent = !showContent }) { + Button( + onClick = { + showContent = !showContent + if (showContent) randomInt = Random.nextInt() + } + ) { Text("Click me!") } AnimatedVisibility(showContent) { @@ -43,7 +48,7 @@ fun App() { horizontalAlignment = Alignment.CenterHorizontally, ) { Image(painterResource(Res.drawable.compose_multiplatform), null) - Text("a random int: $r") + Text("a random int: $randomInt") } } }