Created
May 30, 2021 08:27
-
-
Save zskamljic/979599cf475229bcdc2b38b2042ff6d5 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
@Composable | |
fun CurvedScroll( | |
itemCount: Int, | |
item: @Composable (Int) -> Unit | |
) { | |
Layout( | |
modifier = Modifier, | |
content = { repeat(itemCount) { item(it) } } | |
) { measurables, constraints -> | |
val placeables = measurables.map { measurable -> | |
measurable.measure(constraints) | |
} | |
layout(constraints.maxWidth, constraints.maxHeight) { | |
var yPosition = 0 | |
placeables.forEach { placeable -> | |
placeable.placeRelative(x = 0, y = yPosition) | |
yPosition += placeable.height | |
} | |
} | |
} | |
} | |
@Preview | |
@Composable | |
fun CurvedScrollPreview() { | |
val items = listOf( | |
"One", | |
"Two", | |
"Three", | |
"Four", | |
"Five", | |
"Six" | |
) | |
CustomTheme { | |
Box( | |
modifier = Modifier | |
.background(Color.Gray) | |
.height(300.dp) | |
) { | |
CurvedScroll(items.count()) { | |
Text(text = items[it], style = MaterialTheme.typography.h4) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment