Skip to content

Commit

Permalink
[FEAT/#19] 완료 버튼으로 키보드 숨기기 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
arinming committed Jul 7, 2024
1 parent 3e55a7e commit 8cd0618
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -17,8 +19,11 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
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
import androidx.compose.ui.unit.dp
import com.terning.core.designsystem.theme.Grey300
import com.terning.core.designsystem.theme.TerningMain
Expand All @@ -44,9 +49,20 @@ fun TerningTextField(
helperIcon: Int? = null,
helperColor: Color = TerningMain,
) {
val keyboardController = LocalSoftwareKeyboardController.current
val focusManager = LocalFocusManager.current

BasicTextField(
value = value,
onValueChange = onValueChange,
singleLine = true,
maxLines = 1,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(
onDone = {
keyboardController?.hide()
focusManager.clearFocus()
}),

modifier = Modifier
.fillMaxWidth()
Expand Down
1 change: 1 addition & 0 deletions feature/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
android:exported="true"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize"
android:theme="@style/Theme.TerningAndroid">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.terning.feature.search

import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
Expand All @@ -9,6 +10,8 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.terning.core.designsystem.textfield.NameTextField
Expand All @@ -27,13 +30,13 @@ fun SearchRoute() {
fun SearchScreen() {
var text by remember { mutableStateOf("") }

// TODO 프로필 스크린 전용으로, 삭제될 코드입니다
// TODO 프로필 스크린 TextField로, 삭제될 코드입니다
var helperMessage by remember { mutableStateOf(R.string.profile_text_field_helper) }
var helperIcon by remember { mutableStateOf<Int?>(null) }
var helperColor by remember { mutableStateOf(Grey400) }
val specialCharacterPattern = Regex("[!@#\$%^&*(),.?\":{}|<>\\[\\]\\\\/]")

// TODO 프로필 스크린 전용으로, 삭제될 코드입니다
// TODO 프로필 스크린 TextField로, 삭제될 코드입니다
fun updateHelper(text: String) {
helperMessage = when {
text.isEmpty() -> R.string.profile_text_field_helper
Expand Down Expand Up @@ -70,7 +73,7 @@ fun SearchScreen() {
leftIcon = R.drawable.ic_nav_search
)

// TODO 프로필 스크린 전용으로, 삭제될 코드입니다
// TODO 프로필 스크린 TextField로, 삭제될 코드입니다
NameTextField(
text = text,
onValueChange = { newText ->
Expand Down

0 comments on commit 8cd0618

Please sign in to comment.