I have a row that contains a lazycolumn and a custom layout. The lazy column contains the hours and a custom layout containing events positioned. They have different scroll states, so they won't scroll together. How can I fix this. Cause I need a lazycolumnn to track the day I am in using the layout info.
@Composable
fun ScheduleSidebar(
hourHeight: Dp = 64.dp){
LazyColumn(
modifier = modifier,
) {
val startTime = LocalTime.MIN
items(168) { hour ->
Box(modifier = Modifier.height(hourHeight)) {
Text(startTime.plusHours(hour.toLong()))
}
}
}
This is my view:
@Composable
fun ScheduleView(
viewModel: ScheduleViewModel = getViewModel()
) {
val verticalScrollState = rememberScrollState()
val ss = rememberLazyListState()
val scrollConnection = rememberNestedScrollInteropConnection()
//added this and still the lazycolumn can scroll alone
LaunchedEffect(key1 = Unit) {
var oldValue = 0
snapshotFlow {
verticalScrollState.value
}.collect {
println("Value: $it")
ss.scrollBy((it-oldValue).toFloat())
oldValue = it
}
}
Column(modifier = Modifier.fillMaxSize()) {
ScheduleHeader()
Row(
modifier = Modifier
.weight(1f)
) {
ScheduleSidebar(
hourHeight = 64.dp,
modifier = Modifier
,
)
Schedule(
bookings = viewModel.state.value.bookingsList,
modifier = Modifier
.verticalScroll(verticalScrollState),
onEmptyViewClicked = { days, hour, selectedDate ->
showSheet = true
viewModel.onEvent(
ScheduleEvent.OnEmptyViewClicked(
days = days,
startTime = hour,
selectedDate = selectedDate
)
)
}
)
}
}
}
You can use
to scroll LazyColumn when Column with vertical scroll is scrolled.
Since it's not reproducible or no image for expected result, made a sample to show that how you can scroll using ones value
Edit
If you wish to scroll both scrollable Column and LazyColumn together NestedScrollConnection can be used to get scroll value of LazyColumn and scroll stat to disable LaunchedEffect that listens Column scroll to not scroll LazyColumn further.
However this doesn't work properly if you start scrolling while scroll in other Composable is in progress.
Edit2
This one seem like works well in any condition