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 settingsState by settingsViewModel.uiState.collectAsStateWithLifecycle()
|
||||||
val searchQuery by searchViewModel.searchQuery.collectAsStateWithLifecycle()
|
val searchQuery by searchViewModel.searchQuery.collectAsStateWithLifecycle()
|
||||||
|
if (!settingsState.hasLoadedPreferences) {
|
||||||
|
Box(modifier = Modifier.fillMaxSize())
|
||||||
|
return
|
||||||
|
}
|
||||||
val isSearchBarAtBottom = settingsState.searchBarPosition == "BOTTOM"
|
val isSearchBarAtBottom = settingsState.searchBarPosition == "BOTTOM"
|
||||||
|
|
||||||
val scrollPosition = remember(searchViewModel) {
|
val scrollPosition = remember(searchViewModel) {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ data class SettingsUiState(
|
|||||||
val importState: ImportState = ImportState.Idle,
|
val importState: ImportState = ImportState.Idle,
|
||||||
val dictionarySources: List<DictionarySource> = emptyList(),
|
val dictionarySources: List<DictionarySource> = emptyList(),
|
||||||
val hasCompletedStartupScan: Boolean = false,
|
val hasCompletedStartupScan: Boolean = false,
|
||||||
|
val hasLoadedPreferences: Boolean = false,
|
||||||
val pipelineIdle: Boolean = true,
|
val pipelineIdle: Boolean = true,
|
||||||
val appVersion: String = "1.0",
|
val appVersion: String = "1.0",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ private data class OperationStateInputs(
|
|||||||
val isLanguageExpanded: Boolean,
|
val isLanguageExpanded: Boolean,
|
||||||
val isSearchBarExpanded: Boolean,
|
val isSearchBarExpanded: Boolean,
|
||||||
val isDictionariesExpanded: Boolean,
|
val isDictionariesExpanded: Boolean,
|
||||||
|
val hasLoadedPreferences: Boolean,
|
||||||
)
|
)
|
||||||
|
|
||||||
class SettingsViewModel(
|
class SettingsViewModel(
|
||||||
@@ -163,6 +164,7 @@ class SettingsViewModel(
|
|||||||
preferencesManager.isLanguageExpanded,
|
preferencesManager.isLanguageExpanded,
|
||||||
preferencesManager.isSearchBarExpanded,
|
preferencesManager.isSearchBarExpanded,
|
||||||
preferencesManager.isDictionariesExpanded,
|
preferencesManager.isDictionariesExpanded,
|
||||||
|
hasLoadedPreferences,
|
||||||
) { params: Array<Any> ->
|
) { params: Array<Any> ->
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
OperationStateInputs(
|
OperationStateInputs(
|
||||||
@@ -176,6 +178,7 @@ class SettingsViewModel(
|
|||||||
isLanguageExpanded = params[7] as Boolean,
|
isLanguageExpanded = params[7] as Boolean,
|
||||||
isSearchBarExpanded = params[8] as Boolean,
|
isSearchBarExpanded = params[8] as Boolean,
|
||||||
isDictionariesExpanded = params[9] as Boolean,
|
isDictionariesExpanded = params[9] as Boolean,
|
||||||
|
hasLoadedPreferences = params[10] as Boolean,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,6 +257,7 @@ class SettingsViewModel(
|
|||||||
importState = operationState.importState,
|
importState = operationState.importState,
|
||||||
dictionaryStatus = operationState.dictionaryStatus,
|
dictionaryStatus = operationState.dictionaryStatus,
|
||||||
hasCompletedStartupScan = operationState.hasCompletedStartupScan,
|
hasCompletedStartupScan = operationState.hasCompletedStartupScan,
|
||||||
|
hasLoadedPreferences = operationState.hasLoadedPreferences,
|
||||||
pipelineIdle = !isIndexing &&
|
pipelineIdle = !isIndexing &&
|
||||||
!operationState.downloadState.isActive &&
|
!operationState.downloadState.isActive &&
|
||||||
!operationState.importState.isActive,
|
!operationState.importState.isActive,
|
||||||
@@ -293,6 +297,7 @@ class SettingsViewModel(
|
|||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
android.util.Log.w("SettingsViewModel", "Failed to load search bar position: ${e.message}")
|
android.util.Log.w("SettingsViewModel", "Failed to load search bar position: ${e.message}")
|
||||||
}
|
}
|
||||||
|
hasLoadedPreferences.value = true
|
||||||
hasCompletedStartupScan.value = true
|
hasCompletedStartupScan.value = true
|
||||||
preferencesManager.setHadNoDictionaries(
|
preferencesManager.setHadNoDictionaries(
|
||||||
localDictionaryRepository.dictionaries.value.isEmpty()
|
localDictionaryRepository.dictionaries.value.isEmpty()
|
||||||
|
|||||||
Reference in new issue
Block a user