From a0ffc45ab7f74d8a0551ba31b412e5ad308f3218 Mon Sep 17 00:00:00 2001 From: MinseoShindor Date: Fri, 12 Jan 2024 03:02:09 +0900 Subject: [PATCH] =?UTF-8?q?[feat/#24]=20snackbar=20=EC=9E=91=EC=97=85=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/moim/MoimFragment.kt | 5 -- .../presentation/moim/MoimIntroduce.kt | 37 ++++++++-- app/src/main/res/layout/fragment_moim.xml | 9 --- app/src/main/res/values/strings.xml | 1 + .../base/component/compose/TmSnackBar.kt | 68 +++++++------------ .../base/component/compose/theme/Color.kt | 2 +- 6 files changed, 61 insertions(+), 61 deletions(-) diff --git a/app/src/main/java/com/teumteum/teumteum/presentation/moim/MoimFragment.kt b/app/src/main/java/com/teumteum/teumteum/presentation/moim/MoimFragment.kt index 2cbb95e4..976ee76d 100644 --- a/app/src/main/java/com/teumteum/teumteum/presentation/moim/MoimFragment.kt +++ b/app/src/main/java/com/teumteum/teumteum/presentation/moim/MoimFragment.kt @@ -51,11 +51,6 @@ class MoimFragment : else -> {} } } -// (activity as? AppCompatActivity)?.setSupportActionBar(binding.toolbar) - -// binding.toolbar.setNavigationOnClickListener { -// goFrontScreen() -// } requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback) } diff --git a/app/src/main/java/com/teumteum/teumteum/presentation/moim/MoimIntroduce.kt b/app/src/main/java/com/teumteum/teumteum/presentation/moim/MoimIntroduce.kt index ba029938..8d27ccf7 100644 --- a/app/src/main/java/com/teumteum/teumteum/presentation/moim/MoimIntroduce.kt +++ b/app/src/main/java/com/teumteum/teumteum/presentation/moim/MoimIntroduce.kt @@ -9,6 +9,7 @@ import androidx.compose.foundation.Image 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.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer @@ -43,6 +44,7 @@ import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import coil.compose.rememberImagePainter import coil.size.Scale @@ -53,6 +55,7 @@ import com.teumteum.base.component.compose.TmMarginVerticalSpacer import com.teumteum.base.component.compose.TmSnackBar import com.teumteum.base.component.compose.theme.TmTypo import com.teumteum.base.component.compose.theme.TmtmColorPalette +import kotlinx.coroutines.delay @Composable fun MoimIntroduce( @@ -61,16 +64,17 @@ fun MoimIntroduce( val introduce by viewModel.introduction.collectAsState() val photo by viewModel.imageUri.collectAsState() val snackbarHostState = remember { SnackbarHostState() } - val snackbarEvent by viewModel.snackbarEvent.collectAsState(initial = MoimViewModel.SnackbarEvent.DEFAULT) LaunchedEffect(Unit) { viewModel.snackbarEvent.collect { event -> when (event) { MoimViewModel.SnackbarEvent.FILE_OVER_10MB -> { val result = snackbarHostState.showSnackbar( - message = "파일 크기가 10MB를 초과합니다.", + message = "10mb 이하의 사진을 등록해주세요", duration = SnackbarDuration.Short ) + delay(1000) + snackbarHostState.currentSnackbarData?.dismiss() if (result == SnackbarResult.Dismissed) { viewModel.resetSnackbarEvent() } @@ -80,8 +84,9 @@ fun MoimIntroduce( } } + TmSnackBar(snackbarHostState = snackbarHostState) + Scaffold( - snackbarHost = { SnackbarHost(hostState = snackbarHostState) } ) { innerPadding-> Column( modifier = Modifier @@ -93,19 +98,43 @@ fun MoimIntroduce( ) { CreateMoimTitle(string= stringResource(id = R.string.moim_introduce_title)) TmMarginVerticalSpacer(size = 28) - MoimIntroColumn(viewModel) TmMarginVerticalSpacer(size = 20) TeumDivider() TmMarginVerticalSpacer(size = 20) MoimPhotoColumn(viewModel) + TmMarginVerticalSpacer(size = 20) + TmSnackBar(snackbarHostState = snackbarHostState) Spacer(modifier = Modifier.weight(1f)) TeumDivider() MoimCreateBtn(text = stringResource(id = R.string.moim_next_btn), viewModel = viewModel, isEnabled = introduce.isNotEmpty() && photo.isNotEmpty()) + TmMarginVerticalSpacer(size = 24) } } +} +@Preview +@Composable +fun TmSnackBar( +) { + Box( + modifier = Modifier + .fillMaxWidth() + .height(60.dp) + .background( + color = TmtmColorPalette.current.color_text_button_primary_default02, + shape = RoundedCornerShape(12.dp) + ) + .padding(horizontal = 12.dp), + contentAlignment = Alignment.Center + ) { + Text( + text = "스낵바", + color = TmtmColorPalette.current.color_text_body_quinary, + style= TmTypo.current.Body1 + ) + } } @Composable diff --git a/app/src/main/res/layout/fragment_moim.xml b/app/src/main/res/layout/fragment_moim.xml index f87733b8..027be4a4 100644 --- a/app/src/main/res/layout/fragment_moim.xml +++ b/app/src/main/res/layout/fragment_moim.xml @@ -31,15 +31,6 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintWidth_percent="1.0"/> - - - - - - - - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0ad5c21d..6421e575 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -35,6 +35,7 @@ 사진 등록 최대 5장 1장 이상의 사진을 필수로 등록해주세요. + 파일 크기가 10MB를 초과합니다. 모임 일정을 정해주세요 날짜 diff --git a/core/base/src/main/java/com/teumteum/base/component/compose/TmSnackBar.kt b/core/base/src/main/java/com/teumteum/base/component/compose/TmSnackBar.kt index e53224ee..e676d836 100644 --- a/core/base/src/main/java/com/teumteum/base/component/compose/TmSnackBar.kt +++ b/core/base/src/main/java/com/teumteum/base/component/compose/TmSnackBar.kt @@ -4,6 +4,7 @@ import android.util.Log import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding @@ -19,56 +20,39 @@ import androidx.compose.ui.unit.dp import androidx.compose.runtime.rememberCoroutineScope import com.teumteum.base.component.compose.theme.TmtmColorPalette import androidx.compose.material.* +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue import androidx.compose.ui.tooling.preview.Preview import com.teumteum.base.component.compose.theme.TmTypo +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.delay import kotlinx.coroutines.launch @Composable fun TmSnackBar( - text: String, - snackbarHostState: SnackbarHostState, + snackbarHostState: SnackbarHostState ) { - val coroutineScope = rememberCoroutineScope() - Box( - modifier = Modifier - .fillMaxWidth() - .height(60.dp) - .clickable { - coroutineScope.launch { - snackbarHostState - .showSnackbar( - "snackBar show!!", "확인", SnackbarDuration.Short // 스낵바 보여주는 시간 - ) - .let { - when (it) { - SnackbarResult.Dismissed -> - Log.d("snackBar", "snackBar: 스낵바 닫아짐") - - SnackbarResult.ActionPerformed -> - Log.d("snackBar", "snackBar: 확인 버튼 눌러짐") - - } - } - } - } - .background( - color = TmtmColorPalette.current.color_text_button_primary_default02, - shape = RoundedCornerShape(12.dp) + SnackbarHost(hostState = snackbarHostState) { data -> + Box( + modifier = Modifier + .fillMaxWidth() + .height(60.dp) + .padding(horizontal = 20.dp) + .background( + color = TmtmColorPalette.current.color_text_button_primary_default02, + shape = RoundedCornerShape(12.dp) + ) + .padding(horizontal = 12.dp), + contentAlignment = Alignment.Center + ) { + Text( + text = data.message, + color = TmtmColorPalette.current.color_text_body_quinary, + style= TmTypo.current.Body1 ) - .padding(horizontal = 12.dp), - contentAlignment = Alignment.Center - ) { - Text( - text = text, - color = TmtmColorPalette.current.color_text_body_quinary, - style= TmTypo.current.Body1 - ) - - SnackbarHost( - hostState = snackbarHostState, - modifier = Modifier.align(Alignment.BottomCenter) - ) + } } - } diff --git a/core/base/src/main/java/com/teumteum/base/component/compose/theme/Color.kt b/core/base/src/main/java/com/teumteum/base/component/compose/theme/Color.kt index 14dc1857..759297de 100644 --- a/core/base/src/main/java/com/teumteum/base/component/compose/theme/Color.kt +++ b/core/base/src/main/java/com/teumteum/base/component/compose/theme/Color.kt @@ -32,7 +32,7 @@ data class ColorPalette_Light( //button val color_text_button_primary_default: Color = Color(0xFFFFFFFF), - val color_text_button_primary_default02: Color = Color(0x4444444), + val color_text_button_primary_default02: Color = Color(0xFF444444), val color_text_button_primary_press: Color = Color(0xFF96D1FF), //tmtm blue 200 val color_text_button_primary_disabled: Color = Color(0xFFC9C9C9), val color_text_button_secondary_default: Color = Color(0xFF44AEFF),