diff --git a/app/src/main/java/org/dianqk/ruslin/ui/page/search/SearchPage.kt b/app/src/main/java/org/dianqk/ruslin/ui/page/search/SearchPage.kt index ce627aa..e07e858 100644 --- a/app/src/main/java/org/dianqk/ruslin/ui/page/search/SearchPage.kt +++ b/app/src/main/java/org/dianqk/ruslin/ui/page/search/SearchPage.kt @@ -47,6 +47,7 @@ fun SearchPage( val focusRequest = remember { FocusRequester() } val lazyListState = rememberLazyListState() val keyboardController = LocalSoftwareKeyboardController.current + Scaffold( modifier = Modifier, topBar = { @@ -74,6 +75,7 @@ fun SearchPage( keyboardActions = KeyboardActions( onSearch = { viewModel.search() + focusRequest.freeFocus() } ) ) @@ -114,8 +116,11 @@ fun SearchPage( keyboardController?.hide() } - LaunchedEffect(Unit) { - focusRequest.requestFocus() + if (uiState.showKeyboardOnFirstLoad) { + LaunchedEffect(Unit) { + focusRequest.requestFocus() + viewModel.hasShownKeyboardOnFirstLoad() + } } } diff --git a/app/src/main/java/org/dianqk/ruslin/ui/page/search/SearchViewModel.kt b/app/src/main/java/org/dianqk/ruslin/ui/page/search/SearchViewModel.kt index 972d4db..75e5f4b 100644 --- a/app/src/main/java/org/dianqk/ruslin/ui/page/search/SearchViewModel.kt +++ b/app/src/main/java/org/dianqk/ruslin/ui/page/search/SearchViewModel.kt @@ -18,7 +18,8 @@ data class SearchUiState( val searchingTerm: String = "", val isSearching: Boolean = false, val searchedNotes: List = emptyList(), - val notFound: Boolean = false + val notFound: Boolean = false, + val showKeyboardOnFirstLoad: Boolean = true, ) @HiltViewModel @@ -40,6 +41,12 @@ class SearchViewModel @Inject constructor( } } + fun hasShownKeyboardOnFirstLoad() { + _uiState.update { + it.copy(showKeyboardOnFirstLoad = false) + } + } + fun search() { if (_uiState.value.isSearching) { return