GlassEffectContainer

A view that combines multiple glass shapes into a single shape that can morph individual shapes into one another.

ComponentiOS 26.0+macOS 26.0+tvOS 26.0+watchOS 26.0+GlassEffectContainer in SwiftUI

Declaration

React
import { GlassEffectContainer } from 'swiftui-react-native';
Swift
@MainActor @preconcurrency struct GlassEffectContainer<Content> where Content : View

Initializers

One SwiftUI initializer backs <GlassEffectContainer>.

React
<GlassEffectContainer
  spacing?: number | null
>
  children?: ReactNode
</GlassEffectContainer>
Swift
@MainActor @preconcurrency init(
    spacing: CGFloat? = nil,
    @ContentBuilder content: () -> Content
)
  • spacingnumber | null

    Default `nil`

  • childrenReactNode

    Content. Strings become Text; React Native views are laid out by Yoga and placed by SwiftUI.

    Swift content: () -> Content

Also takes the common view props: modifiers, style and testID.

Overview

You use a glass effect container with the View.glassEffect(_:in) modifier. Each view with a glass effect contributes a shape rendered with the physical glass material to a set of shapes. SwiftUI renders the glass effects together, improving rendering performance and allowing the effects to interact with and morph into one another.

Configure how the glass shapes interact with one another by customizing the default spacing value provided to the container. As shapes near one another, their paths start to blend into one another. The higher the spacing, the sooner blending begins as glass approaches each other.

In the example below, the two shapes render as if they are a single continuous shape as their geometries overlaps.

private let viewSize = CGSize(width: 40.0, height: 40.0)

GlassEffectContainer(spacing: value) {
    ZStack {
        Image(systemName: "pencil")
            .frame(width: viewSize.width, height: viewSize.height)
            .glassEffect()
            .offset(x: -(viewSize.width / 2.0), y: -(viewSize.height / 2.0))
        Image(systemName: "note")
            .frame(width: viewSize.width, height: viewSize.height)
            .glassEffect()
            .offset(x: (viewSize.width / 2.0), y: (viewSize.height / 2.0))
        }
    }
}

From Apple’s SwiftUI documentation. Code samples there are Swift.

Relationships

Conforms to

  • Swift.Sendable
  • Swift.SendableMetatype
  • View

See also

More in Layout.