kenkyee

    kenkyee

    11 months ago
    Can someone point me at an example of infinite scrolling a LazyColumn that doesn't use the paging library? (more of what I've tried in the thread)
    found this article: https://dev.to/luismierez/infinite-lazycolumn-in-jetpack-compose-44a4 but the launchedEffect didn't make sense so changed it to:
    LaunchedEffect(loadMore) {
        snapshotFlow { loadMore.value }
            .filter { it }
            .collect {
                onLoadMore()
            }
    }
    also put a breakpoint at (lastVisibleItemIndex > (totalItemsNumber - buffer)) in the infinitescrollhandler, but it only gets triggered once when you're scrolling around 🤔
    I expected it to trigger multiple times as you scroll around...
    Nicholas Doglio

    Nicholas Doglio

    11 months ago
    I asked the same question a few weeks ago and didn’t get much traction but the pattern I shared is what I’ve been playing around with in a side project. Still very new to compose so maybe there’s a more efficient or compose-y way to do it 🤷‍♀️ https://kotlinlang.slack.com/archives/CJLTWPH7S/p1631796738397000
    kenkyee

    kenkyee

    11 months ago
    Also found this article, but it only seems to load once as well...but at least the snapshotflow makes sense': https://manavtamboli.medium.com/infinite-list-paged-list-in-jetpack-compose-b10fc7e74768 :blob-shrug:
    thanks Nicholas...your way worked.
    fun DisplayTasks(
        tasks: List<ToDoTask>,
        navigateToTaskScreen: (taskId: Int) -> Unit,
        onLoadMore: () -> Unit
    ) {
        LazyColumn {
            itemsIndexed(tasks) { index, task ->
                if ((tasks.size - 5) == index) {
                    onLoadMore()
                }
                TaskItem(
                    toDoTask = task,
                    navigateToTaskScreen = navigateToTaskScreen
                )
            }
    5 is the load point from the bottom of the list. Still surprised using the lazyliststate doesn't work properly....this is the latest version of Compose 1.0.2
    next bit of fun...nav'ing back to the screen w/ the infinite scrolling loses the scroll position and starts back at the start 😞
    Nicholas Doglio

    Nicholas Doglio

    11 months ago
    Yeah I haven’t gotten there yet in my side project but that will be fun 🙃 If I figure out anything interesting with my side project I’ll be sure to let you know 👍