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

feat: fix QuackLazyVerticalGridTag title padding #392

Merged
merged 3 commits into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -75,7 +75,7 @@ fun QuackRoundTagDemo() {

private val LazyTagContentHorizontalPadding = 20.dp
private const val LazyTagItemChunkedSize = 5
private val LazyTagDemoRange = 10..100
private val LazyTagDemoRange = 0..30

@Composable
fun QuackLazyVerticalGridTagDemo() {
Expand Down Expand Up @@ -104,7 +104,7 @@ fun QuackSingeLazyRowTagDemo() {
contentPadding = PaddingValues(
horizontal = LazyTagContentHorizontalPadding,
),
title = "Title",
title = "QuackSingeLazyRow",
items = LazyTagDemoRange.map(Int::toString),
itemSelections = LazyTagDemoRange.map { Random.nextBoolean() },
tagType = QuackTagType.Round,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,14 +641,15 @@ public fun QuackLazyVerticalGridTag(
"[items.size (${items.size}) != itemsSelection.size (${itemSelections.size})]"
}
}

val chunkedItems = remember(items) {
items.chunked(itemChunkedSize)
}

Column(
modifier = modifier
.fillMaxWidth()
.padding(contentPadding),
verticalArrangement = Arrangement.spacedBy(horizontalSpace),
) {
if (title != null) {
QuackText(
Expand All @@ -658,39 +659,42 @@ public fun QuackLazyVerticalGridTag(
singleLine = true,
)
}
chunkedItems.fastForEachIndexed { rowIndex, items ->
Row(
modifier = Modifier
.fillMaxWidth()
.horizontalScroll(state = rememberScrollState()),
horizontalArrangement = Arrangement.spacedBy(
space = verticalSpace,
),
) {
items.fastForEachIndexed { index, item ->
val currentIndex = rowIndex * itemChunkedSize + index
val isSelected = itemSelections?.get(currentIndex) ?: false
with(tagType) {
when (this) {
is QuackTagType.Grayscale -> QuackGrayscaleTagInternal(
text = item,
trailingText = trailingText,
actualIndex = currentIndex,
onClickWithIndex = onClick,
)
is QuackTagType.Circle -> QuackCircleTagInternal(
text = item,
trailingIcon = trailingIcon,
isSelected = isSelected,
actualIndex = currentIndex,
onClickWithIndex = onClick,
)
QuackTagType.Round -> QuackRoundTagInternal(
text = item,
isSelected = isSelected,
actualIndex = currentIndex,
onClickWithIndex = onClick,
)
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(horizontalSpace),
) {
chunkedItems.fastForEachIndexed { rowIndex, items ->
Row(
modifier = Modifier
.fillMaxWidth()
.horizontalScroll(state = rememberScrollState()),
horizontalArrangement = Arrangement.spacedBy(verticalSpace),
) {
items.fastForEachIndexed { index, item ->
val currentIndex = rowIndex * itemChunkedSize + index
val isSelected = itemSelections?.get(currentIndex) ?: false
with(tagType) {
when (this) {
is QuackTagType.Grayscale -> QuackGrayscaleTagInternal(
text = item,
trailingText = trailingText,
actualIndex = currentIndex,
onClickWithIndex = onClick,
)
is QuackTagType.Circle -> QuackCircleTagInternal(
text = item,
trailingIcon = trailingIcon,
isSelected = isSelected,
actualIndex = currentIndex,
onClickWithIndex = onClick,
)
QuackTagType.Round -> QuackRoundTagInternal(
text = item,
isSelected = isSelected,
actualIndex = currentIndex,
onClickWithIndex = onClick,
)
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion versions/ui-components.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
major=1
minor=3
patch=6
patch=7