Skip to content

Commit 62761fd

Browse files
fix(ui): update reader options ui
1 parent bc746c0 commit 62761fd

2 files changed

Lines changed: 69 additions & 32 deletions

File tree

features/document/src/main/kotlin/ss/document/reader/ReaderOptionsUi.kt

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@
2222

2323
package ss.document.reader
2424

25+
import androidx.compose.animation.AnimatedVisibility
2526
import androidx.compose.foundation.layout.Arrangement
2627
import androidx.compose.foundation.layout.Column
28+
import androidx.compose.foundation.layout.FlowRow
2729
import androidx.compose.foundation.layout.Row
2830
import androidx.compose.foundation.layout.fillMaxWidth
2931
import androidx.compose.foundation.layout.padding
3032
import androidx.compose.foundation.layout.size
31-
import androidx.compose.material3.SegmentedButton
32-
import androidx.compose.material3.SegmentedButtonDefaults
33-
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
33+
import androidx.compose.material3.FilterChip
34+
import androidx.compose.material3.Icon
3435
import androidx.compose.material3.Surface
3536
import androidx.compose.material3.Text
3637
import androidx.compose.runtime.Composable
@@ -40,12 +41,14 @@ import androidx.compose.runtime.remember
4041
import androidx.compose.runtime.setValue
4142
import androidx.compose.ui.Alignment
4243
import androidx.compose.ui.Modifier
44+
import androidx.compose.ui.res.painterResource
4345
import androidx.compose.ui.res.stringResource
4446
import androidx.compose.ui.text.font.FontWeight
4547
import androidx.compose.ui.tooling.preview.PreviewLightDark
4648
import androidx.compose.ui.unit.dp
4749
import app.ss.design.compose.extensions.haptics.LocalSsHapticFeedback
4850
import app.ss.design.compose.theme.SsTheme
51+
import app.ss.design.compose.widget.divider.Divider
4952
import app.ss.design.compose.widget.icon.IconBox
5053
import app.ss.design.compose.widget.icon.ResIcon
5154
import app.ss.design.compose.widget.material.LegacySlider
@@ -66,7 +69,7 @@ fun ReaderOptionsUi(state: State, modifier: Modifier = Modifier) {
6669
Column(
6770
modifier = modifier
6871
.fillMaxWidth()
69-
.padding(bottom = 16.dp), horizontalAlignment = Alignment.CenterHorizontally,
72+
.padding(bottom = 16.dp, top = 8.dp), horizontalAlignment = Alignment.CenterHorizontally,
7073
verticalArrangement = Arrangement.spacedBy(12.dp)
7174
) {
7275
ReaderOptionsTheme(state.config.theme) {
@@ -96,28 +99,35 @@ private fun ReaderOptionsTheme(
9699
text = stringResource(L10nR.string.ss_settings_theme),
97100
modifier = Modifier
98101
.fillMaxWidth()
99-
.padding(horizontal = 16.dp, vertical = 8.dp),
102+
.padding(horizontal = 16.dp),
100103
style = SsTheme.typography.titleMedium.copy(fontWeight = FontWeight.Bold)
101104
)
102105

103-
SingleChoiceSegmentedButtonRow(
106+
FlowRow(
104107
modifier = modifier
105108
.fillMaxWidth()
106-
.padding(horizontal = 16.dp)
109+
.padding(horizontal = 16.dp),
110+
horizontalArrangement = Arrangement.spacedBy(6.dp, Alignment.Start),
107111
) {
108-
ReaderStyle.Theme.entries.forEachIndexed { index, item ->
109-
SegmentedButton(
110-
selected = theme == item,
112+
ReaderStyle.Theme.entries.forEach { item ->
113+
val isSelected = theme == item
114+
FilterChip(
115+
selected = isSelected,
111116
onClick = { onSelected(item) },
112-
shape = SegmentedButtonDefaults.itemShape(index = index, count = ReaderStyle.Typeface.entries.size)
113-
) {
114-
Text(
115-
text = stringResource(item.label()),
116-
style = SsTheme.typography.titleMedium
117-
)
118-
}
117+
label = {
118+
Text(
119+
text = stringResource(item.label()),
120+
style = SsTheme.typography.titleMedium
121+
)
122+
},
123+
leadingIcon = {
124+
LeadingCheckIcon(isSelected)
125+
}
126+
)
119127
}
120128
}
129+
130+
Divider()
121131
}
122132

123133
private fun ReaderStyle.Theme.label() = when (this) {
@@ -137,30 +147,48 @@ private fun ReaderOptionsTypeface(
137147
text = stringResource(L10nR.string.ss_settings_typeface),
138148
modifier = Modifier
139149
.fillMaxWidth()
140-
.padding(horizontal = 16.dp, vertical = 8.dp),
150+
.padding(horizontal = 16.dp),
141151
style = SsTheme.typography.titleMedium.copy(fontWeight = FontWeight.Bold)
142152
)
143153

144-
SingleChoiceSegmentedButtonRow(
154+
FlowRow(
145155
modifier = modifier
146156
.fillMaxWidth()
147-
.padding(horizontal = 16.dp)
157+
.padding(horizontal = 16.dp),
158+
horizontalArrangement = Arrangement.spacedBy(6.dp, Alignment.Start),
148159
) {
149-
ReaderStyle.Typeface.entries.forEachIndexed { index, item ->
150-
SegmentedButton(
151-
selected = typeface == item,
152-
onClick = { onSelected(item) },
153-
shape = SegmentedButtonDefaults.itemShape(index = index, count = ReaderStyle.Typeface.entries.size)
154-
) {
155-
Text(
156-
text = stringResource(item.label()),
157-
style = SsTheme.typography.titleMedium.copy(
158-
fontFamily = Styler.fontFamily(item)
160+
ReaderStyle.Typeface.entries.forEach { option ->
161+
val isSelected = typeface == option
162+
FilterChip(
163+
selected = isSelected,
164+
onClick = { onSelected(option) },
165+
label = {
166+
Text(
167+
text = stringResource(option.label()),
168+
style = SsTheme.typography.titleMedium.copy(
169+
fontFamily = Styler.fontFamily(option)
170+
)
159171
)
160-
)
161-
}
172+
},
173+
leadingIcon = {
174+
LeadingCheckIcon(isSelected)
175+
}
176+
)
162177
}
163178
}
179+
180+
Divider()
181+
}
182+
183+
@Composable
184+
private fun LeadingCheckIcon(isSelected: Boolean, modifier: Modifier = Modifier) {
185+
AnimatedVisibility(isSelected) {
186+
Icon(
187+
painter = painterResource(DocumentR.drawable.ic_check_small),
188+
contentDescription = null,
189+
modifier = modifier,
190+
)
191+
}
164192
}
165193

166194
private fun ReaderStyle.Typeface.label() = when (this) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="960"
5+
android:viewportHeight="960">
6+
<path
7+
android:pathData="m400,544 l236,-236q11,-11 28,-11t28,11q11,11 11,28t-11,28L428,628q-12,12 -28,12t-28,-12L268,524q-11,-11 -11,-28t11,-28q11,-11 28,-11t28,11l76,76Z"
8+
android:fillColor="#e8eaed"/>
9+
</vector>

0 commit comments

Comments
 (0)