17
17
18
18
package ru.tech.imageresizershrinker.core.ui.widget.controls.selection
19
19
20
+ import androidx.compose.animation.AnimatedVisibility
21
+ import androidx.compose.animation.expandVertically
22
+ import androidx.compose.animation.fadeIn
23
+ import androidx.compose.animation.fadeOut
24
+ import androidx.compose.animation.shrinkVertically
20
25
import androidx.compose.foundation.layout.Arrangement
21
26
import androidx.compose.foundation.layout.Column
22
- import androidx.compose.foundation.layout.FlowRow
23
27
import androidx.compose.foundation.layout.PaddingValues
24
28
import androidx.compose.foundation.layout.Row
25
29
import androidx.compose.foundation.layout.RowScope
@@ -86,7 +90,6 @@ fun ScaleModeSelector(
86
90
backgroundColor : Color = Color .Unspecified ,
87
91
shape : Shape = RoundedCornerShape (24.dp),
88
92
enableItemsCardBackground : Boolean = true,
89
- showAsColumns : Boolean = false,
90
93
titlePadding : PaddingValues = PaddingValues (top = 8.dp),
91
94
titleArrangement : Arrangement .Horizontal = Arrangement .Center ,
92
95
entries : List <ImageScaleMode > = ImageScaleMode .defaultEntries(),
@@ -171,90 +174,55 @@ fun ScaleModeSelector(
171
174
} else Modifier .padding(8 .dp)
172
175
)
173
176
174
- if (showAsColumns) {
175
- FlowRow (
176
- verticalArrangement = Arrangement .spacedBy(
177
- space = 8 .dp,
178
- alignment = Alignment .CenterVertically
179
- ),
180
- horizontalArrangement = Arrangement .spacedBy(
181
- space = 8 .dp,
182
- alignment = Alignment .CenterHorizontally
177
+ val state = rememberLazyStaggeredGridState()
178
+ LazyHorizontalStaggeredGrid (
179
+ verticalArrangement = Arrangement .spacedBy(
180
+ space = 8 .dp,
181
+ alignment = Alignment .CenterVertically
182
+ ),
183
+ state = state,
184
+ horizontalItemSpacing = 8 .dp,
185
+ rows = StaggeredGridCells .Adaptive (30 .dp),
186
+ modifier = Modifier
187
+ .heightIn(max = if (enableItemsCardBackground) 160 .dp else 140 .dp)
188
+ .then(chipsModifier)
189
+ .fadingEdges(
190
+ scrollableState = state,
191
+ isVertical = false ,
192
+ spanCount = 3
183
193
),
184
- modifier = chipsModifier
185
- ) {
186
- entries.forEach {
187
- val selected by remember(value, it) {
188
- derivedStateOf {
189
- value::class .isInstance(it)
190
- }
194
+ contentPadding = PaddingValues (2 .dp)
195
+ ) {
196
+ items(entries) {
197
+ val selected by remember(value, it) {
198
+ derivedStateOf {
199
+ value::class .isInstance(it)
191
200
}
192
- EnhancedChip (
193
- onClick = {
194
- onValueChange(it.copy(value.scaleColorSpace))
195
- },
196
- selected = selected,
197
- label = {
198
- Text (text = stringResource(it.title))
199
- },
200
- contentPadding = PaddingValues (horizontal = 16 .dp, vertical = 6 .dp),
201
- selectedColor = MaterialTheme .colorScheme.outlineVariant(
202
- 0.2f ,
203
- MaterialTheme .colorScheme.tertiary
204
- ),
205
- selectedContentColor = MaterialTheme .colorScheme.onTertiary,
206
- unselectedContentColor = MaterialTheme .colorScheme.onSurface
207
- )
208
201
}
209
- }
210
- } else {
211
- val state = rememberLazyStaggeredGridState()
212
- LazyHorizontalStaggeredGrid (
213
- verticalArrangement = Arrangement .spacedBy(
214
- space = 8 .dp,
215
- alignment = Alignment .CenterVertically
216
- ),
217
- state = state,
218
- horizontalItemSpacing = 8 .dp,
219
- rows = StaggeredGridCells .Adaptive (30 .dp),
220
- modifier = Modifier
221
- .heightIn(max = if (enableItemsCardBackground) 160 .dp else 140 .dp)
222
- .then(chipsModifier)
223
- .fadingEdges(
224
- scrollableState = state,
225
- isVertical = false ,
226
- spanCount = 3
202
+ EnhancedChip (
203
+ onClick = {
204
+ onValueChange(it.copy(value.scaleColorSpace))
205
+ },
206
+ selected = selected,
207
+ label = {
208
+ Text (text = stringResource(id = it.title))
209
+ },
210
+ contentPadding = PaddingValues (horizontal = 16 .dp, vertical = 6 .dp),
211
+ selectedColor = MaterialTheme .colorScheme.outlineVariant(
212
+ 0.2f ,
213
+ MaterialTheme .colorScheme.tertiary
227
214
),
228
- contentPadding = PaddingValues (2 .dp)
229
- ) {
230
- items(entries) {
231
- val selected by remember(value, it) {
232
- derivedStateOf {
233
- value::class .isInstance(it)
234
- }
235
- }
236
- EnhancedChip (
237
- onClick = {
238
- onValueChange(it.copy(value.scaleColorSpace))
239
- },
240
- selected = selected,
241
- label = {
242
- Text (text = stringResource(id = it.title))
243
- },
244
- contentPadding = PaddingValues (horizontal = 16 .dp, vertical = 6 .dp),
245
- selectedColor = MaterialTheme .colorScheme.outlineVariant(
246
- 0.2f ,
247
- MaterialTheme .colorScheme.tertiary
248
- ),
249
- selectedContentColor = MaterialTheme .colorScheme.onTertiary,
250
- unselectedContentColor = MaterialTheme .colorScheme.onSurface
251
- )
252
- }
215
+ selectedContentColor = MaterialTheme .colorScheme.onTertiary,
216
+ unselectedContentColor = MaterialTheme .colorScheme.onSurface
217
+ )
253
218
}
254
219
}
255
220
256
- if (isColorSpaceSelectionVisible) {
257
- Spacer (modifier = Modifier .height(4 .dp))
221
+ AnimatedVisibility (
222
+ visible = isColorSpaceSelectionVisible,
223
+ enter = fadeIn() + expandVertically(),
224
+ exit = fadeOut() + shrinkVertically()
225
+ ) {
258
226
val items = remember {
259
227
ScaleColorSpace .entries
260
228
}
@@ -276,10 +244,14 @@ fun ScaleModeSelector(
276
244
shape = ContainerShapeDefaults .bottomShape,
277
245
modifier = Modifier
278
246
.fillMaxWidth()
247
+ .padding(top = 4 .dp)
279
248
.padding(horizontal = 8 .dp),
280
249
selectedItemColor = MaterialTheme .colorScheme.secondary
281
250
)
282
- Spacer (modifier = Modifier .height(8 .dp))
251
+ }
252
+
253
+ AnimatedVisibility (isColorSpaceSelectionVisible || enableItemsCardBackground) {
254
+ Spacer (Modifier .height(8 .dp))
283
255
}
284
256
}
285
257
0 commit comments