fix(main): compose the main route only after preferences load
Show a blank frame until the first preferences snapshot arrives, so the saved bar position does not flash or jump on cold start.
This commit is contained in:
1 parent
a62e3a1e8f
commit
232c1955ec
3 files changed
+10
No files matched your search
@@ -47,6 +47,10 @@ fun MainRoute(
|
||||
|
||||
val settingsState by settingsViewModel.uiState.collectAsStateWithLifecycle()
|
||||
val searchQuery by searchViewModel.searchQuery.collectAsStateWithLifecycle()
|
||||
if (!settingsState.hasLoadedPreferences) {
|
||||
Box(modifier = Modifier.fillMaxSize())
|
||||
return
|
||||
}
|
||||
val isSearchBarAtBottom = settingsState.searchBarPosition == "BOTTOM"
|
||||
|
||||
val scrollPosition = remember(searchViewModel) {
|
||||
|
||||
@@ -25,6 +25,7 @@ data class SettingsUiState(
|
||||
val importState: ImportState = ImportState.Idle,
|
||||
val dictionarySources: List<DictionarySource> = emptyList(),
|
||||
val hasCompletedStartupScan: Boolean = false,
|
||||
val hasLoadedPreferences: Boolean = false,
|
||||
val pipelineIdle: Boolean = true,
|
||||
val appVersion: String = "1.0",
|
||||
)
|
||||
|
||||
@@ -54,6 +54,7 @@ private data class OperationStateInputs(
|
||||
val isLanguageExpanded: Boolean,
|
||||
val isSearchBarExpanded: Boolean,
|
||||
val isDictionariesExpanded: Boolean,
|
||||
val hasLoadedPreferences: Boolean,
|
||||
)
|
||||
|
||||
class SettingsViewModel(
|
||||
@@ -163,6 +164,7 @@ class SettingsViewModel(
|
||||
preferencesManager.isLanguageExpanded,
|
||||
preferencesManager.isSearchBarExpanded,
|
||||
preferencesManager.isDictionariesExpanded,
|
||||
hasLoadedPreferences,
|
||||
) { params: Array<Any> ->
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
OperationStateInputs(
|
||||
@@ -176,6 +178,7 @@ class SettingsViewModel(
|
||||
isLanguageExpanded = params[7] as Boolean,
|
||||
isSearchBarExpanded = params[8] as Boolean,
|
||||
isDictionariesExpanded = params[9] as Boolean,
|
||||
hasLoadedPreferences = params[10] as Boolean,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -254,6 +257,7 @@ class SettingsViewModel(
|
||||
importState = operationState.importState,
|
||||
dictionaryStatus = operationState.dictionaryStatus,
|
||||
hasCompletedStartupScan = operationState.hasCompletedStartupScan,
|
||||
hasLoadedPreferences = operationState.hasLoadedPreferences,
|
||||
pipelineIdle = !isIndexing &&
|
||||
!operationState.downloadState.isActive &&
|
||||
!operationState.importState.isActive,
|
||||
@@ -293,6 +297,7 @@ class SettingsViewModel(
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.w("SettingsViewModel", "Failed to load search bar position: ${e.message}")
|
||||
}
|
||||
hasLoadedPreferences.value = true
|
||||
hasCompletedStartupScan.value = true
|
||||
preferencesManager.setHadNoDictionaries(
|
||||
localDictionaryRepository.dictionaries.value.isEmpty()
|
||||
|
||||
Reference in new issue
Block a user