I updated to `0.4.0-rc2` version (from `0.4.0-buil...
# compose-desktop
j
I updated to
0.4.0-rc2
version (from
0.4.0-build189
) and now seeing what looks like change in recomposition behaviour...more in thread...
I have
Copy code
var selectedPerson by remember { mutableStateOf("") }

PersonList(peopleState, selectedPerson) {
    selectedPerson = it.name
}
and later on in same function I have following that used to be invoked when
selectedPerson
was updated (after user selected in list) but doesn't seem to be any more
Copy code
PersonDetailsView(selectedPerson)
maybe something I was doing wrong from the start that's only manifesting itself now
j
It is super hard for me to reason about what's going on in that code. As a general rule of thumb, assigning to a variable in a parent scope from within a composable lambda is a huge nono. I think we have a bug open to make that a warning/error.
j
what would the general pattern be for master/detail UI like that where selection of entry in list should cause detail to be updated?
in terms of triggering the appropriate recomposition/update
j
Oh, personSelected is not composable...
personSelected : (person : Assignment) -> Unit
sorry, I miss-read the code. That seems fine.
I saw what looked like a Composable call with a trailing lambda and assumed it was a children lambda
I might suggest making that lambda be a non-trailing lambda, move it in front of the
selectedPerson
parameter so it doesn't end up in the trailing lambda position
but that doesn't answer your original question
j
what's the reason for not having that as a trailing lambda?
j
Because readers will assume it's composable
j
ok, see what you mean
j
I tried running your gist to minimize it, but it had some dependencies and I wasn't sure if I was going to break your repo when removing all those dependencies. Can you simplify it a little to be self-contained and not involve complex data types/dependencies?
j
yeah, will do that now
hmm, I was paring it down and it started working again! seems to be somehow related to implementation of
PersonDetailsView
- can't remember history of why that's exactly way that is but if I use say normal
Column
there it works.... Here's a gist with failing code (with no other dependencies I think) https://gist.github.com/joreilly/4541a4245ca5964b391884dd2c9438a3
so, I probably mischaracterised this earlier as being related to not recomposing...
or at least in terms of
PersonDetailsView
being invoked....could it be somehow related to some caching behaviour related to
item
(just clutching at straws here!)
so, following works (passing in key in to
item
)
Copy code
@Composable
fun PersonDetailsView(personName: String) {
    LazyColumn(
        modifier = Modifier.padding(16.dp).fillMaxWidth(),
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        item(personName) {
            Text(personName, style = MaterialTheme.typography.h4)
        }
    }
}