Просмотр исходного кода

fix: prevent bookshelf content flicker

HapeLee 3 месяцев назад
Родитель
Сommit
d2db36ce51

+ 3 - 2
app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfScreen.kt

@@ -75,6 +75,7 @@ import androidx.compose.material3.SnackbarHostState
 import androidx.compose.material3.SnackbarResult
 import androidx.compose.runtime.Composable
 import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.SideEffect
 import androidx.compose.runtime.derivedStateOf
 import androidx.compose.runtime.getValue
 import androidx.compose.runtime.key
@@ -249,12 +250,12 @@ fun BookshelfScreen(
     val latestGroups by rememberUpdatedState(uiState.groups)
     val latestSelectedGroupId by rememberUpdatedState(uiState.selectedGroupId)
 
-    LaunchedEffect(uiState.selectedGroupIndex, uiState.groups.size) {
+    SideEffect {
         if (uiState.groups.isNotEmpty()
             && uiState.selectedGroupIndex in uiState.groups.indices
             && pagerState.currentPage != uiState.selectedGroupIndex
         ) {
-            pagerState.scrollToPage(uiState.selectedGroupIndex)
+            pagerState.requestScrollToPage(uiState.selectedGroupIndex)
         }
     }
 

+ 6 - 2
app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt

@@ -411,14 +411,18 @@ class BookshelfViewModel(
     val uiState: StateFlow<BookshelfUiState> = combine(
         dataStateFlow,
         interactionStateFlow,
-        visibleBooksFlow,
         isInitialLoadingFlow
-    ) { data, interaction, filteredBooks, isInitialLoading ->
+    ) { data, interaction, isInitialLoading ->
         val books = data.books
         val groups = data.groups
         val allGroups = data.allGroups
         val previews = data.previews
         val internal = data.internal
+        val filteredBooks = filterBooks(
+            books = books,
+            searchKey = internal.searchKey,
+            isSearchMode = internal.isSearchMode
+        )
         val selectedGroupIndex = groups.indexOfFirst { it.groupId == internal.groupId }
             .coerceAtLeast(0)
         val currentGroupName = allGroups.firstOrNull { it.groupId == internal.groupId }?.groupName