All skills
dimillian avatar

/swiftui-liquid-glass

@052112b official
by Thomas Ricouarddimillian/skills4k stars
206

Implement, review, or improve SwiftUI features using the iOS 26+ Liquid Glass API. Use when asked to adopt Liquid Glass in new SwiftUI UI, refactor an existing feature to Liquid Glass, or review Liquid Glass usage for correctness, performance, and design alignment.

Use this Skill: https://skilld.dev/gh/dimillian/skills/swiftui-liquid-glass

This session only. Nothing lands on disk.

referencesliquid-glass.md

≈2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Implementing Liquid Glass Design in SwiftUI

Overview

Liquid Glass is a dynamic material introduced in iOS that combines the optical properties of glass with a sense of fluidity. It blurs content behind it, reflects color and light from surrounding content, and reacts to touch and pointer interactions in real time. This guide covers how to implement and customize Liquid Glass effects in SwiftUI applications. You should always seek guides on Liquid Glass when asked for help adopting new Apple design.

Key features of Liquid Glass:

  • Blurs content behind the material
  • Reflects color and light from surrounding content
  • Reacts to touch and pointer interactions
  • Can morph between shapes during transitions
  • Available for standard and custom components

Basic Implementation

Adding Liquid Glass to a View

The simplest way to add Liquid Glass to a view is using the glassEffect() modifier:

Text("Hello, World!")
    .font(.title)
    .padding()
    .glassEffect()

By default, this applies the regular variant of Glass within a Capsule shape behind the view's content.

Customizing the Shape

You can specify a different shape for the Liquid Glass effect:

Text("Hello, World!")
    .font(.title)
    .padding()
    .glassEffect(in: .rect(cornerRadius: 16.0))

Common shape options:

  • .capsule (default)
  • .rect(cornerRadius: CGFloat)
  • .circle

Customizing Liquid Glass Effects

Glass Variants and Properties

You can customize the Liquid Glass effect by configuring the Glass structure:

Text("Hello, World!")
    .font(.title)
    .padding()
    .glassEffect(.regular.tint(.orange).interactive())

Key customization options:

  • .regular - Standard glass effect
  • .tint(Color) - Add a color tint to suggest prominence
  • .interactive(Bool) - Make the glass react to touch and pointer interactions

Making Interactive Glass

To make Liquid Glass react to touch and pointer interactions:

Text("Hello, World!")
    .font(.title)
    .padding()
    .glassEffect(.regular.interactive(true))

Or more concisely:

Text("Hello, World!")
    .font(.title)
    .padding()
    .glassEffect(.regular.interactive())

Working with Multiple Glass Effects

Using GlassEffectContainer

When applying Liquid Glass effects to multiple views, use GlassEffectContainer for better rendering performance and to enable blending and morphing effects:

GlassEffectContainer(spacing: 40.0) {
    HStack(spacing: 40.0) {
        Image(systemName: "scribble.variable")
            .frame(width: 80.0, height: 80.0)
            .font(.system(size: 36))
            .glassEffect()

        Image(systemName: "eraser.fill")
            .frame(width: 80.0, height: 80.0)
            .font(.system(size: 36))
            .glassEffect()
    }
}

The spacing parameter controls how the Liquid Glass effects interact with each other:

  • Smaller spacing: Views need to be closer to merge effects
  • Larger spacing: Effects merge at greater distances

Uniting Multiple Glass Effects

To combine multiple views into a single Liquid Glass effect, use the glassEffectUnion modifier:

@Namespace private var namespace

// Later in your view:
GlassEffectContainer(spacing: 20.0) {
    HStack(spacing: 20.0) {
        ForEach(symbolSet.indices, id: \.self) { item in
            Image(systemName: symbolSet[item])
                .frame(width: 80.0, height: 80.0)
                .font(.system(size: 36))
                .glassEffect()
                .glassEffectUnion(id: item < 2 ? "1" : "2", namespace: namespace)
        }
    }
}

This is useful when creating views dynamically or with views that live outside of an HStack or VStack.

Morphing Effects and Transitions

Creating Morphing Transitions

To create morphing effects during transitions between views with Liquid Glass:

  1. Create a namespace using the @Namespace property wrapper
  2. Associate each Liquid Glass effect with a unique identifier using glassEffectID
  3. Use animations when changing the view hierarchy
@State private var isExpanded: Bool = false
@Namespace private var namespace

var body: some View {
    GlassEffectContainer(spacing: 40.0) {
        HStack(spacing: 40.0) {
            Image(systemName: "scribble.variable")
                .frame(width: 80.0, height: 80.0)
                .font(.system(size: 36))
                .glassEffect()
                .glassEffectID("pencil", in: namespace)

            if isExpanded {
                Image(systemName: "eraser.fill")
                    .frame(width: 80.0, height: 80.0)
                    .font(.system(size: 36))
                    .glassEffect()
                    .glassEffectID("eraser", in: namespace)
            }
        }
    }

    Button("Toggle") {
        withAnimation {
            isExpanded.toggle()
        }
    }
    .buttonStyle(.glass)
}

The morphing effect occurs when views with Liquid Glass appear or disappear due to view hierarchy changes.

Button Styling with Liquid Glass

Glass Button Style

SwiftUI provides built-in button styles for Liquid Glass:

Button("Click Me") {
    // Action
}
.buttonStyle(.glass)

Glass Prominent Button Style

For a more prominent glass button:

Button("Important Action") {
    // Action
}
.buttonStyle(.glassProminent)

Advanced Techniques

Background Extension Effect

To stretch content behind a sidebar or inspector with the background extension effect:

NavigationSplitView {
    // Sidebar content
} detail: {
    // Detail content
        .background {
            // Background content that extends under the sidebar
        }
}

Extending Horizontal Scrolling Under Sidebar

To extend horizontal scroll views under a sidebar or inspector:

ScrollView(.horizontal) {
    // Scrollable content
}
.scrollExtensionMode(.underSidebar)

Best Practices

  1. Container Usage: Always use GlassEffectContainer when applying Liquid Glass to multiple views for better performance and morphing effects.

  2. Effect Order: Apply the .glassEffect() modifier after other modifiers that affect the appearance of the view.

  3. Spacing Consideration: Carefully choose spacing values in containers to control how and when glass effects merge.

  4. Animation: Use animations when changing view hierarchies to enable smooth morphing transitions.

  5. Interactivity: Add .interactive() to glass effects that should respond to user interaction.

  6. Consistent Design: Maintain consistent shapes and styles across your app for a cohesive look and feel.

Example: Custom Badge with Liquid Glass

struct BadgeView: View {
    let symbol: String
    let color: Color

    var body: some View {
        ZStack {
            Image(systemName: "hexagon.fill")
                .foregroundColor(color)
                .font(.system(size: 50))

            Image(systemName: symbol)
                .foregroundColor(.white)
                .font(.system(size: 30))
        }
        .glassEffect(.regular, in: .rect(cornerRadius: 16))
    }
}

// Usage:
GlassEffectContainer(spacing: 20) {
    HStack(spacing: 20) {
        BadgeView(symbol: "star.fill", color: .blue)
        BadgeView(symbol: "heart.fill", color: .red)
        BadgeView(symbol: "leaf.fill", color: .green)
    }
}

References

Source: SKILL.md on GitHub

No alerts17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    This skill provides documentation and code snippets for the SwiftUI Liquid Glass API. It does not perform any dangerous operations, execute external code, or access sensitive data.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer6mo

    2 files scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 052112b. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Dormantupdated 9 months ago
  • Design
  • swiftui
  • ios
  • liquid-glass
  • ui
  • glass-effect
  • apple
  • ios-26

README badge

README badge for dimillian/skills/swiftui-liquid-glass

Implement, review, or improve SwiftUI features using the iOS 26+ Liquid Glass API, including native modifiers like `glassEffect`, `GlassEffectContainer`, and glass button styles. Use this when adopting Liquid Glass in new UI, refactoring existing features, or reviewing for correctness, performance, and design alignment with Apple's guidelines.

Generated from the current SKILL.md.

What iOS versions does this skill support?
The skill targets iOS 26+ and requires gating code with #available(iOS 26, *). Fallback UI using materials like .ultraThinMaterial is expected for earlier versions.
Does this skill work with SwiftUI only?
Yes. The skill is specific to SwiftUI and uses native SwiftUI modifiers like .glassEffect(), GlassEffectContainer, and button styles.
What should I use instead of custom blur effects?
The skill prioritizes native Liquid Glass APIs (.glassEffect and GlassEffectContainer) over custom blurs for consistency with Apple design guidance and performance.
When should I use GlassEffectContainer versus individual glassEffect modifiers?
Use GlassEffectContainer when multiple glass elements coexist together to manage spacing and composition; use individual .glassEffect() modifiers for isolated glass surfaces.
How do I handle animations and view hierarchy changes with Liquid Glass?
Use glassEffectID with @Namespace to enable morphing transitions when the view hierarchy changes during animation.

Generated from the current SKILL.md. These answers refresh after source changes.