GlassEffectContainer
A view that combines multiple glass shapes into a single shape that can morph individual shapes into one another.
Declaration
import { GlassEffectContainer } from 'swiftui-react-native';@MainActor @preconcurrency struct GlassEffectContainer<Content> where Content : ViewInitializers
One SwiftUI initializer backs <GlassEffectContainer>.
<GlassEffectContainer
spacing?: number | null
>
children?: ReactNode
</GlassEffectContainer>@MainActor @preconcurrency init(
spacing: CGFloat? = nil,
@ContentBuilder content: () -> Content
)spacingnumber | nullDefault
`nil`childrenReactNodeContent. 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.
- AnyLayoutA type-erased instance of the layout protocol.
- GeometryReaderA container view that defines its content as a function of its own size and coordinate space.
- GridA container view that arranges other views in a two dimensional layout.
- GridLayoutA grid that you can use in conditional layouts.
- GridRowA horizontal row in a two dimensional grid container.
- HStackA view that arranges its subviews in a horizontal line.
- HStackLayoutA horizontal container that you can use in conditional layouts.
- LazyHGridA container view that arranges its child views in a grid that grows horizontally, creating items only as needed.
- LazyHStackA view that arranges its children in a line that grows horizontally, creating items only as needed.
- LazyVGridA container view that arranges its child views in a grid that grows vertically, creating items only as needed.
- LazyVStackA view that arranges its children in a line that grows vertically, creating items only as needed.
- ScrollViewA scrollable view.