Skip to content

Scrolling and lists ​

Choose the scroll container based on the amount of content. Pass the screen's content padding when using BasicScreen.

Standard scrolling and lazy layouts ​

Use Column with verticalScroll for a small, fixed set of sections. Use lazy composition for long or changing collections. SaltUI includes Compose-based lists, grids, staggered grids, and pagers in com.moriafly.salt.ui.lazy, its subpackages, and com.moriafly.salt.ui.pager.

kotlin
import com.moriafly.salt.ui.lazy.LazyColumn
import com.moriafly.salt.ui.lazy.items

LazyColumn(
    contentPadding = contentPadding
) {
    items(
        items = songs,
        key = { it.id }
    ) { song ->
        Text(text = song.title)
    }
}

Give each song a stable, unique ID so state follows the item when the list is reordered. Check the SaltUI declarations when migrating from Compose Foundation.

Snapping ​

com.moriafly.salt.ui.gestures.snapping provides SnapFlingBehavior. Select the layout info provider that matches the container.

LayoutProvider
Lazy listLazyListSnapLayoutInfoProvider
Lazy gridLazyGridSnapLayoutInfoProvider
PagerPagerSnapLayoutInfoProvider

See the snapping source for signatures.

Cupertino scrolling ​

See Cupertino scrolling for rubber-band overscroll and fling configuration. For nested scrollables, enable overscroll on the edges owned by each container.

Scroll over material ​

Keep the wallpaper outside the scrolling container and draw it before the list in the same theme scope. Cards can then sample the wallpaper as they scroll. To sample both the list and wallpaper behind a floating control, see Glass sources.

Google/Android 是 Google LLC 的注册商标,Salt Player 和糖醋音乐均是寻浔科技(上海)有限公司在中华人民共和国的注册商标