Docs
Controls

View ToggleNew

A glass list and grid toggle whose red pill flows between them, switching inside an animation so matched items morph.

$npx swiftpieces add ViewToggle
Free · MIT + Commons ClauseiOS 17.0+Liquid Glasslayoutlistgridtogglematched-geometryglasshaptics
Type
ViewToggle
Files
ViewToggle.swift
Depends on
Nothing (Apple frameworks only)
Version
1.0.0

The two layouts ViewToggle switches between.

Notes

  • A two-segment glass toggle for list and grid, with SF Symbols for each. The red pill flows between them.
  • The toggle sets layout inside an animation, the morph spring unless you pass your own. Mark each item with matchedGeometryEffect(id:in:) in both layouts, using one @Namespace, and the items move from rows to tiles with the pill instead of cutting.
  • One selection haptic fires per change. VoiceOver reads it as Layout with List and Grid buttons and marks the selected one.
  • Under Reduce Motion the pill slides whole and the morph spring has no overshoot.

Usage

ViewToggleExample()

Install

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

Terminal

$npx swiftpieces add ViewToggle

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

>Add the SwiftPieces "View Toggle" 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 buttons and controls →

Build it yourself: SwiftUI motion guide · SwiftUI buttons guide · SwiftUI haptics 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.

Explore Pro