https://kotlinlang.org logo
#compose
Title
# compose
m

Mahdi

11/15/2020, 8:49 AM
Hi. I have a LiveData<List<Items> that Observe it inside composable like:
Copy code
val items = viewModel.liveDataItems.observeAsState(initial = emptyList())
After user do some action I wanna expand that specific item. For do that I will tell viewModel update expandation field of selected item. Then I will update liveDataItems and want to expandations happens. I have two problem here, first making change to list items not trigger Live Data in compose so I have to replace all data with new that specific items is updated with isExpanded=true. Second issue is with tis way I will lose my scroll point and view will render from start. How I can handle expandation like this to have
p

Pavel Marchenko

11/15/2020, 12:22 PM
Hi, first problem you mentioned actually is not a problem, this is expected behavior,
LiveData
does not observe changes inside the
data
, only changes of
data
itself. Regarding second problem, scroll position is stored in
LazyListState
or
ScrollState
or similar, depending on what scrollable composable you are using. Usually scrollable composable remembers scroll state and it survives recomposition, so to resolve this problem you need to understand why scroll state is recreated in your case, without actual code it is hard to guess.
m

Mahdi

11/16/2020, 1:23 AM
@Pavel Marchenko When one thing inside it change I thing whole thing is changed now. And this way always work for me in normal data binding or observe on old way view. But now it is not trigger. You saying that this is not problem?
33 Views