From 70997df6411131b59eff8e4ed4d5ef6d1dc51246 Mon Sep 17 00:00:00 2001 From: yangsooplus Date: Mon, 5 Feb 2024 17:48:39 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=B3=B4=EB=82=B8=20=EB=B4=89=ED=88=AC?= =?UTF-8?q?=20=EA=B2=80=EC=83=89=20=EA=B2=B0=EA=B3=BC=20=ED=81=B4=EB=A6=AD?= =?UTF-8?q?=EC=8B=9C=20=ED=8F=AC=EC=BB=A4=EC=8A=A4=20=EC=A7=80=EC=9B=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SentEnvelopeSearchScreen.kt | 22 ++++++++++++++----- .../SentEnvelopeSearchViewModel.kt | 2 ++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/feature/sent/src/main/java/com/susu/feature/envelopesearch/SentEnvelopeSearchScreen.kt b/feature/sent/src/main/java/com/susu/feature/envelopesearch/SentEnvelopeSearchScreen.kt index f1905cfa..20680e6a 100644 --- a/feature/sent/src/main/java/com/susu/feature/envelopesearch/SentEnvelopeSearchScreen.kt +++ b/feature/sent/src/main/java/com/susu/feature/envelopesearch/SentEnvelopeSearchScreen.kt @@ -10,9 +10,13 @@ import androidx.compose.foundation.layout.padding import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.remember import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview @@ -42,10 +46,12 @@ fun SentEnvelopeSearchRoute( popBackStack: () -> Unit, ) { val uiState = viewModel.uiState.collectAsStateWithLifecycle().value + val focusRequester = remember { FocusRequester() } + val focusManager = LocalFocusManager.current viewModel.sideEffect.collectWithLifecycle { sideEffect -> when (sideEffect) { - EnvelopeSearchEffect.FocusClear -> {} + EnvelopeSearchEffect.FocusClear -> focusManager.clearFocus() is EnvelopeSearchEffect.NavigateEnvelopDetail -> navigateSentEnvelopeDetail(sideEffect.envelopeId) EnvelopeSearchEffect.PopBackStack -> popBackStack() } @@ -63,26 +69,32 @@ fun SentEnvelopeSearchRoute( SentEnvelopeSearchScreen( uiState = uiState, + focusRequester = focusRequester, onSearchKeywordUpdated = viewModel::updateSearchKeyword, onClickClearIcon = { viewModel.updateSearchKeyword("") }, onSelectRecentSearch = { + viewModel.clearFocus() viewModel.upsertEnvelopeRecentSearch(it) viewModel.updateSearchKeyword(it) }, onDeleteRecentSearch = viewModel::deleteEnvelopeRecentSearch, popBackStack = popBackStack, - onClickEnvelope = { viewModel.navigateToEnvelopeDetail(it.id) }, + onClickEnvelope = { id, search -> + viewModel.upsertEnvelopeRecentSearch(search) + viewModel.navigateToEnvelopeDetail(id) + }, ) } @Composable fun SentEnvelopeSearchScreen( uiState: EnvelopeSearchState = EnvelopeSearchState(), + focusRequester: FocusRequester = remember { FocusRequester() }, onSearchKeywordUpdated: (String) -> Unit = {}, onClickClearIcon: () -> Unit = {}, onSelectRecentSearch: (String) -> Unit = {}, onDeleteRecentSearch: (String) -> Unit = {}, - onClickEnvelope: (Envelope) -> Unit = {}, + onClickEnvelope: (Long, String) -> Unit = { _, _ -> }, popBackStack: () -> Unit = {}, ) { Column( @@ -98,7 +110,7 @@ fun SentEnvelopeSearchScreen( modifier = Modifier.padding( horizontal = SusuTheme.spacing.spacing_m, vertical = SusuTheme.spacing.spacing_xxs, - ), + ).focusRequester(focusRequester), value = uiState.searchKeyword, placeholder = stringResource(R.string.sent_envelope_search_search_title), onValueChange = onSearchKeywordUpdated, @@ -142,7 +154,7 @@ fun SentEnvelopeSearchScreen( .fillMaxWidth() .padding(horizontal = SusuTheme.spacing.spacing_m), searchResult = uiState.envelopeList, - onClickItem = onClickEnvelope, + onClickItem = { onClickEnvelope(it.id, uiState.searchKeyword) }, ) } } diff --git a/feature/sent/src/main/java/com/susu/feature/envelopesearch/SentEnvelopeSearchViewModel.kt b/feature/sent/src/main/java/com/susu/feature/envelopesearch/SentEnvelopeSearchViewModel.kt index 11b73855..9919df48 100644 --- a/feature/sent/src/main/java/com/susu/feature/envelopesearch/SentEnvelopeSearchViewModel.kt +++ b/feature/sent/src/main/java/com/susu/feature/envelopesearch/SentEnvelopeSearchViewModel.kt @@ -88,4 +88,6 @@ class EnvelopeSearchViewModel @Inject constructor( copy(recentSearchKeywordList = searchList.toPersistentList()) } } + + fun clearFocus() = postSideEffect(EnvelopeSearchEffect.FocusClear) }