In SwiftUI when using .drawingGroup() to flatten a View, I get different results than expected if the view builder uses a ForEach. Example code below results in a view that incorrectly shows only two Circles. If I comment out the .drawingGroup() call then the View correctly shows four Circles in a diamond formation.
Is there a way to get around this? When the .drawingGroup() works its seems pretty effective in improving memory performance and I would like to use if I can.
struct DrawingGroupView: View {
var offsets = [CGPoint(x: 0, y: -1), CGPoint(x: -1, y: 0),
CGPoint(x: 1, y: 0), CGPoint(x: 0, y: 1)]
var width: CGFloat = 90
var body: some View {
ZStack {
ForEach(0..<4) { index in
Circle()
.offset(
x: offsets[index].x * width,
y: offsets[index].y * width
)
.frame(width: width)
}
}
.drawingGroup()
}
}
