New Compose Multiplatform components arrived on Composables UICheck it out →

Modifier in Compose Foundation

horizontalScroll

Common

Modify element to allow to scroll horizontally when width of the content is bigger than max constraints allow.

Last updated:

Installation

dependencies {
   implementation("androidx.compose.foundation:foundation:1.7.0-beta04")
}

Overloads


fun Modifier.horizontalScroll(
    state: ScrollState,
    enabled: Boolean = true,
    flingBehavior: FlingBehavior? = null,
    reverseScrolling: Boolean = false
)

Parameters

namedescription
statestate of the scroll
enabledwhether or not scrolling via touch input is enabled
flingBehaviorlogic describing fling behavior when drag has finished with velocity. If null, default from [ScrollableDefaults.flingBehavior] will be used.
reverseScrollingreverse the direction of scrolling, when true, 0 [ScrollState.value] will mean right, when false, 0 [ScrollState.value] will mean left

Code Example

HorizontalScrollSample

@Composable
@Sampled
fun HorizontalScrollSample() {
    val scrollState = rememberScrollState()
    val gradient = Brush.horizontalGradient(
        listOf(Color.Red, Color.Blue, Color.Green), 0.0f, 10000.0f, TileMode.Repeated
    )
    Box(
        Modifier
            .horizontalScroll(scrollState)
            .size(width = 10000.dp, height = 200.dp)
            .background(brush = gradient)
    )
}