Last active
September 15, 2023 07:27
-
-
Save c-villain/a294fdf502796e2d2cc8396f4b30df77 to your computer and use it in GitHub Desktop.
progress loader
This file contains 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
// | |
// ProgressNew.swift | |
// Test2 | |
// | |
// Created by Alexander Kraev on 14.09.2023. | |
// | |
import SwiftUI | |
struct ProgressNew: View { | |
var progress: CGFloat | |
@State var animate = false | |
var body: some View { | |
VStack(spacing: 40.0) { | |
Button("Start") { | |
animate.toggle() | |
} | |
loader | |
.frame(width: 100, height: 10) | |
} | |
} | |
var loader: some View { | |
GeometryReader { geometry in | |
ZStack(alignment: .leading) { | |
Rectangle() | |
.foregroundColor(Color.white.opacity(0.3)) | |
.cornerRadius(5) | |
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .leading) | |
Rectangle() | |
.foregroundColor(Color.white.opacity(0.9)) | |
.cornerRadius(5) | |
.frame(width: geometry.size.width * self.progress, height: geometry.size.height, alignment: .leading) | |
.padding(.leading, animate ? geometry.size.width : -geometry.size.width * self.progress) | |
.animation(.linear(duration: 2.0).repeatForever(autoreverses: false), value: animate) | |
} | |
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .leading) | |
.clipped() | |
} | |
} | |
} | |
struct ProgressNew_PreviewProvider: PreviewProvider { | |
static var previews: some View { | |
ProgressNew(progress: 0.3) | |
.preferredColorScheme(.dark) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment