-
-
Save eevajonnapanula/59eea746053bc80880672480cca0fe11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CardStack.kt | |
@Composable | |
fun CardStack( | |
modifier: Modifier = Modifier, | |
content: @Composable () -> Unit, | |
) { | |
Layout( | |
content, | |
modifier, | |
) { measurables, constraints -> | |
val placeables = | |
measurables.map { measurable -> | |
measurable.measure(constraints) | |
} | |
val height = if (placeables.isNotEmpty()) | |
placeables.first().height + | |
(CardStack.EXTRA_PADDING * placeables.size) | |
else 0 | |
val width = if (placeables.isNotEmpty()) | |
placeables.first().width | |
else 0 | |
layout(width = width, height = height) { | |
placeables.mapIndexed { index, placeable -> | |
placeable.place( | |
x = if (index.isEven()) | |
0 | |
else | |
CardStack.X_POSITION, | |
y = CardStack.Y_POSITION * index, | |
) | |
} | |
} | |
} | |
} | |
object CardStack { | |
const val EXTRA_PADDING = 10 | |
const val Y_POSITION = 5 | |
const val X_POSITION = 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment