glassEffectUnion
Associates any glass effects defined within this view to a union with the provided id.
Declaration
compose().glassEffectUnion({
id: (string | number | boolean) | null,
namespace: string,
})@MainActor @preconcurrency func glassEffectUnion(
id: (some Hashable & Sendable)?,
namespace: Namespace.ID
) -> some ViewParameters
options.id*(string | number | boolean) | nulloptions.namespace*string
Discussion
You may want the geometries of multiple views to contribute to
a single glass effect shape. In these cases, you can use a
View.glassEffectUnion(id:namespace:) to specify that
a view should contribute to a union of glass effects with
a particular id. All glass effects with the same
shape and glass will be combined into a single shape.
In the example below, two shapes are rendered on the leading and trailing edge each encapsulating two distinct views.
enum PlacementGroup: Hashable {
case leading
case trailing
case spacer
}
struct Item: Identifiable {
var id: String
var placement: Placement
}
@State private var items: [Item] = [
Item(id: "0", placement: .leading),
Item(id: "1", placement: .leading),
Item(id: "spacer", placement: .spacer),
Item(id: "2", placement: .trailing),
Item(id: "3", placement: .trailing)
]
@Namespace private var namespace
var body: some View {
GlassEffectContainer {
HStack {
ForEach(items) { item in
itemView(item)
}
}
}
}
func itemView(_ item: Item) -> some View {
VStack {
if item.placement == .spacer {
Spacer()
} else {
Text(items.id)
.padding()
.glassEffect()
.glassEffectUnion(id: item.placement, namespace: namespace)
}
}
}See also
More in Visual effects.
- allowedDynamicRangeReturns a new view configured with the specified allowed dynamic range.
- backgroundExtensionEffectAdds the background extension effect to the view. The view will be duplicated into mirrored copies which will be placed around the view on any edge with available safe area. Additionally, a blur effect will be applied on top to blur out the copies.
- blurApplies a Gaussian blur to this view.
- brightnessBrightens this view by the specified amount.
- clippedClips this view to its bounding rectangular frame.
- colorEffectReturns a new view that applies shader to self as a filter effect on the color of each pixel.
- colorInvertInverts the colors in this view.
- colorMultiplyAdds a color multiplication effect to this view.
- compositingGroupWraps this view in a compositing group.
- contrastSets the contrast and separation between similar colors in this view.
- distortionEffectReturns a new view that applies shader to self as a geometric distortion effect on the location of each pixel.
- drawingGroupComposites this view's contents into an offscreen image before final display.