Scrollbar.kt
composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/ui/components/Scrollbar.kt
1package eu.friedcutlet.yokan.ui.components23import androidx.compose.foundation.ScrollState4import androidx.compose.foundation.layout.Box5import androidx.compose.foundation.layout.BoxScope6import androidx.compose.foundation.lazy.LazyListState7import androidx.compose.foundation.lazy.grid.LazyGridState8import androidx.compose.runtime.Composable9import androidx.compose.ui.Modifier1011/**12 * Wraps content in a Box and overlays a vertical scrollbar on the trailing13 * edge on platforms that expose one. Desktop gets a real draggable scrollbar;14 * Android and iOS keep their native scroll feedback.15 *16 * Three overloads cover the three scroll state types we actually use in the17 * app: LazyListState (LazyColumn/LazyRow), LazyGridState (LazyVerticalGrid),18 * and ScrollState (vertical/horizontal Modifier.verticalScroll).19 */20@Composable21fun ScrollbarBox(22 state: LazyListState,23 modifier: Modifier = Modifier,24 content: @Composable BoxScope.() -> Unit,25) {26 Box(modifier, propagateMinConstraints = true) {27 content()28 // Keep the overlay out of the outer Box's wrap-content measurement.29 // Desktop's scrollbar fills its available height; measuring it as a30 // normal child would therefore expand compact dialogs to their maximum31 // height instead of letting their scrollable content determine it.32 Box(Modifier.matchParentSize()) {33 PlatformVerticalScrollbar(state)34 }35 }36}3738@Composable39fun ScrollbarBox(40 state: LazyGridState,41 modifier: Modifier = Modifier,42 content: @Composable BoxScope.() -> Unit,43) {44 Box(modifier, propagateMinConstraints = true) {45 content()46 Box(Modifier.matchParentSize()) {47 PlatformVerticalScrollbar(state)48 }49 }50}5152@Composable53fun ScrollbarBox(54 state: ScrollState,55 modifier: Modifier = Modifier,56 content: @Composable BoxScope.() -> Unit,57) {58 Box(modifier, propagateMinConstraints = true) {59 content()60 Box(Modifier.matchParentSize()) {61 PlatformVerticalScrollbar(state)62 }63 }64}6566@Composable67internal expect fun BoxScope.PlatformVerticalScrollbar(state: LazyListState)6869@Composable70internal expect fun BoxScope.PlatformVerticalScrollbar(state: LazyGridState)7172@Composable73internal expect fun BoxScope.PlatformVerticalScrollbar(state: ScrollState)74