chanjungskim
03/07/2023, 3:51 AMchanjungskim
03/07/2023, 3:52 AMvalue
when onClear is called.
@Composable
fun NumberTypeQuestionLayout(
min: Int,
max: Int,
hint: String,
onClear: () -> Unit,
onAnswer: (HashMap<String, String>) -> Unit,
modifier: Modifier = Modifier
) {
// FIXME
var value by rememberSaveable { mutableStateOf("") }
}
Is there anything something similar to listener in compose?Pablichjenkov
03/07/2023, 4:12 AMchanjungskim
03/07/2023, 4:19 AMPablichjenkov
03/07/2023, 4:42 AMclass ParentState {
val childStates: List<ChildState> = …
…
val callbackForChildren: Callback
…
interface Callback {
fun childRequestSomething(childId: Int)
}
}
Composable
fun Parent(parentState: ParentState) {
…
for (i in 0 .. 10) {
Child(parentState.childStates[i], parentState.callbackForChildren)
}
…
}
Composable
fun Child(childState: ChildState, parentCallback: ParentState.ChildCallback) {
…
onClick {
parentCallback.childRequestSomething(childState.ID)
}
…
}
Pablichjenkov
03/07/2023, 4:44 AMPablichjenkov
03/07/2023, 4:47 AMchanjungskim
03/07/2023, 4:48 AMchanjungskim
03/07/2023, 5:14 AM@Composable
fun Child(
childData: ChildData,
childState: ChildState,
parentCallback: ParentState.ChildCallback
) {
var value by rememberSaveable { mutableStateOf("") }
// TODO: update value to "" with parentCallback
}
It will be something like this:
@Composable
fun Parent(
parentData: ParentData
){
val parentState: ParentState
Row{
Child(childData, childState, parentCallback)
Button(
onClick = {
parentState.fetchNextQuestion()
}
){
Text(text="next")
}
}
}
Pablichjenkov
03/07/2023, 6:09 AMvar value by rememberSaveable { mutableStateOf("") }
Could you use a key in rememberSaveable.Pablichjenkov
03/07/2023, 6:14 AMfetchNextQuestion()
should mutate some State in the parent State that triggers recomposition, in which you pass the new state to the children. I am running out of time now but I might do a little example latter, kind of intrigue me.