Last active
July 30, 2024 11:53
-
-
Save jverkoey/780ff5262980b4fe7109c4cf0ba7d740 to your computer and use it in GitHub Desktop.
LinkedIn activity indicator in SwiftUI
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
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