Skip to content

Commit

Permalink
[#441] HighlightedText 컴포넌트 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
nodobi committed Oct 30, 2024
1 parent 8908955 commit 5bed85a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package `in`.koreatech.koin.feature.timetable.component

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.ParagraphStyle
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.LineBreak
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.withStyle

@Composable
fun HighlightedText(
texts: Array<String>,
highlightIndices: List<Int>,
defaultStyle: TextStyle,
highlightStyle: TextStyle,
modifier: Modifier = Modifier
) {
val annotatedString = buildAnnotatedString {
pushStyle(
ParagraphStyle(
lineBreak = LineBreak(
strategy = LineBreak.Strategy.Balanced,
wordBreak = LineBreak.WordBreak.Phrase,
strictness = LineBreak.Strictness.Normal
)
)
)
texts.forEachIndexed { idx, text ->
withStyle(
style = highlightIndices.find { it == idx }
?.let { highlightStyle.toSpanStyle() }
?: defaultStyle.toSpanStyle()
) {
append(text)
}
}
}

Text(
text = annotatedString,
style = defaultStyle,
textAlign = TextAlign.Center,
modifier = modifier
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,26 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringArrayResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.ParagraphStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.LineBreak
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import `in`.koreatech.koin.core.designsystem.theme.FontScalePreviews
import `in`.koreatech.koin.core.designsystem.theme.KoinTheme
import `in`.koreatech.koin.feature.timetable.R
import `in`.koreatech.koin.feature.timetable.component.FilledTextButton
import `in`.koreatech.koin.feature.timetable.component.HighlightedText

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LectureDuplicationDialog(
onConfirm: () -> Unit,
onDismiss: () -> Unit
onDismiss: () -> Unit,
modifier: Modifier = Modifier
) {
BasicAlertDialog(
onDismissRequest = { onDismiss() },
modifier = Modifier,
modifier = modifier,
) {
Surface(
modifier = Modifier
Expand All @@ -69,40 +68,15 @@ fun LectureDuplicationDialog(
style = KoinTheme.typography.bold16,
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = buildAnnotatedString {
pushStyle(
ParagraphStyle(
lineBreak = LineBreak(
strategy = LineBreak.Strategy.Balanced,
wordBreak = LineBreak.WordBreak.Phrase,
strictness = LineBreak.Strictness.Normal
)
)
)
withStyle(
style = KoinTheme.typography.regular14.copy(
color = KoinTheme.colors.neutral600,
).toSpanStyle()
) {
append("추가하시려는 시간에 이미 다른 강의가 있어요.")
}
withStyle(
style = KoinTheme.typography.regular14.copy(
color = KoinTheme.colors.warning600,
).toSpanStyle()
) {
append(" 새로운 강의로 대체")
}
withStyle(
style = KoinTheme.typography.regular14.copy(
color = KoinTheme.colors.neutral600,
).toSpanStyle()
) {
append("하시겠어요?")
}
},
textAlign = TextAlign.Center
HighlightedText(
texts = stringArrayResource(id = R.array.lecture_duplication_description),
highlightIndices = listOf(1),
defaultStyle = KoinTheme.typography.regular14.copy(
color = KoinTheme.colors.neutral600,
),
highlightStyle = KoinTheme.typography.regular14.copy(
color = KoinTheme.colors.warning600,
)
)
Spacer(modifier = Modifier.height(24.dp))
Row(
Expand Down
8 changes: 8 additions & 0 deletions feature/timetable/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@
<string name="lecture_duplication_title">시간표가 중복돼요.</string>
<string name="lecture_duplication_cancellation">취소</string>
<string name="lecture_duplication_confirmation">대체하기</string>

<string-array name="lecture_duplication_description">
<item>추가하시려는 시간에 이미 다른 강의가 있어요.</item>
<item>" 새로운 강의로 대체"</item>
<item>하시겠어요?</item>
</string-array>


</resources>

0 comments on commit 5bed85a

Please sign in to comment.