Skip to content

Releases: Dave861/LazyLayoutKit

Release list

0.1.0

Choose a tag to compare

@Dave861 Dave861 released this 02 Aug 08:10

You know LazyVStack, LazyHStack and LazyVGrid. Meet their cousin, the one that lets you write the layout yourself.

Masonry, timelines, calendars, boards: any layout you can describe, with SwiftUI building only the views actually on screen.

LazyLayoutView(photos, layout: MasonryLayout(columns: 3)) { photo in
    .aspectRatio(photo.width / photo.height)   // layout input — no view built
} content: { photo in
    PhotoCell(photo)                           // called only when on screen
}

Why

SwiftUI's Layout gives you any geometry but is eager — it measures every subview, so it falls over a few thousand items in. LazyVStack and friends are lazy but geometrically fixed. There's nothing in between, and in between is where photo grids, feeds, calendars and boards live.

That gap isn't an oversight: Layout asks each subview how big it wants to be, and you can't ask a view that hasn't been built. This package changes the question instead — tell it your item sizes up front and layout becomes arithmetic, so only the frames intersecting your viewport ever become views.

Measured on device

iPhone 14 Pro (A16), iOS 26.5.2, Release:

100,000 items 1,000,000 items
Sustained scroll 120 fps, 8.34 ms p99, zero frames over 16.7 ms 120 fps, 8.34 ms p99, zero frames over 16.7 ms
Visibility query 2.1 µs average 2.0 µs average
Cells materialized, any depth 54 54

The query staying flat from 100k to 1M is the property the design exists to produce. Apple's LazyVStack over the same 100,000 items also managed 120 fps with the same p99 — read that as generality costing very little, not as a claim to be faster.

In this release

  • LazyLayoutAlgorithm, the layout protocol. Item is an associated type, so a timeline can take intervals where masonry takes aspect ratios.
  • LazyLayoutView, a vertically scrolling container that materializes only the visible window, with configurable overscan.
  • VerticalVisibilityIndex — a uniform bucket index over arbitrary frames. Compressed-sparse-row, with an oversized list so tall items aren't duplicated into every bucket. Assumes nothing about ordering, overlap or sign.
  • LayoutSnapshot, an exact eager solve keyed by caller-supplied identity, with identity-based scroll anchoring.
  • MasonryLayout and TimelineLayout reference implementations.
  • Instruments signposts under com.lazylayoutkit / layout.
  • A Release benchmark and an iOS demo app that records on-device frame statistics.

Not in 0.1.0

Vertical scrolling only; item sizes must be known before the view exists; collection changes are correct but unanimated; snapshots are exact and eager, so unbounded collections are out of scope; no custom visibility-query overrides.

Requires iOS 18 / macOS 15.

Apache 2.0.