Fix unnecessary recompose when calling LazyListState.isScrolledToEnd (#7598)

(cherry picked from commit 2e15be59af23de2302d7ccebd7ccea31d4f98da3)
This commit is contained in:
Ivan Iskandar 2022-07-24 19:49:28 +07:00 committed by Jobobby04
parent dcf152b5c2
commit e6ab9e3815

View File

@ -8,7 +8,15 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
fun LazyListState.isScrolledToEnd() = layoutInfo.visibleItemsInfo.lastOrNull()?.index == layoutInfo.totalItemsCount - 1 @Composable
fun LazyListState.isScrolledToEnd(): Boolean {
return remember {
derivedStateOf {
val lastItem = layoutInfo.visibleItemsInfo.lastOrNull()
lastItem == null || lastItem.size + lastItem.offset <= layoutInfo.viewportEndOffset
}
}.value
}
@Composable @Composable
fun LazyListState.isScrollingUp(): Boolean { fun LazyListState.isScrollingUp(): Boolean {