package eu.friedcutlet.yokan.ui.components import androidx.compose.foundation.ScrollState import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxScope import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.grid.LazyGridState import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier /** * Wraps content in a Box and overlays a vertical scrollbar on the trailing * edge on platforms that expose one. Desktop gets a real draggable scrollbar; * Android and iOS keep their native scroll feedback. * * Three overloads cover the three scroll state types we actually use in the * app: LazyListState (LazyColumn/LazyRow), LazyGridState (LazyVerticalGrid), * and ScrollState (vertical/horizontal Modifier.verticalScroll). */ @Composable fun ScrollbarBox( state: LazyListState, modifier: Modifier = Modifier, content: @Composable BoxScope.() -> Unit, ) { Box(modifier, propagateMinConstraints = true) { content() // Keep the overlay out of the outer Box's wrap-content measurement. // Desktop's scrollbar fills its available height; measuring it as a // normal child would therefore expand compact dialogs to their maximum // height instead of letting their scrollable content determine it. Box(Modifier.matchParentSize()) { PlatformVerticalScrollbar(state) } } } @Composable fun ScrollbarBox( state: LazyGridState, modifier: Modifier = Modifier, content: @Composable BoxScope.() -> Unit, ) { Box(modifier, propagateMinConstraints = true) { content() Box(Modifier.matchParentSize()) { PlatformVerticalScrollbar(state) } } } @Composable fun ScrollbarBox( state: ScrollState, modifier: Modifier = Modifier, content: @Composable BoxScope.() -> Unit, ) { Box(modifier, propagateMinConstraints = true) { content() Box(Modifier.matchParentSize()) { PlatformVerticalScrollbar(state) } } } @Composable internal expect fun BoxScope.PlatformVerticalScrollbar(state: LazyListState) @Composable internal expect fun BoxScope.PlatformVerticalScrollbar(state: LazyGridState) @Composable internal expect fun BoxScope.PlatformVerticalScrollbar(state: ScrollState)