fix: 搜索结果页返回时丢失搜索状态
1. MainNavigator: 从 BookInfo 进入 ReadBook 时保留栈中历史, 返回路径恢复为 ReadBook → BookInfo → Search → Home 2. SearchViewModel: initialize() 检查 committedQuery 是否为空, 已有活跃搜索会话时跳过 clearSearchResults(),避免 LaunchedEffect 在 Navigation3 entry 重新进入 composition 时 清空搜索结果
This commit is contained in:
@@ -317,8 +317,13 @@ class SearchViewModel(
|
||||
}
|
||||
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()
|
||||
|
||||
val initKey = key?.trim().orEmpty()
|
||||
|
||||
@@ -48,7 +48,10 @@ object MainNavigator {
|
||||
is MainRouteCache,
|
||||
MainRouteBookCacheManage,
|
||||
is MainRouteReadBook -> {
|
||||
if (currentRoute == MainRouteHome) {
|
||||
if (
|
||||
currentRoute == MainRouteHome ||
|
||||
currentRoute is MainRouteBookInfo
|
||||
) {
|
||||
backStack.add(route)
|
||||
} else {
|
||||
backStack.clear()
|
||||
|
||||
Reference in New Issue
Block a user