From 4b627b4d05b47316b0919adcfb3469d1ac3ab825 Mon Sep 17 00:00:00 2001 From: OneWay Date: Tue, 6 Oct 2026 09:42:54 +0800 Subject: [PATCH] fix(search): rebuild the results pager only when the dictionary set changes Background metadata loading rewrote the dictionaries flow several times after startup, and every emission recreated the Pager: the results list visibly collapsed and refilled. Distinct on the index paths that paging actually uses, and seed the state synchronously instead of an empty list. --- .../com/example/research/feature/search/SearchViewModel.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/research/feature/search/SearchViewModel.kt b/app/src/main/java/com/example/research/feature/search/SearchViewModel.kt index 7d1947d..9b45c63 100644 --- a/app/src/main/java/com/example/research/feature/search/SearchViewModel.kt +++ b/app/src/main/java/com/example/research/feature/search/SearchViewModel.kt @@ -69,10 +69,12 @@ class SearchViewModel( private val activeDictionaries: StateFlow> = repository.dictionaries.map { dictList -> dictList.filter { it.isActive } + }.distinctUntilChanged { previous, current -> + previous.map { it.indexPath } == current.map { it.indexPath } }.stateIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(5000), - initialValue = emptyList() + initialValue = repository.dictionaries.value.filter { it.isActive } ) init {