Billy Newman
06/03/2021, 7:08 PMval items by state.items
val scope = rememberCoroutineScope()
var itemCount by remember { mutableStateOf(state.items.value.size) }
LazyColumn(
state = listState,
modifier = Modifier.fillMaxHeight()
) {
item {
HeaderContent()
}
itemsIndexed(items) { index, item ->
ItemContent(item)
}
if (itemCount < items.size) {
scope.launch {
// items.size, not items.size - 1 to account for header
listState.animateScrollToItem(items.size)
}
itemCount = items.size
}
}
This works most of the time. However, every so often the scroll will end at the bottom or middle of the newly added item, not the top of the new item.Kirill Grouchnikov
06/03/2021, 7:14 PMDominaezzz
06/03/2021, 7:16 PMscope.launch
with LauncedEffect
.Dominaezzz
06/03/2021, 7:20 PMLaunchedEffect(items.size)
. I think it's related now.Billy Newman
06/03/2021, 7:21 PM@Composable invocations can only happen from the context of a @Composable function
Dominaezzz
06/03/2021, 7:21 PMLAzyColumn
.Billy Newman
06/03/2021, 7:31 PMBilly Newman
06/03/2021, 7:43 PMMBegemot
06/04/2021, 4:37 AMBilly Newman
06/04/2021, 2:08 PMBilly Newman
06/06/2021, 2:27 PM