I need to create a vertical picker, pretty similar like the one from iOS
I managed to do the snapping, the retrieving of the central item, but the only thing I'm failing to is how to make the list have dynamic height so everytime I'm using it to contain only 5 items.
LazyColumn(
modifier = Modifier
.fillMaxWidth()
.height(264.dp)
.background(Color.Red),
verticalArrangement = Arrangement.spacedBy(8.dp),
state = state,
flingBehavior = rememberSnapFlingBehavior(lazyListState = state),
) {
repeat(2) {
item {
Spacer(modifier = Modifier
.fillMaxWidth()
.height(48.dp))
}
}
items(option1) {
Text(
modifier = Modifier
.fillMaxWidth()
.height(48.dp)
.background(Color.Blue)
.padding(vertical = 16.dp),
text = it,
textAlign = TextAlign.Center,
)
}
repeat(2) {
item {
Spacer(modifier = Modifier
.fillMaxWidth()
.height(48.dp))
}
}
}
Spacer(modifier = Modifier
.fillMaxWidth()
.height(40.dp)
.background(color = Color(30, 30, 30, 40), RoundedCornerShape(12.dp)))
}
I'm actually adding 2 spacer items with the same height as the text items so that the first and last item can be actually selected (be in the middle).