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

[Setting] ConfirmButton 만들기 #15

Merged
merged 2 commits into from
Jan 25, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package ac.dnd.bookkeeping.android.presentation.common.view

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
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

@Composable
fun ConfirmButton(
text: String,
isMain: Boolean,
modifier: Modifier = Modifier,
isLoading: Boolean = false,
isEnabled: Boolean = true,
onClick: () -> Unit = {}
) {
Button(
modifier = modifier,
shape = RoundedCornerShape(10.dp),
contentPadding = PaddingValues(top = 10.dp, start = 10.dp, end = 10.dp, bottom = 10.dp),
colors = ButtonDefaults.textButtonColors(
backgroundColor = if (isMain) Color.Cyan else Color.LightGray
),
elevation = ButtonDefaults.elevation(0.dp, 0.dp, 0.dp, 0.dp, 0.dp),
onClick = onClick,
enabled = isEnabled && !isLoading
) {
if (isLoading) {
CircularProgressIndicator()
} else {
Text(
text = text,
fontSize = 16.sp,
color = Color.Black,
textAlign = TextAlign.Center,
fontWeight = FontWeight.Medium
)
}
}
}

@Preview
@Composable
fun ConfirmButtonPreview1() {
ConfirmButton(
text = "확인",
isMain = true,
modifier = Modifier
.padding(20.dp)
.fillMaxWidth()
)
}

@Preview
@Composable
fun ConfirmButtonPreview2() {
ConfirmButton(
text = "취소",
isMain = false,
modifier = Modifier
.padding(20.dp)
.fillMaxWidth()
)
}

@Preview
@Composable
fun ConfirmButtonPreview3() {
ConfirmButton(
text = "다음",
isMain = true,
modifier = Modifier
.padding(20.dp)
.fillMaxWidth(),
isEnabled = false
)
}

@Preview
@Composable
fun ConfirmButtonPreview4() {
ConfirmButton(
text = "로딩",
isMain = true,
modifier = Modifier
.padding(20.dp)
.fillMaxWidth(),
isLoading = true
)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ac.dnd.bookkeeping.android.presentation.common.view

import ac.dnd.bookkeeping.android.presentation.R
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
Expand All @@ -10,10 +9,8 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Card
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -54,10 +51,8 @@ fun DialogScreen(
}
) {
Card(
modifier = Modifier.background(
color = Color.White,
shape = RoundedCornerShape(10.dp)
),
backgroundColor = Color.White,
shape = RoundedCornerShape(10.dp)
) {
Column(
modifier = Modifier
Expand All @@ -67,7 +62,7 @@ fun DialogScreen(
) {
Text(
text = title,
fontSize = 16.sp,
fontSize = 24.sp,
color = Color.Black
)

Expand All @@ -76,50 +71,38 @@ fun DialogScreen(

Text(
text = message,
fontSize = 12.sp,
color = Color.Black
fontSize = 16.sp,
color = Color.Black,
textAlign = TextAlign.Center
)
}

Spacer(modifier = Modifier.height(20.dp))

Row(modifier = Modifier.wrapContentSize()) {
if (onCancel != null) {
TextButton(
modifier = Modifier
.weight(1f),
shape = RoundedCornerShape(4.dp),
colors = ButtonDefaults.textButtonColors(
backgroundColor = Color.Gray
),
ConfirmButton(
text = cancelMessage,
isMain = false,
modifier = Modifier.weight(1f),
onClick = {
onCancel()
onDismissRequest()
},
) {
Text(text = cancelMessage)
}
}
)

Spacer(modifier = Modifier.width(10.dp))
}

TextButton(
modifier = Modifier
.weight(1f),
shape = RoundedCornerShape(4.dp),
colors = ButtonDefaults.textButtonColors(
backgroundColor = Color.Gray
),
ConfirmButton(
text = confirmMessage,
isMain = true,
modifier = Modifier.weight(1f),
onClick = {
onConfirm()
onDismissRequest()
}
) {
Text(
text = confirmMessage,
textAlign = TextAlign.Center
)
}
)
}
}
}
Expand All @@ -135,7 +118,7 @@ fun DialogScreenPreview1() {
DialogScreen(
isShowing = isShowing,
title = "제목",
message = "내용",
message = "내용\n여러줄 넘어가면 이렇게 됨.\n가가가가가가가가가가가가가가가가가가가가가가가",
ajou4095 marked this conversation as resolved.
Show resolved Hide resolved
onCancel = {},
onDismissRequest = {
isShowing = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ fun SettingScreen(
DialogScreen(
isShowing = isDialogShowing,
title = stringResource(R.string.setting_dialog_title),
message = stringResource(R.string.setting_dialog_message),
onCancel = {},
onDismissRequest = { isDialogShowing = false }
)
}
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
<string name="error_dialog_title">앗, 에러가 발생했어요!</string>

<string name="setting_dialog_title">테스트</string>
<string name="setting_dialog_message">테스트내용\n앗, 에러가 발생했어요!\n이렇게 됩니다.</string>

</resources>
Loading