SP GlassKit1.1.0

GlassDataGrid

Lazy grid for large collections with stable identifiers and generic cells.

  • Content
  • iOS 26 · iPadOS 26 · macOS 26
  • Version 1.1.0
  • glass-data-grid

Content on an opaque, readable surface. Glass is kept for controls.

GlassDataGrid running in SP Glass Studio.Capture
Capture of the component running in SP Glass Studio on the iOS 26.5 simulator. Liquid Glass is rendered by the system; this is an image, not a live preview.

Installation

spglass add glass-data-grid

Copies the sources and their dependencies into your project. Set up the CLI.

Swift
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")

import SPGlassKit
Identifierglass-data-grid
ModuleSPGlassData
Kindcontent-component — a lazy grid of host content; no glass on cells
PlatformsiOS 26, iPadOS 26, macOS 26
ExampleExamples/Gallery/Data/GlassDataGridExample.swift

Minimal usage

Swift
GlassDataGrid(photos) { photo in
    PhotoCell(photo: photo)
}

Variants

VariantUse
layout: .adaptive(minimum:maximum:)As many tracks as fit the width; the default is .adaptive(minimum: 140).
layout: .fixed(n)Exactly n tracks of equal size.
axis: .verticalLazyVGrid in a vertical scroll view (default).
axis: .horizontalLazyHGrid in a horizontal scroll view; give the grid a bounded height.
With selectionEvery cell becomes a toggle button; the cell closure receives isSelected.

Parameters

ParameterTypeDefaultMeaning
dataRandomAccessCollection of Identifiable—The elements. Identifiers must be stable and unique.
layoutGlassGridLayout.adaptive(minimum: 140)Track sizing.
axisAxis.verticalScrolling direction.
spacingGlassSpacingStep.smGap between cells and around the grid, from the theme's scale.
selectionBinding<Set<Element.ID>>?nilSelected identifiers.
emptyTitleLocalizedStringKey?nilText of the empty state; defaults to "No data".
cell@ViewBuilder (Element) -> Cell or (Element, Bool) -> Cell—Content of one cell.

States

  • Empty: a ContentUnavailableView with emptyTitle.
  • Selected (with a selection binding): a checkmark badge in the top trailing corner and the .isSelected trait; the cell can also change its own appearance from isSelected.
  • Pressed and focused states of selectable cells are those of a plain system button.

Advanced example

Swift
/// A collection that produces its elements on demand: nothing is allocated for 30 000 samples.
struct Samples: RandomAccessCollection {
    let count: Int
    var startIndex: Int { 0 }
    var endIndex: Int { count }
    subscript(position: Int) -> Sample { Sample(id: position) }
}

@State private var selection: Set<Int> = []

GlassDataGrid(Samples(count: 30_000), layout: .fixed(4), spacing: .xs, selection: $selection) { sample, isSelected in
    SampleCell(sample: sample)
        .opacity(isSelected ? 1 : 0.85)
}

Accessibility

  • Cells keep the accessibility of the host's content. Selectable cells are buttons with the .isSelected trait.
  • Selection is shown by a checkmark symbol, not by colour alone.
  • An adaptive layout reflows with the window width and with Dynamic Type if the host's minimum leaves room for larger text; prefer adaptive layouts.

Limits

  • Laziness depends on the collection: indexing and count must be constant-time, and identifiers stable. The grid performs no per-element work in body and never copies the collection into an array.
  • The grid owns its scroll view; do not nest it in another scroll view of the same axis.
  • No prefetching, sections, reordering or drag and drop.
  • Do not put a glass surface in each cell: glass is for controls and navigation layers, and one glass effect per cell is costly.
  • Scrolling performance with tens of thousands of elements was not measured with Instruments in this phase; only the absence of eager work at construction is covered by a test.

Example

Complete example (compiled with the package)
import SwiftUI
import SPGlassKit

public struct GlassDataGridExample: GlassExample {
    public static let componentID = "glass-data-grid"

    struct Sample: Identifiable {
        let id: Int
        var reading: Double { Double((id * 37) % 100) / 100 }
    }

    /// Thirty thousand fictitious samples, produced on demand: no array of that size is ever built.
    struct Samples: RandomAccessCollection {
        let count: Int
        var startIndex: Int { 0 }
        var endIndex: Int { count }
        subscript(position: Int) -> Sample { Sample(id: position) }
    }

    @State private var selection: Set<Int> = [2]
    @State private var fixedColumns = false

    public init() {}

    public var body: some View {
        VStack(alignment: .leading, spacing: 12) {
            Toggle("Three fixed columns", isOn: $fixedColumns)
            Text("\(selection.count) of \(Samples(count: 30_000).count) samples selected")
                .font(.callout)
                .foregroundStyle(.secondary)
            GlassDataGrid(
                Samples(count: 30_000),
                layout: fixedColumns ? .fixed(3) : .adaptive(minimum: 110),
                selection: $selection
            ) { sample, isSelected in
                VStack(alignment: .leading, spacing: 4) {
                    Text("Sample \(sample.id + 1)")
                        .font(.headline)
                    Text(sample.reading, format: .percent.precision(.fractionLength(0)))
                        .font(.callout.monospacedDigit())
                        .foregroundStyle(.secondary)
                    Text(isSelected ? "Selected" : "Tap to select")
                        .font(.caption)
                        .foregroundStyle(.secondary)
                }
                .frame(maxWidth: .infinity, alignment: .leading)
                .padding(12)
                .background(.quaternary, in: RoundedRectangle(cornerRadius: 12, style: .continuous))
            }
        }
        .padding()
    }
}

#Preview("GlassDataGrid") { GlassDataGridExample() }

Registry entry

Identifierglass-data-grid
Version1.1.0
Depends onglass-foundation, glass-table
FrameworksSwiftUI
Public symbolsGlassGridLayout, GlassDataGrid
LicenceMIT
Manifestmanifest.json

Files