|
| 1 | +package com.threegap.bitnagil.presentation.guide |
| 2 | + |
| 3 | +import androidx.compose.foundation.background |
| 4 | +import androidx.compose.foundation.layout.Column |
| 5 | +import androidx.compose.foundation.layout.Spacer |
| 6 | +import androidx.compose.foundation.layout.fillMaxSize |
| 7 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 8 | +import androidx.compose.foundation.layout.height |
| 9 | +import androidx.compose.foundation.layout.padding |
| 10 | +import androidx.compose.foundation.layout.statusBarsPadding |
| 11 | +import androidx.compose.runtime.Composable |
| 12 | +import androidx.compose.runtime.getValue |
| 13 | +import androidx.compose.ui.Modifier |
| 14 | +import androidx.compose.ui.tooling.preview.Preview |
| 15 | +import androidx.compose.ui.unit.dp |
| 16 | +import androidx.hilt.navigation.compose.hiltViewModel |
| 17 | +import androidx.lifecycle.compose.collectAsStateWithLifecycle |
| 18 | +import com.threegap.bitnagil.designsystem.BitnagilTheme |
| 19 | +import com.threegap.bitnagil.designsystem.component.block.BitnagilTopBar |
| 20 | +import com.threegap.bitnagil.presentation.common.flow.collectAsEffect |
| 21 | +import com.threegap.bitnagil.presentation.guide.component.atom.GuideButton |
| 22 | +import com.threegap.bitnagil.presentation.guide.component.template.GuideBottomSheet |
| 23 | +import com.threegap.bitnagil.presentation.guide.model.GuideIntent |
| 24 | +import com.threegap.bitnagil.presentation.guide.model.GuideSideEffect |
| 25 | +import com.threegap.bitnagil.presentation.guide.model.GuideType |
| 26 | + |
| 27 | +@Composable |
| 28 | +fun GuideScreenContainer( |
| 29 | + navigateToBack: () -> Unit, |
| 30 | + viewModel: GuideViewModel = hiltViewModel(), |
| 31 | +) { |
| 32 | + val uiState by viewModel.container.stateFlow.collectAsStateWithLifecycle() |
| 33 | + |
| 34 | + viewModel.sideEffectFlow.collectAsEffect { sideEffect -> |
| 35 | + when (sideEffect) { |
| 36 | + is GuideSideEffect.NavigateToBack -> navigateToBack() |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + if (uiState.guideBottomSheetVisible) { |
| 41 | + uiState.guideType?.let { guideType -> |
| 42 | + GuideBottomSheet( |
| 43 | + guideType = guideType, |
| 44 | + onDismissRequest = { viewModel.sendIntent(GuideIntent.OnHideGuideBottomSheet) }, |
| 45 | + ) |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + GuideScreen( |
| 50 | + onClickGuideButton = { viewModel.sendIntent(GuideIntent.OnClickGuideButton(it)) }, |
| 51 | + onBackClick = { viewModel.sendIntent(GuideIntent.OnBackClick) }, |
| 52 | + ) |
| 53 | +} |
| 54 | + |
| 55 | +@Composable |
| 56 | +private fun GuideScreen( |
| 57 | + onClickGuideButton: (GuideType) -> Unit, |
| 58 | + onBackClick: () -> Unit, |
| 59 | + modifier: Modifier = Modifier, |
| 60 | +) { |
| 61 | + Column( |
| 62 | + modifier = modifier |
| 63 | + .fillMaxSize() |
| 64 | + .background(BitnagilTheme.colors.white) |
| 65 | + .statusBarsPadding(), |
| 66 | + ) { |
| 67 | + BitnagilTopBar( |
| 68 | + title = "설명서", |
| 69 | + showBackButton = true, |
| 70 | + onBackClick = onBackClick, |
| 71 | + modifier = Modifier.fillMaxWidth(), |
| 72 | + ) |
| 73 | + |
| 74 | + Spacer(modifier = Modifier.height(46.dp)) |
| 75 | + |
| 76 | + GuideType.entries.forEach { guideType -> |
| 77 | + GuideButton( |
| 78 | + title = guideType.title, |
| 79 | + onClick = { onClickGuideButton(guideType) }, |
| 80 | + modifier = Modifier |
| 81 | + .padding(horizontal = 16.dp) |
| 82 | + .padding(bottom = 12.dp), |
| 83 | + ) |
| 84 | + } |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +@Preview |
| 89 | +@Composable |
| 90 | +private fun GuideScreenPreview() { |
| 91 | + GuideScreen( |
| 92 | + onClickGuideButton = {}, |
| 93 | + onBackClick = {}, |
| 94 | + ) |
| 95 | +} |
0 commit comments