Andrei Kovalev
10/08/2021, 9:01 AMzIndex
, but the problem is that in lazy LazyGrid Implementation
val rows = (scope.totalSize + nColumns - 1) / nColumns
LazyColumn(
modifier = modifier,
state = state,
contentPadding = contentPadding
) {
items(rows) { rowIndex ->
Row {
for (columnIndex in 0 until nColumns) {
val itemIndex = rowIndex * nColumns + columnIndex
if (itemIndex < scope.totalSize) {
Box(
modifier = Modifier.weight(1f, fill = true),
propagateMinConstraints = true
) {
scope.contentFor(itemIndex, this@items).invoke()
}
} else {
Spacer(Modifier.weight(1f, fill = true))
}
}
}
}
}
our composable items are wrapped in a Box, but zIndex
only works for direct children of the composable node.
How would you resolve this issue? Any suggestions are welcomepatrick
10/08/2021, 9:52 AMAndrei Kovalev
10/08/2021, 11:12 AMLazyColumn(
modifier = modifier,
state = state,
contentPadding = contentPadding
) {
items(rows) { rowIndex ->
CompositionLocalProvider(
LocalSwipableIndex provides mutableStateOf(-1),
) {
Row {
for (columnIndex in 0 until nColumns) {
val itemIndex = rowIndex * nColumns + columnIndex
if (itemIndex < scope.totalSize) {
Box(
modifier = Modifier
.weight(1f, fill = true)
.zIndex(if (itemIndex == LocalSwipableIndex.current.value) 1f else 0f),
propagateMinConstraints = true
) {
scope.contentFor(itemIndex, this@items).invoke()
}
} else {
Spacer(Modifier.weight(1f, fill = true))
}
}
}
}
}
}
So I provide state of the swipeable card for each row
and in my SwipabeCard I set current index of the card which is being swiped:
@Composable
fun SwipableProfileCard(
index: Int,
model : ProfileCardModel
) {
if (swipeState.swipeProgress.value.absoluteValue > 0) {
LocalSwipableIndex.current.value = index
}
}
Andrey Kulikov
10/11/2021, 12:08 PMAndrei Kovalev
10/11/2021, 12:10 PMAlex
12/08/2021, 3:57 PMAndrei Kovalev
12/08/2021, 3:58 PMAndrey Kulikov
12/08/2021, 5:54 PM