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

Mike Speed

02/18/2022, 11:16 AM
Hi all, I have a very strange problem with my
LazyColumn
. I am updating the menuList
State
in the ViewModel, the view recomposes but the debugger gets to LazyColumn and then stops, which means the children aren’t redrawn with the new data. Any ideas why? Thanks! MyView:
Copy code
val menuList = viewModel.menuData.observeAsState()

LazyColumn() {
                items(menuList.value.size) { i->
                    MenuItem(menuList.value[i])
                }
}
MyViewModel:
Copy code
private var menu: MenuUiState? = null
val menuData: SingleLiveEvent<MenuUiState> by lazy { SingleLiveEvent() }

// ...
menu?.sections?.forEach {
    //update menu properties here
}
menuData.value = menu?.copy()
l

Lokik Soni

02/18/2022, 11:20 AM
check your menuList size in log
m

Mike Speed

02/18/2022, 11:21 AM
the data is definitely there. the debugger doesn’t even get to the
items(){}
line to check the size
c

Colton Idle

02/18/2022, 5:05 PM
I've had a ton of issues with compose + debugger. It's anecdotal at this point but I have been recluded to using logs instead of debugger in my compose apps.
m

Mike Speed

02/18/2022, 5:06 PM
I also tried that.. nothing after
LazyColumn() {
is printed
a

Adrijan Rogan

02/19/2022, 1:31 PM
You can try using
items(menuList.value)
or
itemsIndexed(menuList.value)
if you really need indices.
The state has changed, but if the size does not change, I believe your
items
block will not be executed.