// // CircularProgressView.swift // OTP // // Created by Shadowfacts on 8/21/21. // import SwiftUI struct CircularProgressView: View { let progress: Double let colorChangeThreshold: Double var body: some View { ZStack { Circle() .stroke(lineWidth: 4) .foregroundColor(progress <= colorChangeThreshold ? .red : .accentColor) .opacity(0.4) .animation(.default, value: progress) Circle() .trim(from: 0, to: progress) .stroke(lineWidth: 4) .foregroundColor(progress <= colorChangeThreshold ? .red : .accentColor) .rotationEffect(.degrees(270)) .animation(.default, value: progress) } .aspectRatio(1, contentMode: .fit) } } struct CircularProgressView_Previews: PreviewProvider { static var previews: some View { CircularProgressView(progress: 0.6, colorChangeThreshold: 0) .frame(width: 30) } }