drawingGroup

Composites this view's contents into an offscreen image before final display.

View ModifieriOS 13.0+macOS 10.15+tvOS 13.0+watchOS 6.0+drawingGroup(opaque:colorMode:) in SwiftUI

Declaration

React
compose().drawingGroup({
  opaque?: boolean,
  colorMode?: SwiftUI.ColorRenderingMode,
})
Swift
nonisolated func drawingGroup(
    opaque: Bool = false,
    colorMode: ColorRenderingMode = .nonLinear
) -> some View

Parameters

Return value

A view that composites this view's contents into an offscreen image before display.

Discussion

The drawingGroup(opaque:colorMode:) modifier flattens a subtree of views into a single view before rendering it.

In the example below, the contents of the view are composited to a single bitmap; the bitmap is then displayed in place of the view:

VStack {
    ZStack {
        Text("DrawingGroup")
            .foregroundColor(.black)
            .padding(20)
            .background(Color.red)
        Text("DrawingGroup")
            .blur(radius: 2)
    }
    .font(.largeTitle)
    .compositingGroup()
    .opacity(1.0)
}
.background(Color.white)
.drawingGroup()

See also

More in Visual effects.