Skip to content

Instantly share code, notes, and snippets.

@zskamljic
Created May 30, 2021 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zskamljic/979599cf475229bcdc2b38b2042ff6d5 to your computer and use it in GitHub Desktop.
Save zskamljic/979599cf475229bcdc2b38b2042ff6d5 to your computer and use it in GitHub Desktop.
@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