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

[PC-300] 약관 디테일 화면 구현 #27

Merged
merged 12 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
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.material3.Text
Expand All @@ -30,7 +31,9 @@ fun PieceMainTopBar(
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = modifier,
modifier = modifier
.fillMaxWidth()
.height(60.dp),
) {
Text(
text = title,
Expand All @@ -54,7 +57,9 @@ fun PieceSubTopBar(
Row(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
modifier = modifier,
modifier = modifier
.fillMaxWidth()
.height(60.dp),
) {
Image(
painter = painterResource(R.drawable.ic_arrow_left),
Expand All @@ -78,7 +83,11 @@ fun PieceSubBackTopBar(
onBackClick: () -> Unit,
modifier: Modifier = Modifier,
) {
Box(modifier = modifier.fillMaxWidth()) {
Box(
modifier = modifier
.fillMaxWidth()
.height(60.dp),
) {
Image(
painter = painterResource(R.drawable.ic_arrow_left),
contentDescription = "뒤로 가기 버튼",
Expand All @@ -105,7 +114,11 @@ fun PieceSubCloseTopBar(
closeButtonEnabled: Boolean = true,
contentColor: Color = PieceTheme.colors.black,
) {
Box(modifier = modifier.fillMaxWidth()) {
Box(
modifier = modifier
.fillMaxWidth()
.height(60.dp),
) {
Text(
text = title,
style = PieceTheme.typography.headingSSB,
Expand Down Expand Up @@ -176,9 +189,7 @@ fun PreviewPieceSubTopBar() {
modifier = Modifier.size(32.dp),
)
},
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 20.dp),
modifier = Modifier.padding(vertical = 20.dp),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.puzzle.designsystem.component

import android.webkit.WebChromeClient
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.viewinterop.AndroidView

@Composable
fun PieceWebView(
url: String,
modifier: Modifier = Modifier,
) {
val context = LocalContext.current
var webView by remember { mutableStateOf<WebView?>(null) }

AndroidView(
factory = {
webView = WebView(context).apply {
settings.javaScriptEnabled = true
webViewClient = object : WebViewClient() {}
webChromeClient = object : WebChromeClient() {}
}
webView!!
},
update = { it.loadUrl(url) },
onRelease = { webView?.destroy() },
modifier = modifier,
)
}
5 changes: 5 additions & 0 deletions core/designsystem/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--Term-->
<string name="next">다음</string>
<string name="agree">동의하기</string>
<string name="all_term_agree">약관 전체 동의</string>

<!--Matching-->
<string name="matching_title">Matching</string>
<string name="check_the_matching_pieces">매칭 조각을 확인해주세요!</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,51 @@
package com.puzzle.auth.graph.registration

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.puzzle.designsystem.R
import com.puzzle.designsystem.component.PieceSolidButton
import com.puzzle.designsystem.component.PieceSubBackTopBar
import com.puzzle.designsystem.component.PieceWebView
import com.puzzle.domain.model.terms.Term

@Composable
internal fun RegistrationDetailScreen() {
internal fun RegistrationDetailScreen(
term: Term,
onBackClick: () -> Unit,
onAgreeClick: () -> Unit,
) {
BackHandler { onBackClick() }

}
Column(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 20.dp),
) {
PieceSubBackTopBar(
title = term.title,
onBackClick = onBackClick,
)

PieceWebView(
url = term.content,
modifier = Modifier
.fillMaxWidth()
.weight(1f),
)

PieceSolidButton(
label = stringResource(R.string.agree),
onClick = onAgreeClick,
modifier = Modifier
.fillMaxWidth()
.padding(top = 12.dp, bottom = 10.dp),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import androidx.compose.foundation.layout.Column
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.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
Expand All @@ -19,31 +21,47 @@ import com.airbnb.mvrx.compose.mavericksViewModel
import com.puzzle.auth.graph.registration.contract.RegistrationIntent
import com.puzzle.auth.graph.registration.contract.RegistrationSideEffect
import com.puzzle.auth.graph.registration.contract.RegistrationState
import com.puzzle.designsystem.R
import com.puzzle.designsystem.component.PieceCheckList
import com.puzzle.designsystem.component.PieceSolidButton
import com.puzzle.designsystem.component.PieceSubBackTopBar
import com.puzzle.designsystem.foundation.PieceTheme
import com.puzzle.domain.model.terms.Term
import com.puzzle.navigation.NavigationEvent

@Composable
internal fun RegistrationRoute(
viewModel: RegistrationViewModel = mavericksViewModel()
) {
val state by viewModel.collectAsState()
val (selectedTerm, setSelectedTerm) = remember { mutableStateOf<Term?>(null) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    var selectedTerm by remember { mutableStateOf<Term?>(null) }

selectedTerm을 위임이 아니라 분해 선언을 하신 이유가 궁금합니다!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    var selectedTerm by remember { mutableStateOf<Term?>(null) }

selectedTerm을 위임이 아니라 분해 선언을 하신 이유가 궁금합니다!

selectedTerm 프로퍼티로 위임해서 사용하고 있었는데,

약관 상세에서 다시 이전화면으로 돌아갈 때

selectedTerm = null

이라는 코드가 약간 어색하게(?) 느껴져서 setSelectedTerm() 이라는 메서드를 사용하고 싶어서 분해하였습니다 ㅎㅎ,,


이 부분 코드 일관성을 위해서 그냥 위임하는게 나을까요 ?!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 아뇨 충분히 좋은 접근이라고 생각합니다....!! 일관성도 가독성을 위한 것이라 생각하기 때문에, setSelectedTerm으로 분리해서 쓰신 이유가 가독성이라면 굳이 일관성을 위해 다시 수정할 필요는 없을 것 같아요!


RegistrationScreen(
state = state,
checkAllTerms = { viewModel.onIntent(RegistrationIntent.CheckAllTerms) },
checkTerm = { viewModel.onIntent(RegistrationIntent.CheckTerm(it)) },
navigate = { event -> viewModel.onSideEffect(RegistrationSideEffect.Navigate(event)) }
)
if (selectedTerm != null) {
RegistrationDetailScreen(
term = selectedTerm,
onBackClick = { setSelectedTerm(null) },
onAgreeClick = {
viewModel.onIntent(RegistrationIntent.CheckTerm(selectedTerm.termId))
setSelectedTerm(null)
}
)
} else {
RegistrationScreen(
state = state,
checkAllTerms = { viewModel.onIntent(RegistrationIntent.CheckAllTerms) },
checkTerm = { viewModel.onIntent(RegistrationIntent.CheckTerm(it)) },
showTermDetail = { setSelectedTerm(it) },
navigate = { event -> viewModel.onSideEffect(RegistrationSideEffect.Navigate(event)) }
)
}
}

@Composable
private fun RegistrationScreen(
state: RegistrationState,
checkAllTerms: () -> Unit,
checkTerm: (Int) -> Unit,
showTermDetail: (Term) -> Unit,
navigate: (NavigationEvent) -> Unit,
) {
Column(
Expand All @@ -54,7 +72,6 @@ private fun RegistrationScreen(
PieceSubBackTopBar(
title = "",
onBackClick = { navigate(NavigationEvent.NavigateUp) },
modifier = Modifier.height(60.dp),
)

Text(
Expand All @@ -80,21 +97,21 @@ private fun RegistrationScreen(

PieceCheckList(
checked = state.allTermsAgreed,
label = "약관 전체 동의",
label = stringResource(R.string.all_term_agree),
containerColor = PieceTheme.colors.light3,
onCheckedChange = checkAllTerms,
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 12.dp),
)

state.terms.forEach { termInfo ->
state.terms.forEach { term ->
PieceCheckList(
checked = state.termsCheckedInfo.getOrDefault(termInfo.termId, false),
checked = state.termsCheckedInfo.getOrDefault(term.termId, false),
arrowEnabled = true,
label = termInfo.title,
onCheckedChange = { checkTerm(termInfo.termId) },
onArrowClick = {},
label = term.title,
onCheckedChange = { checkTerm(term.termId) },
onArrowClick = { showTermDetail(term) },
modifier = Modifier.fillMaxWidth(),
)
}
Expand All @@ -106,7 +123,7 @@ private fun RegistrationScreen(
)

PieceSolidButton(
label = "다음",
label = stringResource(R.string.next),
onClick = {},
modifier = Modifier
.fillMaxWidth()
Expand Down
Loading