Compose Modifier

interactiveScrollbar

A visual and interactive scrollbar that represents the current scroll position of a scrolling component and allows users to scroll the component by dragging the thumb or pressing the track.

interactiveScrollbar

Source set: Common
@Composable
public fun Modifier.interactiveScrollbar(
    state: ScrollIndicatorState,
    orientation: Orientation,
    onThumbDrag: (positionFraction: Float) -> Unit,
    onTrackPress: (positionFraction: Float) -> Unit,
    thickness: Dp = InteractiveScrollbarDefaults.Thickness,
    thumbMinLength: Dp = InteractiveScrollbarDefaults.ThumbMinLength,
    thumbMaxLengthFraction: Float = InteractiveScrollbarDefaults.ThumbMaxLengthFraction,
    isFadeEnabled: Boolean = true,
    fadeDurationMillis: Int = InteractiveScrollbarDefaults.ThumbFadeDurationMillis,
    fadeDelayMillis: Int = InteractiveScrollbarDefaults.ThumbFadeDelayMillis,
    mainAxisTrackInset: Dp = InteractiveScrollbarDefaults.MainAxisTrackInset,
    crossAxisTrackInset: Dp = InteractiveScrollbarDefaults.CrossAxisTrackInset,
    colors: InteractiveScrollbarColors = InteractiveScrollbarDefaults.colors(),
    thumbInteractionSource: MutableInteractionSource? = null,
): Modifier

A visual and interactive scrollbar that represents the current scroll position of a scrolling component and allows users to scroll the component by dragging the thumb or pressing the track. For a visual-only scrollbar that does not respond to user input, see nonInteractiveScrollbar.

It is drawn at the end edge (respecting layout direction) for a vertically scrollable component, and at the bottom edge for a horizontally scrollable component.

The scrollbar is only visible if the content size is strictly greater than the viewport size. By default, the scrollbar is shown when scrolling is active and fades out after a delay when scrolling stops. Hovering over the scrollbar will also keep it fully visible (or fade it in if it had faded out). This fading behavior can be disabled by setting isFadeEnabled to false, in which case the scrollbar remains always visible.

To use an interactive scrollbar with a androidx.compose.foundation.lazy.LazyColumn, see:

To use an interactive scrollbar with a androidx.compose.foundation.layout.Column that uses androidx.compose.foundation.verticalScroll, see:

Parameters

state the ScrollIndicatorState that represents the scroll state.
orientation the orientation of the scrollbar.
onThumbDrag a callback invoked when the scrollbar thumb is dragged. The lambda receives the positionFraction representing the position of the thumb along the track (between 0f and 1f), which should be used to scroll the content. Note that pressing the thumb without moving the pointer does not invoke this callback, it is only invoked once the pointer moves.
onTrackPress a callback invoked when the scrollbar track is pressed outside the thumb. The lambda receives the positionFraction representing the target position on the track (between 0f and 1f) to jump or navigate to. Note that if onTrackPress moves the thumb under the pressed position, continuous dragging is handled by onThumbDrag.
thickness the thickness of the scrollbar.
thumbMinLength the minimum length of the scrollbar thumb. Note that the scrollbar will not be shown if the available track length is less than this minimum length. Takes precedence over thumbMaxLengthFraction.
thumbMaxLengthFraction the maximum length of the scrollbar thumb as a fraction of the track length. This should be between 0f and 1f. Clamped to at least thumbMinLength.
isFadeEnabled whether the fade behavior is enabled. If enabled, the scrollbar will be shown when scrolling is active, and fades out after a delay when scrolling is idle. If disabled, the scrollbar remains always visible.
fadeDurationMillis the duration of the fade animation in milliseconds.
fadeDelayMillis the delay before the scrollbar fades out in milliseconds.
mainAxisTrackInset the inset to apply to the scrollbar track along the main axis.
crossAxisTrackInset the inset to apply to the scrollbar track along the cross axis.
colors the InteractiveScrollbarColors used to resolve the colors of the scrollbar thumb and track in different states.
thumbInteractionSource an optional hoisted MutableInteractionSource for observing and emitting Interactions for the scrollbar thumb. You can use this to change the thumb's appearance or preview it in different states. Externally emitted interactions only affect the thumb's appearance and do not affect fade visibility; set isFadeEnabled to false to preview interaction states. Interactions are only emitted for the thumb (PressInteraction, DragInteraction, and HoverInteraction), not for track presses. Note that if null is provided, interactions will still happen internally.
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: