24 lines
871 B
Swift
24 lines
871 B
Swift
import SwiftUI
|
|
|
|
/// Clips both layers to the track, including fills narrower than the track height.
|
|
struct MetricProgressBar: View {
|
|
let value: Double
|
|
let color: Color
|
|
@Environment(\.metricAnimationsEnabled) private var animates
|
|
|
|
private var fraction: Double { value.isFinite ? min(1, max(0, value)) : 0 }
|
|
|
|
var body: some View {
|
|
GeometryReader { proxy in
|
|
ZStack(alignment: .leading) {
|
|
Capsule().fill(color.opacity(0.15))
|
|
Capsule().fill(color).frame(width: proxy.size.width * fraction)
|
|
}
|
|
.frame(width: proxy.size.width, height: proxy.size.height)
|
|
.clipShape(Capsule())
|
|
.animation(animates ? .easeInOut(duration: MetricMotion.duration) : nil, value: fraction)
|
|
.transaction { if !animates { $0.disablesAnimations = true } }
|
|
}
|
|
}
|
|
}
|