Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#11 메뉴 정보 입력 페이지 기능을 구현한다. #28

Merged
merged 9 commits into from
Feb 17, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.erica.gamsung.menu.presentation.InputMenuScreen
import com.erica.gamsung.ui.theme.GamsungTheme

class MainActivity : ComponentActivity() {
Expand All @@ -35,11 +36,12 @@ class MainActivity : ComponentActivity() {

@Composable
fun MainNavHost(navController: NavHostController) {
NavHost(navController = navController, startDestination = "main") {
NavHost(navController = navController, startDestination = Screen.MAIN.route) {
composable(Screen.MAIN.route) { MainScreen(navController = navController) }
composable(Screen.SETTING.route) { SettingScreen() }
composable(Screen.PUBLISH_POSTING.route) { PublishPostingScreen() }
composable(Screen.CHECK_POSTING.route) { CheckPostingScreen() }
composable(Screen.INPUT_MENU.route) { InputMenuScreen(navController = navController) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ enum class Screen(
SETTING("setting"),
PUBLISH_POSTING("publishPosting"),
CHECK_POSTING("checkPosting"),
INPUT_MENU("inputMenu"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,27 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -44,11 +47,11 @@ fun GsTextBox(
modifier: Modifier,
innerTextModifier: Modifier,
) {
val text by remember { mutableStateOf(TextFieldValue(hintText)) }
var text by remember { mutableStateOf(TextFieldValue(hintText)) }
var expanded by remember { mutableStateOf(false) }
var selectedOption by remember { mutableStateOf("") }
Column {
TextTitle(title, isRequired, description)
TextTitle(title, isRequired, description, Modifier)
if (options != null) {
DropdownTextBox(
text,
Expand All @@ -66,9 +69,11 @@ fun GsTextBox(
)
} else {
InputTextBox(
text,
innerTextModifier,
modifier,
modifier = innerTextModifier,
hintText = text.text,
onValueChange = { text = TextFieldValue(it) },
keyboardType = KeyboardType.Text,
isError = false,
)
}
}
Expand All @@ -79,6 +84,7 @@ fun TextTitle(
title: String,
isRequired: Boolean,
description: String?,
modifier: Modifier = Modifier,
) {
Text(
text =
Expand Down Expand Up @@ -108,6 +114,8 @@ fun TextTitle(
description?.let { append(description) }
}
},
style = MaterialTheme.typography.titleSmall,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Text 컴포저블 사용할 때 서체를 사용할 수 있더라구
서체 사용하면 fontWeight, fontSize, lineHeight, letterSpacing 이 이미 정의되어있는거라 일일히 지정하는 귀찮음을 없앨 수 있어서 적극활용해보면 좋을듯

image

https://developer.android.com/jetpack/compose/designsystems/material3?hl=ko&_gl=1*844823*_up*MQ..*_ga*MTc3NTg1NDM1NS4xNzA4MDEzMDkw*_ga_34B604LFFQ*MTcwODAxMzA4OS4xLjAuMTcwODAxMzA4OS4wLjAuMA..#typography

modifier = modifier,
)
}

Expand Down Expand Up @@ -168,51 +176,41 @@ private fun DropdownTextBox(

@Composable
fun InputTextBox(
hintText: TextFieldValue,
modifier: Modifier,
innerTextModifier: Modifier,
modifier: Modifier = Modifier,
hintText: String,
onValueChange: (String) -> Unit,
keyboardType: KeyboardType = KeyboardType.Text,
isError: Boolean = false,
Comment on lines +182 to +183
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KeyboardType.Number 로 인자 넘기면 숫자 키보드 사용할 수 있어.

isError는 사용자가 잘못된 입력을 했을 때 true로 넘겨주면 테두리가 빨간색으로 변해

) {
var text by remember {
mutableStateOf(hintText)
}
var isFocused by remember {
mutableStateOf(false)
var textState by remember {
mutableStateOf("")
}
BasicTextField(
value = text,
onValueChange = { updatedText ->
text = updatedText
OutlinedTextField(
value = textState,
onValueChange = {
textState = it
onValueChange(it)
},
singleLine = true,
modifier =
modifier
.background(Color.Transparent)
.border(
1.dp,
Color.LightGray,
RoundedCornerShape(percent = 15),
).onFocusChanged { focusState ->
isFocused = focusState.isFocused
if (isFocused && text == hintText) {
text = TextFieldValue("")
} else if (!isFocused && text.text.isEmpty()) {
text = hintText
}
},
decorationBox = { innerTextField ->
Row(
modifier = innerTextModifier,
verticalAlignment = Alignment.CenterVertically,
) {
if (!isFocused && text == hintText) {
Text(hintText.text, color = Color.Gray)
Spacer(modifier = Modifier.weight(1f))
} else {
innerTextField()
Spacer(modifier = Modifier.weight(1f))
}
}
placeholder = {
Text(
text = hintText,
color = Color.Gray,
style = MaterialTheme.typography.bodyLarge,
)
},
singleLine = true,
colors =
TextFieldDefaults.colors(
unfocusedContainerColor = Color.Transparent,
unfocusedIndicatorColor = Color.LightGray,
focusedContainerColor = Color.Transparent,
errorContainerColor = Color.Transparent,
),
shape = RoundedCornerShape(percent = 15),
keyboardOptions = KeyboardOptions(keyboardType = keyboardType),
textStyle = MaterialTheme.typography.bodyLarge,
modifier = modifier,
isError = isError,
)
}

Expand Down
Loading
Loading