Skip to content

Commit

Permalink
[FEAT] 검색 키보드 액션 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
arinming committed Jul 18, 2024
1 parent ab4ab08 commit d372b01
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package com.terning.core.designsystem.component.textfield
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.text.input.ImeAction
import com.terning.core.designsystem.theme.Grey300
import com.terning.core.designsystem.theme.Grey400
import com.terning.core.designsystem.theme.TerningMain
Expand All @@ -17,8 +20,11 @@ fun SearchTextField(
leftIcon: Int,
enabled: Boolean = true,
readOnly: Boolean = false,
onDoneAction: (() -> Unit)? = null,
onSearchAction: () -> Unit? = {},
) {
val keyboardController = LocalSoftwareKeyboardController.current
val focusManager = LocalFocusManager.current

TerningBasicTextField(
value = text,
onValueChange = onValueChange,
Expand All @@ -32,9 +38,17 @@ fun SearchTextField(
hintColor = Grey300,
leftIcon = leftIcon,
leftIconColor = TerningMain,
imeAction = ImeAction.Search,
enabled = enabled,
readOnly = readOnly,
onDoneAction = onDoneAction,
onSearchAction = {
if (text.isNotBlank()) {
keyboardController?.hide()
keyboardController?.hide()
focusManager.clearFocus()
onSearchAction()
}
},
helperColor = TerningMain
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.ImeAction
Expand Down Expand Up @@ -55,28 +53,24 @@ fun TerningBasicTextField(
enabled: Boolean = true,
helperColor: Color,
readOnly: Boolean = false,
onDoneAction: (() -> Unit)? = null,
onDoneAction: () -> Unit? = {},
onSearchAction: () -> Unit? = {},
) {
val keyboardController = LocalSoftwareKeyboardController.current
val focusManager = LocalFocusManager.current
val isFocused: MutableState<Boolean> = remember { mutableStateOf(false) }

BasicTextField(
value = value,
onValueChange = onValueChange,
onValueChange = {
if (maxTextLength == null || it.length <= maxTextLength) {
onValueChange(it)
}
},
singleLine = true,
maxLines = 1,
keyboardOptions = KeyboardOptions(imeAction = imeAction),
keyboardActions = KeyboardActions(
onDone = {
if (value.isNotBlank()) {
keyboardController?.hide()
focusManager.clearFocus()
if (onDoneAction != null) {
onDoneAction()
}
}
}
onDone = { onDoneAction() },
onSearch = { onSearchAction() },
),

modifier = modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fun SearchProcessScreen(
.padding(top = 8.dp)
.focusRequester(focusRequester)
.addFocusCleaner(focusManager),
onDoneAction = {
onSearchAction = {
viewModel.getSearchList(
keyword = state.text,
sortBy = SORT_BY,
Expand Down

0 comments on commit d372b01

Please sign in to comment.