0

To draw data using the paging and jetpack composite libraries, I use the LazyColumn(). The data comes in every second and I need to stop the view on the elements when I go down. Now they go lower when adding fresh data at the top of the list. How i can do it with scrollState or any other method?

@Composable
fun HistoryTableList(
    viewModel: HistoryViewModel = viewModel()
) {
    val scrollState = rememberLazyListState()
    val coroutineScope = rememberCoroutineScope()

    LazyColumn(
        state = scrollState,
        modifier = Modifier
            .padding(
                HistoryListHorizontalPadding,
                0.dp,
                HistoryListHorizontalPadding,
                HistoryListPaddingBottom
            )
            .fillMaxWidth(),
    ) {
        items(historyItems) { historyRecord ->
            if (historyRecord != null) {
                // need to set scrollState to view elements without moving[![enter image description here][1]][1]
                HistoryTableItem(history = historyRecord)
            }
        }
    }
}

Now they move if I go down

enter image description here

Sunbey13
  • 339
  • 4
  • 12

1 Answers1

0

Try specifying some unique keys on your items: https://developer.android.com/jetpack/compose/lists#item-keys

That way, when you update your data, item with the same key will be stay on top of your list.

Jan Bína
  • 3,447
  • 14
  • 16