From 2e15be59af23de2302d7ccebd7ccea31d4f98da3 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sun, 24 Jul 2022 19:49:28 +0700 Subject: [PATCH] Fix unnecessary recompose when calling LazyListState.isScrolledToEnd (#7598) --- .../java/eu/kanade/presentation/util/LazyListState.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/presentation/util/LazyListState.kt b/app/src/main/java/eu/kanade/presentation/util/LazyListState.kt index 5783232d8..84409babd 100644 --- a/app/src/main/java/eu/kanade/presentation/util/LazyListState.kt +++ b/app/src/main/java/eu/kanade/presentation/util/LazyListState.kt @@ -8,7 +8,15 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember 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 fun LazyListState.isScrollingUp(): Boolean {