Skip to content

Instantly share code, notes, and snippets.

@navsing
Created January 5, 2023 23:50
Show Gist options
  • Save navsing/e0a7bdd8a4b4ee98a4279f4392bad828 to your computer and use it in GitHub Desktop.
Save navsing/e0a7bdd8a4b4ee98a4279f4392bad828 to your computer and use it in GitHub Desktop.
Card Shimmer Sample
struct CardShimmer : View {
@State var show = false
var center = (UIScreen.main.bounds.width / 2) + 110 //removing padding with this hack
var body : some View{
ZStack{
Color.black.opacity(0.08)
.frame(height: 250)
.cornerRadius(20)
Color.white
.frame(height: 250)
.cornerRadius(20)
.mask(
Rectangle()
.fill(
LinearGradient(gradient: .init(colors: [.clear,Color.white.opacity(0.5),.clear]), startPoint: .top, endPoint: .bottom)
)
.rotationEffect(.init(degrees: 60))
.offset(x: self.show ? center : -center)
)
}
.onAppear {
withAnimation(Animation.default.speed(0.20).delay(0).repeatForever(autoreverses: false)){ //same animation as text shimmer
self.show.toggle()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment