I am doing a scrollable week calendar in jetpack c...
# compose
e
I am doing a scrollable week calendar in jetpack compose android, it scrolls past 7 days. When I am scrolling through the layout, how can I know my current postion to show the specific date . Cause layoutinfo is not working with me. The code is in the thread below ``````
Copy code
@Composable
fun Schedule(
    bookings: List<Booking>,
    modifier: Modifier = Modifier,
    bookingContent: @Composable (booking: Booking) -> Unit = { BookingCard(booking = it) },
    onEmptyViewClicked: (Int, Int, Int) -> Unit
) {
    val hourHeight = 64.dp

    Layout(
        content = {
            bookings.sortedBy { it.start.localDateTime }
                .forEach { booking ->
                    Box(modifier = Modifier.bookingData(booking)) {
                        bookingContent(booking)
                    }
                }
        },
        modifier = modifier
            .pointerInput(Unit) {
                detectTapGestures {
                    val x = it.x.toDp()
                    val y = it.y.toDp()
                    val time = y.value.toInt() / hourHeight.value
                    val selectedDate = time.toInt()
                    println("X: $x, Y: $y")
                    println("selected date $selectedDate")
                    println("Time: $time")
                    val days = selectedDate / 24
                    val startHour = selectedDate - (24 * days)

                    onEmptyViewClicked(days, startHour, selectedDate)

                }
            }
            .drawBehind {
                repeat(167) {
                    drawLine(
                        color = Color.LightGray,
                        start = Offset(0f, (it + 1) * hourHeight.toPx()),
                        end = Offset(size.width, (it + 1) * hourHeight.toPx()),
                        strokeWidth = 1.dp.toPx()
                    )
                }
            },
    ) { measureables, constraints ->
        val height = hourHeight.roundToPx() * 168
        val placeablesWithBookings = measureables.map { measurable ->
            val booking = measurable.parentData as Booking
            val bookingDurationMinutes =
                ChronoUnit.MINUTES.between(booking.start.localDateTime, booking.end.localDateTime)
            val eventHeight = ((bookingDurationMinutes / 60f) * hourHeight.toPx()).roundToInt()
            val placeable = measurable.measure(
                constraints.copy(
                    minHeight = eventHeight,
                    maxHeight = eventHeight
                )
            )
            Pair(placeable, booking)
        }
        layout(constraints.maxWidth, height) {
            placeablesWithBookings.forEach { (placeable, booking) ->
                val dayOffset = ChronoUnit.DAYS.between(
                    LocalDate.now(),
                    booking.start.localDateTime.toLocalDate()
                )
                val bookingOffsetMinutes = ChronoUnit.MINUTES.between(
                    LocalTime.MIN,
                    booking.start.localDateTime.toLocalTime()
                )
                val bookingY =
                    (((bookingOffsetMinutes / 60f) * hourHeight.toPx()) + (dayOffset * hourHeight.roundToPx() * 24)).roundToInt()
                placeable.place(0, bookingY)

            }
        }
    }
}

private class BookingDataModifier(
    val booking: Booking,
) : ParentDataModifier {
    override fun Density.modifyParentData(parentData: Any?) = booking
}

private fun Modifier.bookingData(booking: Booking) = this.then(BookingDataModifier(booking))
any help?