Skip to content

Commit b85f82f

Browse files
committed
Feat: GuideScreen 화면 구현
1 parent cd13798 commit b85f82f

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.threegap.bitnagil.presentation.guide
2+
3+
import androidx.lifecycle.SavedStateHandle
4+
import com.threegap.bitnagil.presentation.common.mviviewmodel.MviViewModel
5+
import com.threegap.bitnagil.presentation.guide.model.GuideIntent
6+
import com.threegap.bitnagil.presentation.guide.model.GuideSideEffect
7+
import com.threegap.bitnagil.presentation.guide.model.GuideState
8+
import dagger.hilt.android.lifecycle.HiltViewModel
9+
import org.orbitmvi.orbit.syntax.simple.SimpleSyntax
10+
import javax.inject.Inject
11+
12+
@HiltViewModel
13+
class GuideViewModel @Inject constructor(
14+
savedStateHandle: SavedStateHandle,
15+
) : MviViewModel<GuideState, GuideSideEffect, GuideIntent>(
16+
initState = GuideState(),
17+
savedStateHandle = savedStateHandle,
18+
) {
19+
override suspend fun SimpleSyntax<GuideState, GuideSideEffect>.reduceState(
20+
intent: GuideIntent,
21+
state: GuideState,
22+
): GuideState? {
23+
val newState = when (intent) {
24+
is GuideIntent.OnClickGuideButton -> {
25+
state.copy(
26+
guideType = intent.guideType,
27+
guideBottomSheetVisible = true,
28+
)
29+
}
30+
31+
is GuideIntent.OnHideGuideBottomSheet -> {
32+
state.copy(
33+
guideType = null,
34+
guideBottomSheetVisible = false,
35+
)
36+
}
37+
38+
is GuideIntent.OnBackClick -> {
39+
sendSideEffect(GuideSideEffect.NavigateToBack)
40+
null
41+
}
42+
}
43+
44+
return newState
45+
}
46+
}

0 commit comments

Comments
 (0)