Thread
#compose
    TheDukerChip

    TheDukerChip

    1 year ago
    I have been using LazyColumn to load list of items with paging-compose library Here is the code
    @Composable
    fun ListOfItems(pagedItems: Flow<PagingData<Item>>) {
        val items: LazyPagingItems<Item> = pagedItems.collectAsLazyPagingItems()
    
        LazyColumn {
            items(items) { item ->
                ItemCard(item)
            }
        }
    }
    Problem is scrolled state is not retained when the screen is rotated Tried with the following
    val listState: LazyListState = rememberSaveable(saver = LazyListState.Saver) { LazyListState() }
    val scrollState: ScrollState = rememberSaveable(saver = ScrollState.Saver) { ScrollState(0) }
    
    LazyColumn(
        modifier = Modifier
            .scrollable(scrollState, Orientation.Vertical),
        state = listState,
    ) {}
    Still got no luck
    Dominaezzz

    Dominaezzz

    1 year ago
    If
    items
    becomes empty the scroll will be reset.
    TheDukerChip

    TheDukerChip

    1 year ago
    Great @Dominaezzz That list items is getting empty when activity is recreated. So I refactored it to rendering the ListItem composable only when the list is not empty Here is the working code
    Surface(color = MaterialTheme.colors.background) {
        val items = pagedItems.collectAsLazyPagingItems()
        if (items.itemCount > 0) {
            ListOfItems(items)
        }
    }