Skip to content

Instantly share code, notes, and snippets.

View Sypers's full-sized avatar
🎯
Focusing

Ahmad Sypers

🎯
Focusing
View GitHub Profile
@Sypers
Sypers / ComposeScrollbar.kt
Created September 24, 2024 21:21
A Customizable scrollbar that can be applied in any composable in jetpack compose that supports a Modifier. The scrollbar is not interactive and is just an indicator for the current position of the ScrollState.
@Composable
fun Modifier.verticalScrollBar(
state: ScrollState,
color: Color = Color.Gray,
ratio: Float = 3f,
width: Dp = 8.dp,
alwaysOn: Boolean = false
): Modifier {
val targetAlpha = if (state.isScrollInProgress || alwaysOn) 1f else 0f
val duration = if (state.isScrollInProgress) 150 else 500