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

[올리브] 회원가입 미션 1, 2단계 제출합니다. #2

Open
wants to merge 13 commits into
base: kimhm0728
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# android-signup# android-signup
# android-signup
## 1단계 - 컴포즈 기초
### 기능 요구사항
- [x] text() 테스트를 성공하도록 수정한다.
- [x] column() 테스트를 성공하도록 수정한다.
- [x] button() 테스트를 성공하도록 수정한다.

## 2단계 - 회원가입(뷰)
### 기능 요구사항
- [x] 디자인 시안을 참고하여 회원가입 뷰를 구현한다.

### 프로그래밍 요구사항
- [x] ViewModel, Hilt 등은 활용하지 않는다.
- [x] 컴포저블 함수가 너무 많은 일을 하지 않도록 분리한다.
- [x] Material3 Button, TextField를 활용한다.
Comment on lines +1 to +15
Copy link
Member

Choose a reason for hiding this comment

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

굿굿

5 changes: 2 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ plugins {
}

android {
namespace = "nextstep.signup"
namespace = "woowacourse.signup"
compileSdk = 34

defaultConfig {
applicationId = "nextstep.signup"
applicationId = "woowacourse.signup"
minSdk = 26
targetSdk = 34
versionCode = 1
Expand Down Expand Up @@ -50,7 +50,6 @@ android {
}

dependencies {

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
Expand Down
97 changes: 97 additions & 0 deletions app/src/androidTest/java/woowacourse/signup/LayoutBasicsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package woowacourse.signup

import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertCountEquals
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onChildren
import androidx.compose.ui.test.onFirst
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import org.junit.Rule
import org.junit.Test

class LayoutBasicsTest {
@get:Rule
val composeTestRule = createComposeRule()

Comment on lines +28 to +31
Copy link
Member

Choose a reason for hiding this comment

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

Android ViewCompose로 UI 테스트를 진행해봤을 때 어떤 차이점이 있었나요?

단순 질문입니다,,하핳

@Test
fun text() {
// given
val text = "안녕 난 컴포즈야~"
composeTestRule.setContent {
Text(
text = text,
color = Color.Blue,
style = TextStyle(
fontSize = 26.sp,
fontWeight = FontWeight.Bold,
fontFamily = FontFamily.SansSerif
),
)
}

// then
composeTestRule
.onNodeWithText(text)
.assertExists()
}

@Test
fun column() {
// given
composeTestRule.setContent {
Column(
modifier = Modifier.testTag("이름")
) {
Text(text = "깜포즈", color = Color.Red)
Text(text = "킴포즈", color = Color.Cyan)
Text(text = "끔포즈", color = Color.Yellow)
}
}

// then
composeTestRule.onNodeWithTag("이름")
.onChildren()
.assertCountEquals(3)
.onFirst()
.assert(hasText("깜포즈"))
}

@Test
fun button() {
// given
composeTestRule.setContent {
val enabled = remember { mutableStateOf(true) }
Button(
onClick = { enabled.value = !enabled.value },
enabled = enabled.value,
modifier = Modifier.testTag("버튼")
) {
Text(text = "클릭해주세요")
}
}

// when
val button = composeTestRule
.onNodeWithTag("버튼")
.performClick()

// then
button.assertIsNotEnabled()
}
}
46 changes: 0 additions & 46 deletions app/src/main/java/nextstep/signup/MainActivity.kt

This file was deleted.

141 changes: 141 additions & 0 deletions app/src/main/java/woowacourse/signup/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package woowacourse.signup

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
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.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import woowacourse.signup.ui.theme.Blue50
import woowacourse.signup.ui.util.FillMaxTheme
import woowacourse.signup.ui.util.Space

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
FillMaxTheme {
SignUpLayout()
}
}
}
}

@Composable
private fun SignUpLayout() {
Column {
SignUpTitle()
Space(dp = 18)
SignUpInput(titleId = R.string.username_input)
SignUpInput(titleId = R.string.email_input)
SignUpInput(titleId = R.string.password_input, isPassword = true)
SignUpInput(titleId = R.string.password_confirm_input, isPassword = true)
Comment on lines +52 to +55
Copy link
Member

Choose a reason for hiding this comment

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

만약에 Column이 아닌 다른 Composable를 사용하지 않고 SignUpInput()이라는 Composable이 여러개 필요한 UI라면 어떤식으로 구현할 것 같으신가요?!

SignUpInput(titleId = R.string.username_input)
SignUpInput(titleId = R.string.username_input)
SignUpInput(titleId = R.string.username_input)
SignUpInput(titleId = R.string.username_input)
SignUpInput(titleId = R.string.username_input)
SignUpInput(titleId = R.string.username_input)
SignUpInput(titleId = R.string.username_input)

Space(dp = 24)
SignUpButton()
}
}

@Composable
private fun SignUpTitle() {
Text(
text = stringResource(id = R.string.sign_up_title),
fontSize = 26.sp,
color = Color.Black,
fontWeight = FontWeight.W700,
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
.padding(top = 60.dp)
)
}

@Composable
private fun SignUpInput(
@StringRes titleId: Int,
isPassword: Boolean = false,
) {
var input by remember { mutableStateOf("") }

TextField(
label = { SignUpInputLabel(titleId) },
value = input,
onValueChange = { input = it },
textStyle = TextStyle(
fontSize = 16.sp,
fontWeight = FontWeight.W400,
),
singleLine = true,
colors = TextFieldDefaults.colors(
focusedIndicatorColor = Blue50,
focusedLabelColor = Blue50,
cursorColor = Blue50,
),
visualTransformation = if (isPassword) PasswordVisualTransformation() else VisualTransformation.None,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 32.dp, vertical = 18.dp),
)
}

@Composable
private fun SignUpInputLabel(@StringRes labelId: Int) {
Text(
text = stringResource(id = labelId),
fontWeight = FontWeight.W400,
)
}

@Composable
private fun SignUpButton() {
Button(
onClick = {
// TODO
},
contentPadding = PaddingValues(0.dp),
colors = ButtonDefaults.buttonColors(
containerColor = Blue50,
),
modifier =
Modifier
.fillMaxWidth()
.padding(horizontal = 32.dp),
) {
Text(
text = stringResource(id = R.string.sign_up_button),
fontSize = 14.sp,
fontWeight = FontWeight.W500,
modifier = Modifier.padding(vertical = 15.dp)
)
}
}
Comment on lines +111 to +133
Copy link
Member

Choose a reason for hiding this comment

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

여러 곳에서 다양한 크기의 SignUpButton을 사용하고자 할 때, 해당 Composable을 어떻게 개선할 수 있을까요?!


@Preview(showBackground = true)
@Composable
private fun MainActivityPreview() {
FillMaxTheme {
SignUpLayout()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nextstep.signup.ui.theme
package woowacourse.signup.ui.theme

import androidx.compose.ui.graphics.Color

Expand All @@ -8,4 +8,6 @@ val Pink80 = Color(0xFFEFB8C8)

val Purple40 = Color(0xFF6650a4)
val PurpleGrey40 = Color(0xFF625b71)
val Pink40 = Color(0xFF7D5260)
val Pink40 = Color(0xFF7D5260)

val Blue50 = Color(0xFF2196F3)
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package nextstep.signup.ui.theme
package woowacourse.signup.ui.theme

import android.app.Activity
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
Expand All @@ -9,11 +8,8 @@ import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.core.view.WindowCompat

private val DarkColorScheme = darkColorScheme(
primary = Purple80,
Expand All @@ -24,10 +20,10 @@ private val DarkColorScheme = darkColorScheme(
private val LightColorScheme = lightColorScheme(
primary = Purple40,
secondary = PurpleGrey40,
tertiary = Pink40
tertiary = Pink40,
background = Color.White

/* Other default colors to override
background = Color(0xFFFFFBFE),
surface = Color(0xFFFFFBFE),
onPrimary = Color.White,
onSecondary = Color.White,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nextstep.signup.ui.theme
package woowacourse.signup.ui.theme

import androidx.compose.material3.Typography
import androidx.compose.ui.text.TextStyle
Expand Down Expand Up @@ -31,4 +31,4 @@ val Typography = Typography(
letterSpacing = 0.5.sp
)
*/
)
)
Loading