Created
August 9, 2025 13:36
-
-
Save jacobsapps/acd3c6034e80d02fe75b2b07d1df5d2d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@State private var currentProgress: Double = 0.0 | |
private var percentageLabel: some View { | |
Text("\(Int(currentProgress * 100))%") | |
.font(.system(size: 48, weight: .bold, design: .rounded)) | |
.foregroundColor(.white) | |
} | |
private var progressBar: some View { | |
TimelineView(.animation) { context in | |
let elapsedTime = animationTrigger ? context.date.timeIntervalSince(animationStartTime) : 0 | |
// Get the interpolated keyframe progress, between 0 and 1 | |
let keyframeValue = progressTimeline.value(time: elapsedTime) | |
ZStack(alignment: .leading) { | |
RoundedRectangle(cornerRadius: 15) | |
.fill(Color.gray.opacity(0.3)) | |
.frame(width: 300, height: 30) | |
RoundedRectangle(cornerRadius: 15) | |
.fill(LinearGradient()) | |
.frame(width: 300 * keyframeValue.progress, height: 30) | |
} | |
.onChange(of: keyframeValue.progress) { _, newValue in | |
currentProgress = newValue // allows percentage label to update | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment