Remote Compose Storybook Русский GitHub

verticalScroll / horizontalScroll · Vertical

A scrolling column; notches > 0 snaps to positions.

verticalScroll / horizontalScroll · Vertical: the document drawn by the Remote Compose player
Open the live, interactive demo →

Change its controls, read the remote document it produces and the diff after every change.

What it is

Lets content that is longer or wider than its box scroll, with optional snapping, handled entirely on the device.

Good for

  • Lists and feeds
  • Horizontal carousels

Code

The story's source with androidx.compose.remote imports. CI compiles every snippet on this site against AndroidX.

import androidx.compose.remote.creation.compose.layout.RemoteAlignment
import androidx.compose.remote.creation.compose.layout.RemoteBox
import androidx.compose.remote.creation.compose.layout.RemoteColumn
import androidx.compose.remote.creation.compose.layout.RemoteComposable
import androidx.compose.remote.creation.compose.layout.RemoteText
import androidx.compose.remote.creation.compose.modifier.RemoteModifier
import androidx.compose.remote.creation.compose.modifier.background
import androidx.compose.remote.creation.compose.modifier.fillMaxWidth
import androidx.compose.remote.creation.compose.modifier.height
import androidx.compose.remote.creation.compose.modifier.padding
import androidx.compose.remote.creation.compose.modifier.rememberRemoteScrollState
import androidx.compose.remote.creation.compose.modifier.size
import androidx.compose.remote.creation.compose.modifier.verticalScroll
import androidx.compose.remote.creation.compose.state.rc
import androidx.compose.remote.creation.compose.state.rdp
import androidx.compose.remote.creation.compose.state.rs
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color

@Composable
@RemoteComposable
fun VerticalScroll(itemCount: Int, notches: Int) {
    val scrollState = rememberRemoteScrollState(notches)
    RemoteColumn(
        RemoteModifier.size(240.rdp, 260.rdp)
            .background(Color(0xFFF1F3F4).rc)
            .verticalScroll(scrollState),
    ) {
        for (i in 1..itemCount) {
            RemoteBox(
                RemoteModifier.fillMaxWidth()
                    .height(56.rdp)
                    .padding(4.rdp)
                    .background(Color(0xFF26A69A).rc),
                contentAlignment = RemoteAlignment.Center,
            ) {
                RemoteText("Item $i".rs, color = Color.White.rc)
            }
        }
    }
}

API

creation.compose.modifier.verticalScroll

RemoteModifier verticalScroll(RemoteModifier, RemoteScrollState state)

creation.compose.modifier.horizontalScroll

RemoteModifier horizontalScroll(RemoteModifier, RemoteScrollState state)

creation.compose.modifier.rememberRemoteScrollState

RemoteScrollState rememberRemoteScrollState(optional int notches)

creation.compose.modifier.RemoteScrollState

class RemoteScrollState
  RemoteScrollState(MutableRemoteFloat positionState, int notches)
  RemoteScrollState(float position, int notches)
  RemoteScrollState(optional int notches)
  int notches
  MutableRemoteFloat positionState

Reference

Other stories of this component

More in Modifiers