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/#7] time&seats screen 공통 컴포넌트 & seats 스크린 모달 구현 #8

Closed
wants to merge 12 commits into from
Copy link
Contributor

Choose a reason for hiding this comment

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

와 컴포넌트화 이렇게까지 할 수 있네요?
저는 다 다른 버튼이라 다 만들 것 같았는데

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오히려 비효율적이구 헷갈리려나... 싶어서 다시 나눌까 고민중이어요 ㅎㅎㅜㅠ..

Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package org.sopt.cgv.core.designsystem.component.button

import android.R
import android.widget.Button
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ComposeCompilerApi
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.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import org.sopt.cgv.core.designsystem.theme.Gray200
import org.sopt.cgv.core.designsystem.theme.PrimaryRed400
import org.sopt.cgv.core.designsystem.theme.White

data class ButtonStyle(
val backgroundColor: Color,
val border: BorderStroke?,
val textColor: Color,
)

@Composable
fun getButtonStyle(buttonType: String): ButtonStyle {
return remember(buttonType) {
when (buttonType) {
"Choice" -> ButtonStyle(
backgroundColor = PrimaryRed400,
border = null,
textColor = White
)
"Back" -> ButtonStyle(
backgroundColor = White,
border = BorderStroke(1.dp, PrimaryRed400),
textColor = PrimaryRed400
)
else -> ButtonStyle(
backgroundColor = PrimaryRed400,
border = null,
textColor = White
)
}
}

}

@Composable
fun ModalButton(
buttonType: String, //선택 버튼인 경우 Choice, 뒤로가기인 경우 Back
initialActivation: Boolean, // 처음부터 활성화 상태면 true, 활성화 조건 필요하면 false
content: String,
length: String, //long, half로 사용
){

var isActivated by remember { mutableStateOf(initialActivation) }
val buttonStyle = getButtonStyle(buttonType)

val (buttonWidth, buttonHeight) = remember(length) {
when (length) {
"long" -> Pair(324.dp, 54.dp)
"half" -> Pair(156.dp, 54.dp)
else -> Pair(324.dp, 54.dp)
}
}
Comment on lines +74 to +80
Copy link
Member

Choose a reason for hiding this comment

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

버튼 크기를 고정 dp로 주는 것이 아닌, 텍스트를 기준으로 horizontalPadding, verticalPadding을 주신후 나중에 스크린에서 전체 화면에서의 패딩을 조절하면 기기 대응에도 더 좋을 거 같습니당


Box(
modifier = Modifier
.size(width = buttonWidth, height = buttonHeight)
.clip(RoundedCornerShape(12.dp))
.background(buttonStyle.backgroundColor)
.then(
if (buttonStyle.border != null)
Modifier.border(buttonStyle.border, RoundedCornerShape(8.dp))
else
Modifier
)
) {
Row(
modifier = Modifier.fillMaxSize(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceEvenly
){
Text(
text = content,
color = buttonStyle.textColor
)

}
}
}



@Preview
@Composable
fun ButtonPreview(){
Column(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
ModalButton(
buttonType = "Choice",
initialActivation = true,
content = "좌석선택",
length = "long"
)
ModalButton(
buttonType = "Back",
initialActivation = false,
content = "뒤로가기",
length = "half"
)
ModalButton(
buttonType = "Choice",
initialActivation = true,
content = "확인",
length = "half"
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package org.sopt.cgv.core.designsystem.component.button

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import org.sopt.cgv.R
import org.sopt.cgv.core.designsystem.theme.Gray100
import org.sopt.cgv.core.designsystem.theme.Gray700
import org.sopt.cgv.core.designsystem.theme.Gray800

@Composable
fun Stepper(
modifier: Modifier = Modifier,
initialValue: Int = 0,
onValueChange: (Int) -> Unit
) {
var currentValue by remember { mutableStateOf(initialValue) }

Row(
modifier = modifier
.size(height = 36.dp, width = 100.dp)
.clip(RoundedCornerShape(8.dp))
.background(Gray100),
) {
Row(
modifier = modifier
.fillMaxSize()
.padding(horizontal = 8.dp, vertical = 4.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceAround,
){
// - 버튼
Box(
modifier = Modifier
.clickable {
if (currentValue > 0) {
currentValue--
onValueChange(currentValue)
}
}
.size(20.dp),
contentAlignment = Alignment.Center
) {
Icon(
painter = painterResource(id = R.drawable.ic_seats_minus),
contentDescription = "인원 감소",
tint = Gray800,
modifier = Modifier.size(20.dp)
)
}

// 현재 값
Box(
modifier = Modifier
.padding(horizontal = 5.dp)
.size(width = 34.dp, height = 28.dp)
.background(Color.White, RoundedCornerShape(8.dp)),
contentAlignment = Alignment.Center
) {
Text(
text = currentValue.toString(),
fontSize = 17.sp,
color = Gray700
)
}

// + 버튼
Box(
modifier = Modifier
.clickable {
currentValue++
onValueChange(currentValue)
}
.size(20.dp),
contentAlignment = Alignment.Center
) {
Icon(
painter = painterResource(id = R.drawable.ic_seats_plus),
contentDescription = "인원 증가",
tint = Gray800,
modifier = Modifier.size(20.dp) // 아이콘 크기
)
}
}

}
}

@Preview
@Composable
fun StepperPreview() {
Stepper(
initialValue = 0,
onValueChange = { newValue ->
println("Stepper value changed: $newValue")
}
)
}
Loading