Docs
Backgrounds

Touch Grid

A dot grid that swells and warms in colour under the finger, springs back on release and sends a ripple out from a tap.

$npx swiftpieces add TouchGrid
Free · MIT + Commons ClauseiOS 17.0+backgroundgridinteractivecanvashapticspalette
Type
TouchGrid
Files
TouchGrid.swift
Depends on
Nothing (Apple frameworks only)
Version
2.2.0

Interactive dot grid. Resting dots are a tonal ramp on Style.dot (.primary by default, so both color schemes work); under the finger they swell and take on Style.highlight, a solid house block. It is a surface for content and glass controls to sit on, so it draws no glass and no text of its own.

Notes

  • Everything is drawn in one Canvas inside a TimelineView that pauses when nothing is pressed, springing or rippling, so an idle grid costs nothing. A short task clears expired springs and ripples so the timeline can pause again.
  • While dragging, the field sits on the finger at every frame. At touch-down its strength swells in on the library's press spring (about 90% in 90 ms, no overshoot), so the dots rise under the finger instead of appearing at full size.
  • On release the field springs back on the library's expressive spring, dipping below resting size before it settles in about 0.8 s (the dots under a full press shrink to about 0.75x for a moment), and coasts on along the finger's last direction like a scroll view decelerating, eased toward half the radius, so a flick leaves a short wake. A quick tap lifted mid-swell carries on for a moment before it springs back. A new touch never cuts a lifted field short: it plays out where it was let go while the new one swells under the finger.
  • A tap (moved under 8 pt, held under 0.3 s) emits one ripple ring that eases outward and widens as it fades; ripples are capped at three.
  • Lifted dots swell up to 3.2x and crossfade from the resting ink into the style highlight, so a fully lifted dot reads as solid block color.
  • The .selection haptic fires at most every 120 ms and only when the finger crosses into a new grid cell, so a quick drag ticks lightly instead of buzzing.
  • A touch the system cancels (a scroll taking over, an alert) lets go like a lift, so the grid never stays pressed.
  • Reduce Motion keeps the swell, the color and the haptic under the finger. The release settles on a short spring without dipping below rest or coasting, and a tap blooms in place, warming the dots around it for about half a second, instead of sending a ring out. ripples: false turns the bloom off too.
  • probe drives the grid without a finger, for previews, hints, or onboarding. Its releases spring back in place, with no coast.
  • style: sets the resting dot color (.primary by default) and the block the dots take on as they lift. .standard warms into the brand red, #FF0000; .sky, .lilac, .sage and .butter use the other blocks, and .mono keeps the single-tone ramp.
  • The grid is a surface, not a control, so it draws no glass and no text of its own.
  • The #Preview is the grid alone on the house ground, full bleed; touch it to swell, release to spring back, flick to see the field coast, tap for a ripple.

Usage

TouchGridExample().preferredColorScheme(.light)

Parameters

ParameterDescription
spacingDistance between dots.
dotSizeResting dot diameter.
radiusInfluence radius of the touch.
baseOpacityOpacity of resting dots on .primary.
ripplesWhether a tap emits a ripple ring. Under Reduce Motion a tap blooms in place instead of sending a ring out.
probeOptional programmatic touch point for previews and onboarding hints. Setting it back to nil triggers the release spring; a probe held under 0.3 s emits a ripple like a tap.
styleResting dot color and the block color dots take on under the finger. .standard (default) warms into the brand red; .sky, .lilac, .sage and .butter use the other blocks; .mono keeps the original single-tone ramp.

Install

Pick one. Run it from the folder that contains your .xcodeproj and the files land inside your app.

Terminal

$npx swiftpieces add TouchGrid

Or ask your coding agent · Claude Code, Cursor or Xcode, once the MCP server is connected

>Add the SwiftPieces "Touch Grid" piece to my app

Or copy the source above into your app.

New to SwiftUI?If you know React, CSS or Tailwind, SwiftUI is easier to pick up than it looks.Try real app patterns first

Building a whole app? See SwiftPieces Pro →

All backgrounds →

Build it yourself: SwiftUI animations guide

On this page

SwiftPiecesPro

Build the whole app with one library.

Production-ready screens, whole flows, complete app templates, a Build Kit your agent follows and Pro remixing.

54 screens · 46 patterns · 48 flows · 12 templates · 31 Build Kit skills

Explore Pro