Daniel Okanin
11/24/2022, 9:36 PMdewildte
11/24/2022, 10:10 PMdewildte
11/24/2022, 10:11 PMdewildte
11/24/2022, 10:15 PMLazyListState#layoutItemInfo
has this infomation.james
11/25/2022, 1:51 AMcanScrollForward
and canScrollBackward
properties to ScrollableState.. and it sounds like that’s exactly what you need
if you do need to deliver this functionality immediately then just grab the current value
and the maxValue
of your scroll state and compare them (if you’re checking for end of list)Daniel Okanin
11/25/2022, 6:46 AMjames
11/27/2022, 10:04 PMval scrollState = rememberScrollState()
val canScrollBackward by remember {
derivedStateOf {
scrollState.value > 0
}
}
then in your back handler code you can simply check if (canScrollBackward) { your scroll-to-top code } else { your dismiss code }
once you get that working you might even want to take it a little further and introduce some threshold, because if the user has scrolled a tiny bit (eg. only a few pixels) then they’re effectively still at the “top” already, but canScrollBackward
will be true because the scroll state is >0, and so the behaviour might feel a bit strange to the user.. but I’ll leave that one up to you 😄