LazyGridScope

Declares keyed lazy-grid entries with spans and separated logical and physical ownership.

Typed items declarations evaluate their selectors on every parent declaration pass. Equal item identity and revisions still reuse canonical logical items and their sessions.

Samples

val rows = listOf(RevisionSampleRow(id = 7L, version = 3, label = "Ready"))
val compact = true
val list = buildVNodeTree {
    LazyColumn(
        items = rows,
        key = RevisionSampleRow::id,
        contentType = { "status-row" },
        // Ordinary captures that affect item content also belong in its semantic revision.
        contentRevision = { row -> row.version to compact },
    ) { row ->
        Text(if (compact) row.label else "Status: ${row.label}")
    }
}.single()
val item = (list.spec as LazyColumnNodeProps).items.single()

check(item.key == 7L)
check(item.contentType == "status-row")
check(item.contentRevision == (3 to true))

val topLevelVariants = buildVNodeTree {
    LazyRow(
        items = rows,
        key = RevisionSampleRow::id,
        contentRevision = RevisionSampleRow::version,
    ) { row ->
        Text(row.label)
    }
    LazyVerticalGrid(
        items = rows,
        key = RevisionSampleRow::id,
        contentRevision = RevisionSampleRow::version,
    ) { row ->
        Text(row.label)
    }
    LazyColumn {
        items(
            items = rows,
            key = RevisionSampleRow::id,
            contentRevision = RevisionSampleRow::version,
        ) { row ->
            Text(row.label)
        }
    }
    LazyVerticalGrid {
        items(
            items = rows,
            key = RevisionSampleRow::id,
            contentRevision = RevisionSampleRow::version,
        ) { row ->
            Text(row.label)
        }
    }
}

val nestedCollections = buildVNodeTree {
    PullToRefresh(isRefreshing = false, onRefresh = {}) {
        LazyColumn(
            items = rows,
            key = RevisionSampleRow::id,
            contentRevision = RevisionSampleRow::version,
        ) { row ->
            Text(row.label)
        }
    }
    PullToRefresh(isRefreshing = false, onRefresh = {}) {
        LazyRow(
            items = rows,
            key = RevisionSampleRow::id,
            contentRevision = RevisionSampleRow::version,
        ) { row ->
            Text(row.label)
        }
    }
    PullToRefresh(isRefreshing = false, onRefresh = {}) {
        LazyVerticalGrid(
            items = rows,
            key = RevisionSampleRow::id,
            contentRevision = RevisionSampleRow::version,
        ) { row ->
            Text(row.label)
        }
    }
}

check(topLevelVariants.size == 4)
check((nestedCollections[1].children.single().spec as LazyRowNodeProps).items.single().key == 7L)

Functions

Link copied to clipboard
fun item(key: Any, contentRevision: Any, contentType: Any? = null, span: GridItemSpan = GridItemSpan.Single, content: UiTreeBuilder.() -> Unit)

Adds one independently versioned grid item.

Link copied to clipboard
fun <T> items(items: List<T>, key: (T) -> Any, contentType: (T) -> Any? = { null }, contentRevision: (T) -> Any? = { it }, span: (T) -> GridItemSpan = { GridItemSpan.Single }, itemContent: UiTreeBuilder.(T) -> Unit)

Adds independently keyed and versioned grid items from items.

Link copied to clipboard
fun stickyHeader(key: Any, contentRevision: Any, contentType: Any? = null, content: UiTreeBuilder.() -> Unit)

Adds one independently versioned sticky header spanning the full grid row.