hey guys, does anyone know if Column offers a way to check if there’s enough content for scroll, for example 3 items will not be scrollable in portrait but will be in landscape?
t
Tobias Suchalla
08/23/2023, 1:41 PM
I only know of a workaround using ScrollState:
Copy code
val scrollState = rememberScrollState()
val showScrollbar by scrollState.scrollingNeeded
Column(Modifier.verticalScroll(scrollState)) {
...
}
if (showScrollbar) {
VerticalScrollBar(...)
}
val ScrollState.scrollingNeeded get() = derivedStateOf {
maxValue > 0 && maxValue < Int.MAX_VALUE
}
ScrollState.maxValue
seems to represent the missing space to show all content, i.e. it is greater than 0 when the viewport is too small (and Int.MAX_VALUE when still unkown).
h
Hristijan
08/23/2023, 2:07 PM
Copy code
val scrollState = rememberScrollState()
val canScroll= (scrollState.canScrollForward || scrollState.canScrollBackward)