Purpose and difference of Key and Pivotal ?
# compose
a
Purpose and difference of Key and Pivotal ?
m
Pivotal is the mechanism which is used to implement the key function.
a
I am making infinite scrolling view. After making to the end of verticalScroller. I am calling api to load more data and store it in a local db. I am observing the local db and as change happen i recieved a new list of data(with old data also). Now the problem is that scroller is recomposing the whole view. I only want the data to load with new ids. Is using
Key
or
Pivotal
helps ?
I don't want to recompose the whole ui.
m
Is every parameter of your item composable stable?
a
I am getting list of livedata which is observed inside a below function
Copy code
fun <T> observer(data: LiveData<T>) = effectOf<T?> {
    var result = +state<T?> { data.value }
    val observer = +memo { Observer<T> { result.value = it } }

    +onCommit(data) {
        data.observeForever(observer)
        onDispose { data.removeObserver(observer) }
    }
    result.value
}
m
Can you show me code were you compose the VerticalScroller?
a
Copy code
var internationalState = +observer(newArticleModel.internationalHeadline)
Surface(color = (+MaterialTheme.colors()).surface, modifier = Expanded) {
    if (internationalState == null) {
        ShowLoading()
    } else if (internationalState.isEmpty()) {
        NoContentMore()
    } else {
        val scrollerPosition: ScrollerPosition = +memo { ScrollerPosition(0f) }
        println("MainActivity data here : " + internationalState)

        Observe {
            +onCommit(scrollerPosition.isAtEndOfList) {
                println("Is commit entered")
                if(scrollerPosition.isAtEndOfList)
                    newArticleModel.loadMoreData()
            }
        }
        VerticalScroller(scrollerPosition = scrollerPosition) {
            Column(Expanded) {

                println("Page rendering size " + PageSize.topHeadlineInternationalPageNo)
                internationalState!!.forEach {
                    Ripple(bounded = true) {
                        Clickable() {
                            ArticleTicket(
                                backgroundColor = (+MaterialTheme.colors()).background,
                                article = it
                            )
                        }
                    }
                }
            }
        }
    }
}
m
1. Extract the logic inside the forEach to a function that accepts your article class as a parameter 2. Annotate the article with @Pivotal 3. Annotate the article class with @Immutable, @Stable or @Model depending on what is applicable. I guess it's @Immutable in this case
a
Getting this error
Copy code
java.lang.IllegalStateException: Expected a group start
        at androidx.compose.SlotTableKt.getAsGroupStart(SlotTable.kt:641)
        at androidx.compose.SlotTableKt.access$getAsGroupStart$p(SlotTable.kt:1)
m
You have to use the latest version of compose
a
Okay, let me try after updating the compose
After changing from dev03 to dev04, I am getting this error
java.lang.ClassCastException: androidx.compose.GroupStart cannot be cast to androidx.ui.foundation.ScrollerPosition