fix: 搜索结果页返回时丢失搜索状态
1. MainNavigator: 从 BookInfo 进入 ReadBook 时保留栈中历史, 返回路径恢复为 ReadBook → BookInfo → Search → Home 2. SearchViewModel: initialize() 检查 committedQuery 是否为空, 已有活跃搜索会话时跳过 clearSearchResults(),避免 LaunchedEffect 在 Navigation3 entry 重新进入 composition 时 清空搜索结果
This commit is contained in:
2 files changed
+11
-3
No files matched your search
@@ -317,8 +317,13 @@ class SearchViewModel(
|
|||||||
}
|
}
|
||||||
syncScopeState()
|
syncScopeState()
|
||||||
|
|
||||||
// Always reset search state so the screen starts clean,
|
// When the ViewModel already holds a non-empty committed query,
|
||||||
// regardless of whether the ViewModel was retained by navigation.
|
// 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()
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in new issue
Block a user