Skip to content

Commit

Permalink
fix : QR 확인 시 스낵 바 상단으로 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
HamBP committed Jan 9, 2025
1 parent 61eb6ec commit aab014f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package com.nexters.boolti.presentation.screen.qr
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.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
Expand All @@ -28,6 +30,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.hilt.navigation.compose.hiltViewModel
Expand Down Expand Up @@ -67,6 +70,7 @@ fun QrScanScreen(
val notMatchedErrMessage = stringResource(R.string.error_ticket_not_matched)

val uiState by viewModel.uiState.collectAsStateWithLifecycle()
var bottomPadding by remember { mutableStateOf(0.dp) }

LaunchedEffect(barcodeView) {
barcodeView.resume()
Expand All @@ -78,9 +82,20 @@ fun QrScanScreen(
val (iconId, errMessage) = when (event) {
is QrScanEvent.ScanError -> {
when (event.errorType) {
QrErrorType.ShowNotToday -> Pair(R.drawable.ic_warning, notTodayErrMessage)
QrErrorType.UsedTicket -> Pair(R.drawable.ic_error, usedTicketErrMessage)
QrErrorType.TicketNotFound -> Pair(R.drawable.ic_error, notMatchedErrMessage)
QrErrorType.ShowNotToday -> Pair(
R.drawable.ic_warning,
notTodayErrMessage
)

QrErrorType.UsedTicket -> Pair(
R.drawable.ic_error,
usedTicketErrMessage
)

QrErrorType.TicketNotFound -> Pair(
R.drawable.ic_error,
notMatchedErrMessage
)
}
}

Expand Down Expand Up @@ -114,24 +129,37 @@ fun QrScanScreen(
QrScanBottombar { showEntryCodeDialog = true }
},
snackbarHost = {
ToastSnackbarHost(
hostState = snackbarHostState,
modifier = Modifier.padding(bottom = 100.dp),
leadingIcon = {
snackbarIconId?.let {
CircleBgIcon(
painter = painterResource(it),
bgColor = when (it) {
R.drawable.ic_check -> Success
R.drawable.ic_error -> Error
else -> Warning
}
)
}
},
)
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.TopCenter,
) {
ToastSnackbarHost(
modifier = Modifier
.offset { // Scaffold의 inner padding 만큼 상단을 뚫고 나가는 문제가 있음. 해당 값 보정.
IntOffset(0, bottomPadding.toPx().toInt())
}
.padding(top = 18.dp + 44.dp), // 44.dp 는 top bar 높이 값 수동 계산
hostState = snackbarHostState,
leadingIcon = {
snackbarIconId?.let {
CircleBgIcon(
painter = painterResource(it),
bgColor = when (it) {
R.drawable.ic_check -> Success
R.drawable.ic_error -> Error
else -> Warning
}
)
}
},
)
}
},
) { innerPadding ->
LaunchedEffect(innerPadding) {
bottomPadding = innerPadding.calculateBottomPadding()
}

AndroidView(
modifier = Modifier
.padding(innerPadding)
Expand Down Expand Up @@ -194,7 +222,10 @@ private fun EntryCodeDialog(
onDismiss: () -> Unit,
) {
BTDialog(showCloseButton = false, onDismiss = onDismiss, onClickPositiveButton = onDismiss) {
Text(text = stringResource(R.string.manager_code), style = MaterialTheme.typography.titleLarge)
Text(
text = stringResource(R.string.manager_code),
style = MaterialTheme.typography.titleLarge
)
Text(
modifier = Modifier
.padding(top = 24.dp)
Expand Down
4 changes: 2 additions & 2 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<string name="description_clear_button">모두 지우기</string>

<string name="error_show_not_today">아직 공연일이 아니에요</string>
<string name="error_used_ticket">이미 사용된 티켓이에요</string>
<string name="error_used_ticket">이미 입장에 사용한 티켓이에요</string>
<string name="error_ticket_not_matched">이 공연의 티켓이 아니에요</string>
<string name="error_ticket_not_found">존재하지 않는 티켓이에요</string>

Expand Down Expand Up @@ -325,7 +325,7 @@
<string name="hostedShowsTitle">입장 확인</string>
<string name="hosted_shows_empty_label">입장을 확인할 공연이 없어요</string>
<string name="hosted_shows_empty_desc">공연을 주최하고 QR 코드로\n관객 입장을 확인해 보세요</string>
<string name="message_ticket_validated">사용되었어요</string>
<string name="message_ticket_validated">입장을 확인했어요</string>

<!-- 결제 내역 -->
<string name="reservations_empty">결제 내역이 없어요</string>
Expand Down

0 comments on commit aab014f

Please sign in to comment.