Thanks for the help, this happened after I updated my Xcode to 16.0 today.
struct TestGradientPath: View {
@State private var startPoint: CGPoint = .zero
@State private var endPoint: CGPoint = .init(x: 0, y: 100)
@State private var controlPoint: CGPoint = .init(x: 100, y: 0)
var body: some View {
ClosedCurve(startPoint: startPoint,
endPoint: endPoint,
controlPoint: controlPoint)
.stroke(.red, lineWidth: 2)
.fill(
// nope
// LinearGradient(
// gradient: Gradient(colors: [.red, .blue]),
// startPoint: .topLeading,
// endPoint: .bottomTrailing
// )
// nope
RadialGradient(gradient: Gradient(colors: [.red.opacity(0.3), .red.opacity(0)]),
center: .center,
startRadius: 0,
endRadius: 64)
// works ok
// .red
)
}
}
struct ClosedCurve: Shape {
var startPoint: CGPoint
var endPoint: CGPoint
var controlPoint: CGPoint
func path(in rect: CGRect) -> Path {
Path { path in
path.move(to: startPoint)
path.addQuadCurve(to: endPoint, control: controlPoint)
path.closeSubpath()
}
}
}
#Preview {
TestGradientPath()
}
Tried several scenarios:
- when creating a shape using a regular arc, the gradient works correctly.
- when filling the bezier shape using a solid color, it works correctly.