hi, я недавно нашел использование для мульти платформы Kotlin и Kotlin (KMP), , в котором используется JetPack Compose. Я довольно новичок в них обоих, но не программирование. Now the following code works fine for hoisting state, but I want to understand why, because I don't see how the Child is connected to the Parent.
Here's code that works, and updates count as it should:
Код: Выделить всё
@Composable
fun Parent() {
var count by rememberSaveable { mutableStateOf(0) }
Child(count, { count++ })
}
@Composable
fun Child(count, buttonPressed: () -> Unit) {
Text("Clicked $count times")
Button(onClick = buttonPressed, Modifier.padding(100.dp)) {
// if I do println("here"), the following Text() will only run once,
// so this part of the UI isn't rewritten on subsequent clicks
Text("Click to add")
}
}
@Composable
fun App() {
Parent()
}
fun main() = application {
Window(
onCloseRequest = ::exitApplication,
title = "MyProgramTitle",
) {
App()
}
}
Код: Выделить всё
Parent(increaseBy=0)
// Inside Child()...
Button(onClick = Parent(increaseBy=1))
»кнопки являются фундаментальными компонентами, которые позволяют пользователю запускать определенное действие."
, но это только вызывает пустое lambda. />
Код: Выделить всё
onClick< /code> говорит это: < /p>
«Функция, которую система вызывает, когда пользователь нажимает кнопку». Нет int Так я прав?? Как обновлять счет ?
Подробнее здесь: https://stackoverflow.com/questions/797 ... -in-the-pa
Мобильная версия