Skip to content

Instantly share code, notes, and snippets.

@jverkoey
Last active July 30, 2024 11:53
Show Gist options
  • Save jverkoey/780ff5262980b4fe7109c4cf0ba7d740 to your computer and use it in GitHub Desktop.
Save jverkoey/780ff5262980b4fe7109c4cf0ba7d740 to your computer and use it in GitHub Desktop.
LinkedIn activity indicator in SwiftUI
import SwiftUI
struct LinkedInActivityIndicator: View {
@State private var animating = false
let cornerRadius: CGFloat
var body: some View {
GeometryReader { proxy in
ZStack {
Rectangle()
.fill(.gray.secondary)
Rectangle()
.fill(.blue)
.frame(width: proxy.size.width / 2)
.clipShape(.rect(cornerRadius: cornerRadius))
.offset(x: animating ? proxy.size.width / 2 : -proxy.size.width / 2)
.animation(
.timingCurve(0.6, 0.0, 0.4, 1.0, duration: 0.85)
.repeatForever(autoreverses: true),
value: animating
)
}
.clipShape(.rect(cornerRadius: cornerRadius))
}
.onAppear {
animating = true
}
}
}
#Preview {
VStack {
LinkedInActivityIndicator(cornerRadius: 5)
.frame(width: 100, height: 10)
.padding(100)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment