My app randomly crashes with the error "Could not cast value of type 'CALayer' to 'SwiftUI.ColorShapeLayer'. Unfortunately the crash is not reproducible and happens rather randomly. I think the reason lies in the SwiftUI ProgressView that I show in my app using a UIHostingViewController as the rest of my app is basically built in UIKit. Here is the code for the ProgressView in question:
public struct CircularProgressView: View {
@State private var progress: Double = 0
public var body: some View {
ZStack(alignment: .center) {
SwiftUI.Color(.white)
Circle()
.trim(from: 0, to: progress)
.stroke(lineWidth: 3)
.rotationEffect(.degrees(-90))
.foregroundColor(.black)
.frame(width: 50, height: 50)
}
.ignoresSafeArea(.all)
.accessibilityIdentifier("progress")
.onAppear {
DispatchQueue.main.async {
withAnimation(Animation.easeInOut(duration: 1.0).repeatForever(autoreverses: false)) {
progress = 1
}
}
}
}
}