From 1b20ac4be627ced85ab700dd6bd87d31ed98f979 Mon Sep 17 00:00:00 2001 From: HapeLee <1321903405@qq.com> Date: Fri, 5 Dec 2025 00:15:12 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D]=20=E5=8F=91=E7=8E=B0?= =?UTF-8?q?=E9=A1=B5=E7=BD=91=E6=A0=BC=E6=98=BE=E7=A4=BA=E4=B8=8B=E6=8B=89?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E7=BB=A7=E7=BB=AD=E8=8E=B7=E5=8F=96=E5=88=97?= =?UTF-8?q?=E8=A1=A8=20#430?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/explore/ExploreShowScreen.kt | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowScreen.kt b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowScreen.kt index 0d4243490..029f2091d 100644 --- a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowScreen.kt +++ b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowScreen.kt @@ -24,6 +24,7 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.items +import androidx.compose.foundation.lazy.grid.rememberLazyGridState import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.rememberScrollState @@ -100,10 +101,32 @@ fun ExploreShowScreen( val filterState by viewModel.filterState.collectAsState() val selectedTitle by viewModel.selectedKindTitle.collectAsState() val listState = rememberLazyListState() + val gridState = rememberLazyGridState() val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior() var showKindSheet by remember { mutableStateOf(false) } val layoutState by viewModel.layoutState.collectAsState() val isGridMode = layoutState == 1 + val shouldLoadMore = remember { + derivedStateOf { + val totalItems: Int + val lastVisibleIndex: Int + if (isGridMode) { + totalItems = gridState.layoutInfo.totalItemsCount + lastVisibleIndex = gridState.layoutInfo.visibleItemsInfo.lastOrNull()?.index ?: 0 + } else { + totalItems = listState.layoutInfo.totalItemsCount + lastVisibleIndex = listState.layoutInfo.visibleItemsInfo.lastOrNull()?.index ?: 0 + } + totalItems > 0 && lastVisibleIndex >= totalItems - 3 + } + } + + LaunchedEffect(shouldLoadMore.value) { + if (shouldLoadMore.value) { + viewModel.loadMore() + } + } + if (showKindSheet) { val scrollState = rememberScrollState() // 记住滚动状态 @@ -173,6 +196,7 @@ fun ExploreShowScreen( ) { isGrid -> if (isGrid) { LazyVerticalGrid( + state = gridState, modifier = Modifier.fillMaxSize(), columns = GridCells.Adaptive(minSize = 90.dp), contentPadding = PaddingValues( @@ -234,20 +258,6 @@ fun ExploreShowScreen( } } } - - val shouldLoadMore = remember { - derivedStateOf { - val totalItems = listState.layoutInfo.totalItemsCount - val lastVisibleIndex = listState.layoutInfo.visibleItemsInfo.lastOrNull()?.index ?: 0 - totalItems > 0 && lastVisibleIndex >= totalItems - 5 - } - } - - LaunchedEffect(shouldLoadMore.value) { - if (shouldLoadMore.value) { - viewModel.loadMore() - } - } } } }