Tolriq
02/19/2022, 3:37 PMval playlistEntriesItems = remember(playlistEntries) {
Log.e("AAA", "Update entries")
playlistEntries.toMutableStateList()
}
Then use that state list in a LazyColumn. All works correctly and change to items order properly triggers recomposition. If that function is called again with a new playlistEntries the state is properly updated, but then the LazyColumn no more react on the changes. Am I missing something obvious?Tolriq
02/19/2022, 4:29 PMval playlistEntriesItems = remember { mutableListOf<PlaylistEntry>().toMutableStateList() }
val refresher = remember(playlistEntries) {
Log.e("AAA", "Update entries")
playlistEntriesItems.clear()
playlistEntriesItems.addAll(playlistEntries)
1
}
@Adam Powell sorry to ping but since you are here and talking about that, is this something expected? Should not the LazyColumn properly see that's it's another state and reset whatever it needs to understand the change ?Adam Powell
02/19/2022, 4:33 PMplaylistEntries
changes, since the remember
will create a new list from playlistEntries
as the source, dropping any changes that may have happened to the mutable state listAdam Powell
02/19/2022, 4:34 PMplaylistEntries
) and a local mutable copy, which is adding a lot of complexity you probably don't need or want.Tolriq
02/19/2022, 4:37 PMTolriq
02/19/2022, 4:38 PMTolriq
02/19/2022, 4:42 PMTolriq
02/19/2022, 4:42 PMAdam Powell
02/19/2022, 4:49 PMplaylistEntriesItems
that doesn't update if the actual list instance is recreatedAdam Powell
02/19/2022, 4:50 PMTolriq
02/19/2022, 4:55 PMTolriq
02/19/2022, 4:56 PMTolriq
02/19/2022, 5:43 PM@Composable
fun PlaylistEntryList(
lazyListState: LazyListState,
reorder: Boolean,
header: @Composable () -> Unit,
playlistEntries: List<PlaylistEntry>,
onMoreClick: ((PlaylistEntry, Int) -> Unit)? = null,
onItemDragged: ((from: Int, to: Int) -> Unit)? = null,
onClick: (PlaylistEntry, Int) -> Unit,
) {
val reorderState = rememberReorderState(listState = lazyListState)
val playlistEntriesItems = remember { mutableListOf<PlaylistEntry>().toMutableStateList() }
val refresher = remember(playlistEntries) {
playlistEntriesItems.clear()
playlistEntriesItems.addAll(playlistEntries)
}
@Suppress("UNUSED_EXPRESSION") refresher
LazyColumn(
state = reorderState.listState,
contentPadding = PaddingValues(bottom = 8.dp),
modifier = Modifier.reorderable(state = reorderState,
onMove = { from, to -> runCatching { playlistEntriesItems.move(from.index - 1, to.index - 1) } },
onDragEnd = { from, to -> onItemDragged?.invoke(from - 1, to - 1) })
) {
item {
header()
}
itemsIndexed(items = playlistEntriesItems, key = { _, item -> item.id }) { index, item ->
if (onMoreClick == null) {
PlaylistEntryListEntry(item, reorder = reorder, reorderState = reorderState, onMoreClick = null, onRowClick = { onClick(item, index) })
} else {
PlaylistEntryListEntry(item, reorder = reorder, reorderState = reorderState, onMoreClick = { onMoreClick(item, index) }, onRowClick = { onClick(item, index) })
}
}
}
}