amar_1995

    amar_1995

    2 years ago
    I am trying to use VerticalScroller but it is not working properly. Whole ui lags
    @Composable
    private fun ShowArticle(
        articleList: List<NewsArticle>
    ) {
        val scrollerPosition: ScrollerPosition = +memo {ScrollerPosition(0f)}
        if(scrollerPosition.isAtEndOfList) {
            newArticleModel.loadMoreNationData(2)
        }
        VerticalScroller(scrollerPosition = scrollerPosition) {
            Column(Expanded) {
                articleList.forEach {
                    ArticleTicket(
                        backgroundColor = (+MaterialTheme.colors()).background,
                        article = it
                    )
                }
            }
        }
    }
    val ScrollerPosition.isAtEndOfList: Boolean get() = value >= maxPosition
    I am loading data as verticalscroller reaches its end..
    Manuel Wrage

    Manuel Wrage

    2 years ago
    Try to wrap the "isAtTheEndOfList" if statement inside a Observe { ... }
    Because you reading the scrollPosition.value the whole list is recomposed any time you scroll. By wrapping the code in a Observe it will only recompose the code inside it.
    amar_1995

    amar_1995

    2 years ago
    val observe  = Observer<Boolean> {
        if (it) {
            newArticleModel.loadMoreNationData(2)
        }
    }
    observe.onChanged(scrollerPosition.isAtEndOfList)
    Like this ?
    Manuel Wrage

    Manuel Wrage

    2 years ago
    No i mean androidx.compose.Observe
    androidx.compose.Observe {
        if(scrollerPosition.isAtEndOfList) {
            newArticleModel.loadMoreNationData(2)
        }
    }
    Like this
    amar_1995

    amar_1995

    2 years ago
    Yeah thanks
    Now, It is working fine
    Manuel Wrage

    Manuel Wrage

    2 years ago
    Great😃
    Chuck Jazdzewski [G]

    Chuck Jazdzewski [G]

    2 years ago
    As the above discussion shows
    Observe
    is a confusing name. Any recommendations for renaming it?
    v

    Val Salamakha

    2 years ago
    It’s better to name the component Observe as BodyScope as it “creates a scope which will be the root of recomposition for any reads or writes to Model classes that happen inside of it.
    Manuel Wrage

    Manuel Wrage

    2 years ago
    I think Observe is ok. The problem is that we have to get used to the fact that each composable lambda without a return type is a scope which can be invoked when ever something has changed.
    Klaas Kabini

    Klaas Kabini

    2 years ago
    I had a similar problem and this thread helped me in solving it.