Explorar el Código

fix: 搜索结果页返回时丢失搜索状态

1. MainNavigator: 从 BookInfo 进入 ReadBook 时保留栈中历史,
   返回路径恢复为 ReadBook → BookInfo → Search → Home

2. SearchViewModel: initialize() 检查 committedQuery 是否为空,
   已有活跃搜索会话时跳过 clearSearchResults(),避免
   LaunchedEffect 在 Navigation3 entry 重新进入 composition 时
   清空搜索结果
HapeLee hace 5 meses
padre
commit
f80a46d073

+ 7 - 2
app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt

@@ -317,8 +317,13 @@ class SearchViewModel(
         }
         }
         syncScopeState()
         syncScopeState()
 
 
-        // Always reset search state so the screen starts clean,
-        // regardless of whether the ViewModel was retained by navigation.
+        // When the ViewModel already holds a non-empty committed query,
+        // it means a search session is in progress or completed.
+        // This happens when returning from BookInfo — the LaunchedEffect
+        // re-fires but we must not wipe the existing results.
+        val hasActiveSearch = _uiState.value.committedQuery.isNotEmpty()
+        if (hasActiveSearch) return
+
         clearSearchResults()
         clearSearchResults()
 
 
         val initKey = key?.trim().orEmpty()
         val initKey = key?.trim().orEmpty()

+ 4 - 1
app/src/main/java/io/legado/app/ui/main/MainNavigator.kt

@@ -48,7 +48,10 @@ object MainNavigator {
             is MainRouteCache,
             is MainRouteCache,
             MainRouteBookCacheManage,
             MainRouteBookCacheManage,
             is MainRouteReadBook -> {
             is MainRouteReadBook -> {
-                if (currentRoute == MainRouteHome) {
+                if (
+                    currentRoute == MainRouteHome ||
+                    currentRoute is MainRouteBookInfo
+                ) {
                     backStack.add(route)
                     backStack.add(route)
                 } else {
                 } else {
                     backStack.clear()
                     backStack.clear()