Hey all - I've got an issue that I don't fully und...
# compose
e
Hey all - I've got an issue that I don't fully understand with MutableStateFlow not triggering a re-compose when a deeply nested value changes. Basically, radio buttons set their value based on their status in state. When one is pressed, it toggles its value in state. Ideally, this should trigger a recompose but it doesn't. Made a little repro here if someone has any thoughts. https://github.com/boggsey/stateflow-test
It feels like I'm fundamentally not understanding something about Lists or about how Stateflow subscribes
z
I think your main problem is here:
map
just returns a new list with the result of the map function, so if you’re not assigning the returned value to anything it’s effectively a no-op.
👍 1
I don’t understand what problem that
deepCopy
is trying to solve.
I think a better approach to selection would be for your view model to expose a
selectedId
property, which your composable could then compare to each article ID. That way you don’t need to walk the entire list in your view model every time the selection changes, and it means that if only the selection changes then only the two rows that actually had their selection state change need to recompose.
a
The main issue I see is the
var isSelected: Boolean
in your
Tag
class. This means that you have a mutable object inside an observable type, and the observable type has no way of knowing when the mutable object changes.
👍 1
z
Oh i missed that, yea that’s no good either.
e
Ok, this is all helpful. I'm new to Kotlin and Android, so still figuring it all out. Regarding deepCopy, I wasn't sure how to push a deeply nested change as something that would trigger StateFlow to recognize the change
z
I wasn’t sure how to push a deeply nested change as something that would trigger StateFlow to recognize the change
As long as the equals method returns false, that will happen.
e
Thanks all! This sent me down the right path. Appreciate the help!
🎉 1