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

[ISSUE-213] 스낵바가 UI를 가리는 현상 해결 #214

Merged
merged 3 commits into from
Aug 3, 2022
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
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.yapp.growth.presentation.R
import com.yapp.growth.presentation.theme.Gray900
Expand All @@ -22,13 +23,14 @@ import com.yapp.growth.presentation.theme.SubCoral
@Composable
fun PlanzSnackBar(
message: String,
bottomPadding: Int,
) {
Snackbar(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.padding(horizontal = 20.dp)
.padding(bottom = 32.dp),
.padding(bottom = bottomPadding.dp),
backgroundColor = Gray900
) {
Text(
Expand All @@ -43,13 +45,14 @@ fun PlanzSnackBar(
@Composable
fun PlanzErrorSnackBar(
message: String,
bottomPadding: Int,
) {
Snackbar(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.padding(horizontal = 20.dp)
.padding(bottom = 32.dp),
.padding(bottom = bottomPadding.dp),
backgroundColor = Gray900
) {
Row(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ fun DateScreen(
},
snackbarHost = { snackbarHostState ->
SnackbarHost(hostState = snackbarHostState) { snackbarData ->
PlanzErrorSnackBar(message = snackbarData.message)
PlanzErrorSnackBar(
message = snackbarData.message,
bottomPadding = 100
)
}
}
) { padding ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,32 @@ import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
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
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.layout.width
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Card
import androidx.compose.material.Icon
import androidx.compose.material.Scaffold
import androidx.compose.material.SnackbarHost
import androidx.compose.material.Text
import androidx.compose.material.rememberScaffoldState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand Down Expand Up @@ -38,7 +60,14 @@ import com.yapp.growth.presentation.R
import com.yapp.growth.presentation.component.PlanzErrorSnackBar
import com.yapp.growth.presentation.component.PlanzSnackBar
import com.yapp.growth.presentation.firebase.PLAN_ID_KEY_NAME
import com.yapp.growth.presentation.theme.*
import com.yapp.growth.presentation.theme.BackgroundColor1
import com.yapp.growth.presentation.theme.CoolGray500
import com.yapp.growth.presentation.theme.Gray200
import com.yapp.growth.presentation.theme.Gray800
import com.yapp.growth.presentation.theme.Gray900
import com.yapp.growth.presentation.theme.MainPurple900
import com.yapp.growth.presentation.theme.PlanzTypography
import com.yapp.growth.presentation.theme.SubYellow
import kotlinx.coroutines.launch
import timber.log.Timber

Expand All @@ -59,8 +88,15 @@ fun ShareScreen(
snackbarHost = { snackbarHostState ->
SnackbarHost(hostState = snackbarHostState) { snackbarData ->
when (viewState.snackBarType) {
ShareContract.ShareViewState.SnackBarType.SUCCESS -> PlanzSnackBar(message = snackbarData.message)
else -> PlanzErrorSnackBar(message = snackbarData.message)
ShareContract.ShareViewState.SnackBarType.SUCCESS ->
PlanzSnackBar(
message = snackbarData.message,
bottomPadding = 156
)
else -> PlanzErrorSnackBar(
message = snackbarData.message,
bottomPadding = 156
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ fun TimeRangeScreen(
},
snackbarHost = { snackbarHostState ->
SnackbarHost(hostState = snackbarHostState) { snackbarData ->
PlanzErrorSnackBar(message = snackbarData.message)
PlanzErrorSnackBar(
message = snackbarData.message,
bottomPadding = 100
)
}
}
) { padding ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ fun HomeScreen(
}
LoadState.SUCCESS -> {
Scaffold(
scaffoldState = scaffoldState,
backgroundColor = BackgroundColor1,
topBar = {
HomeUserProfile(
Expand All @@ -159,7 +160,10 @@ fun HomeScreen(
modifier = Modifier.fillMaxSize(),
snackbarHost = { snackbarHostState ->
SnackbarHost(hostState = snackbarHostState) { snackbarData ->
PlanzErrorSnackBar(message = snackbarData.message)
PlanzErrorSnackBar(
message = snackbarData.message,
bottomPadding = 32
)
}
}
) { padding ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
Expand All @@ -46,7 +45,6 @@ class HomeViewModel @Inject constructor(

// 사용자가 여러 번 클릭했을 때 버벅거리는 현상을 없애기 위해 따로 분리
private val _currentDate = MutableStateFlow(CalendarDay.today())

@OptIn(FlowPreview::class)
val currentDate: StateFlow<CalendarDay> = _currentDate.debounce(300).stateIn(
scope = viewModelScope,
Expand Down Expand Up @@ -177,7 +175,7 @@ class HomeViewModel @Inject constructor(
if (!isSubscribed) {
isSubscribed = true

currentDate.collectLatest { currentDate ->
currentDate.collect { currentDate ->
val calendarPlans = emptyList<Plan.FixedPlan>().toMutableList()

val month = currentDate.month
Expand All @@ -201,7 +199,7 @@ class HomeViewModel @Inject constructor(
.onError {
sendEffect({ HomeSideEffect.ShowSnackBar(resourcesProvider.getString(R.string.home_error_message)) })
updateState { copy(monthlyPlanLoadState = LoadState.ERROR) }
return@collectLatest
return@collect
}
getMonthlyFixedPlansUseCase.invoke(previousMonth.toFormatDate())
.onSuccess { plans ->
Expand All @@ -210,7 +208,7 @@ class HomeViewModel @Inject constructor(
.onError {
sendEffect({ HomeSideEffect.ShowSnackBar(resourcesProvider.getString(R.string.home_error_message)) })
updateState { copy(monthlyPlanLoadState = LoadState.ERROR) }
return@collectLatest
return@collect
}
getMonthlyFixedPlansUseCase.invoke(nextMonth.toFormatDate())
.onSuccess { plans ->
Expand All @@ -219,7 +217,7 @@ class HomeViewModel @Inject constructor(
.onError {
sendEffect({ HomeSideEffect.ShowSnackBar(resourcesProvider.getString(R.string.home_error_message)) })
updateState { copy(monthlyPlanLoadState = LoadState.ERROR) }
return@collectLatest
return@collect
}

updateState {
Expand Down