Composables
Docs Login
Pairel

Scrollbar

Jetpack Compose Component

Download
package com.composables.pairel.components

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import com.composables.pairel.theme.Theme
import com.composeunstyled.Thumb
import com.composeunstyled.UnstyledVerticalScrollbar
import com.composeunstyled.rememberScrollbarState

@Composable
fun Scrollbar(modifier: Modifier = Modifier, content: @Composable ColumnScope.() -> Unit) {
    val scrollState = rememberScrollState()
    val scrollbarState = rememberScrollbarState(scrollState)
    Box(modifier.clip(Theme.shapes.small).background(Theme.colors.surface)) {
        Column(
            Modifier.fillMaxWidth().verticalScroll(scrollState).padding(end = 12.dp),
            content = content,
        )
        UnstyledVerticalScrollbar(
            scrollbarState = scrollbarState,
            modifier = Modifier.align(Alignment.CenterEnd).width(8.dp).fillMaxHeight(),
        ) {
            Thumb(
                modifier =
                    Modifier.fillMaxWidth()
                        .padding(2.dp)
                        .clip(Theme.shapes.fullyRounded)
                        .background(Theme.colors.accent.copy(alpha = 0.55f))
            )
        }
    }
}

More components from Pairel

by Alex Styl

Search screens and components

Screen flows

Screens

UI Elements

One Android lesson, every Wednesday

Building Android apps?

What Alex learned building Android apps for 14 years, so you don't have to. Reads in under a minute.

Join 3,500+ Android developers. Unsubscribe any time.

You're subscribed

The next lesson lands in on Wednesday.