'Extra un-needed Path compute using Shape protocol in SwiftUI
I am experiencing some extra un-needed path compute from Shape which even happens touching the screen of view, I tried to make it equatable and stoping those un-needed compute but did not helped. How can I make Shape stop this extra loads to CPU and compute when the radius change in value?
struct ContentView: View {
var body: some View {
print("Render!")
return ArcShape(radius: 100.0)
.fill(Color.orange)
.background(Color.blue)
}
}
struct ArcShape: Shape, Equatable {
let radius: CGFloat
func path(in rect: CGRect) -> Path {
return Path { path in
print("Compute!")
path.addArc(center: CGPoint(x: rect.midX, y: rect.midY), radius: radius, startAngle: Angle(degrees: 0), endAngle: Angle(degrees: 360), clockwise: true)
}
}
static func ==(lhs: ArcShape, rhs: ArcShape) -> Bool {
return lhs.radius == rhs.radius
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
