Aaron Yoder
11/11/2021, 1:15 AMif(model.shouldShow()) { // Doesn't show/hide
Text("Title")
TextField(...)
Button(...)
}
Text("Title")
TextField(...)
if(model.shouldShow()) { // Does show/hide
Button(...)
}
Tobias Suchalla
11/11/2021, 6:47 AMderivedStateOf
(if your list is an observable state):
val shouldShow by derivedStateOf { list.size > 0 }
Zach Klippenstein (he/him) [MOD]
11/11/2021, 2:49 PMAaron Yoder
11/11/2021, 5:00 PMZach Klippenstein (he/him) [MOD]
11/11/2021, 5:02 PMAaron Yoder
11/11/2021, 5:02 PMZach Klippenstein (he/him) [MOD]
11/11/2021, 5:06 PMMutableState
– MutableState
only sends change notifications when its reference changes, so if you’re mutating the same list then no change notifications get sentAaron Yoder
11/11/2021, 5:06 PMZach Klippenstein (he/him) [MOD]
11/11/2021, 5:08 PMmutableStateMapOf
if you don’t want to do thatAaron Yoder
11/11/2021, 5:10 PMZach Klippenstein (he/him) [MOD]
11/11/2021, 5:11 PMStateFlow
, or BehaviorSubject
, or etc) with an immutable collection, or use a collection type that is aware of the snapshot state system.Aaron Yoder
11/11/2021, 5:12 PMZach Klippenstein (he/him) [MOD]
11/11/2021, 5:12 PMUnit
as the value typeAaron Yoder
11/12/2021, 4:50 PMmutableStateOf
and observe that, and change the state of the boolean upon selection/deselection since that was the goal anyway (to make UI appear or disappear based on whether something is selected or not).