16
16
17
17
package com.example.jetcaster.ui.home.discover
18
18
19
- import androidx.compose.foundation.layout.Row
19
+ import androidx.compose.foundation.layout.PaddingValues
20
20
import androidx.compose.foundation.layout.Spacer
21
21
import androidx.compose.foundation.layout.fillMaxWidth
22
22
import androidx.compose.foundation.layout.height
23
23
import androidx.compose.foundation.layout.padding
24
24
import androidx.compose.foundation.lazy.LazyListScope
25
+ import androidx.compose.foundation.lazy.LazyRow
25
26
import androidx.compose.foundation.lazy.grid.LazyGridScope
27
+ import androidx.compose.foundation.lazy.itemsIndexed
26
28
import androidx.compose.material.icons.Icons
27
29
import androidx.compose.material.icons.filled.Check
28
30
import androidx.compose.material3.ExperimentalMaterial3Api
31
+ import androidx.compose.material3.FilterChip
32
+ import androidx.compose.material3.FilterChipDefaults
29
33
import androidx.compose.material3.Icon
30
- import androidx.compose.material3.LocalMinimumInteractiveComponentSize
31
34
import androidx.compose.material3.MaterialTheme
32
- import androidx.compose.material3.ScrollableTabRow
33
- import androidx.compose.material3.Surface
34
- import androidx.compose.material3.TabPosition
35
35
import androidx.compose.material3.Text
36
36
import androidx.compose.runtime.Composable
37
- import androidx.compose.runtime.CompositionLocalProvider
38
37
import androidx.compose.ui.Alignment
39
38
import androidx.compose.ui.Modifier
40
- import androidx.compose.ui.graphics.Color
41
39
import androidx.compose.ui.res.stringResource
42
- import androidx.compose.ui.unit.Dp
43
40
import androidx.compose.ui.unit.dp
44
41
import com.example.jetcaster.R
45
42
import com.example.jetcaster.core.model.CategoryInfo
@@ -122,8 +119,6 @@ fun LazyGridScope.discoverItems(
122
119
)
123
120
}
124
121
125
- private val emptyTabIndicator: @Composable (List <TabPosition >) -> Unit = {}
126
-
127
122
@Composable
128
123
private fun PodcastCategoryTabs (
129
124
filterableCategoriesModel : FilterableCategoriesModel ,
@@ -133,15 +128,15 @@ private fun PodcastCategoryTabs(
133
128
val selectedIndex = filterableCategoriesModel.categories.indexOf(
134
129
filterableCategoriesModel.selectedCategory
135
130
)
136
- ScrollableTabRow (
137
- selectedTabIndex = selectedIndex,
138
- containerColor = Color .Transparent ,
139
- divider = {}, /* Disable the built-in divider */
140
- edgePadding = Keyline1 ,
141
- indicator = emptyTabIndicator,
142
- modifier = modifier
131
+ LazyRow (
132
+ modifier = modifier,
133
+ contentPadding = PaddingValues (horizontal = Keyline1 ),
134
+ verticalAlignment = Alignment .CenterVertically ,
143
135
) {
144
- filterableCategoriesModel.categories.forEachIndexed { index, category ->
136
+ itemsIndexed(
137
+ items = filterableCategoriesModel.categories,
138
+ key = { i, category -> category.id }
139
+ ) { index, category ->
145
140
ChoiceChipContent (
146
141
text = category.name,
147
142
selected = index == selectedIndex,
@@ -160,47 +155,33 @@ private fun ChoiceChipContent(
160
155
onClick : () -> Unit ,
161
156
modifier : Modifier = Modifier
162
157
) {
163
- // When adding onClick to Surface, it automatically makes this item higher.
164
- // On the other hand, adding .clickable modifier, doesn't use the same shape as Surface.
165
- // This way we disable the minimum height requirement
166
- CompositionLocalProvider (value = LocalMinimumInteractiveComponentSize provides Dp .Unspecified ) {
167
- Surface (
168
- color = when {
169
- selected -> MaterialTheme .colorScheme.secondaryContainer
170
- else -> MaterialTheme .colorScheme.surfaceContainer
171
- },
172
- contentColor = when {
173
- selected -> MaterialTheme .colorScheme.onSecondaryContainer
174
- else -> MaterialTheme .colorScheme.onSurfaceVariant
175
- },
176
- shape = MaterialTheme .shapes.medium,
177
- modifier = modifier,
178
- onClick = onClick,
179
- ) {
180
- Row (
181
- verticalAlignment = Alignment .CenterVertically ,
182
- modifier = Modifier .padding(
183
- horizontal = when {
184
- selected -> 8 .dp
185
- else -> 16 .dp
186
- },
187
- vertical = 8 .dp
188
- )
189
- ) {
190
- if (selected) {
191
- Icon (
192
- imageVector = Icons .Default .Check ,
193
- contentDescription = stringResource(id = R .string.cd_selected_category),
194
- modifier = Modifier
195
- .height(18 .dp)
196
- .padding(end = 8 .dp)
197
- )
198
- }
199
- Text (
200
- text = text,
201
- style = MaterialTheme .typography.bodyMedium,
158
+ FilterChip (
159
+ selected = selected,
160
+ onClick = onClick,
161
+ leadingIcon = {
162
+ if (selected) {
163
+ Icon (
164
+ imageVector = Icons .Default .Check ,
165
+ contentDescription = stringResource(id = R .string.cd_selected_category),
166
+ modifier = Modifier .height(18 .dp)
202
167
)
203
168
}
204
- }
205
- }
169
+ },
170
+ label = {
171
+ Text (
172
+ text = text,
173
+ style = MaterialTheme .typography.bodyMedium,
174
+ )
175
+ },
176
+ colors = FilterChipDefaults .filterChipColors().copy(
177
+ containerColor = MaterialTheme .colorScheme.surfaceContainer,
178
+ labelColor = MaterialTheme .colorScheme.onSurfaceVariant,
179
+ selectedContainerColor = MaterialTheme .colorScheme.secondaryContainer,
180
+ selectedLabelColor = MaterialTheme .colorScheme.onSecondaryContainer,
181
+ selectedLeadingIconColor = MaterialTheme .colorScheme.onSecondaryContainer,
182
+ ),
183
+ shape = MaterialTheme .shapes.medium,
184
+ border = null ,
185
+ modifier = modifier,
186
+ )
206
187
}
0 commit comments