1

I am new in Compose, and I am struggling with the state issue.

Let's consider such scenario:

  1. The list of items is displayed.
  2. On the bottom of the screen there is a button which state should change if user reaches the bottom of the list.
  3. When button's state is changed, its text content and sharp is changed.
  4. When the state is changed and user scrolls up -> state should not be changed anymore.

It works when I scroll to the bottom -> the state is changed. But state is also changed when I scroll up from the bottom of the list.

val scrollState = rememberLazyListState()
val lastVisibleItemIndex by remember(scrollState) {
    derivedStateOf {
        scrollState.layoutInfo.visibleItemsInfo.lastOrNull()?.index ?: 0 
    }
}

val isEndReached by remember { lastVisibleItemIndex == items.size -1 }

1 Answers1

1

This should do the trick

var isEndReached by remember { mutableStateOf(false) }
if (lastVisibleItemIndex == items.size - 1) {
     isEndReached = true
}
Benoit TH
  • 601
  • 3
  • 12