Skip to content

Instantly share code, notes, and snippets.

@navsing
Created January 5, 2023 23:48
Show Gist options
  • Save navsing/c83eec27afbc87bd28964b8922f04d2c to your computer and use it in GitHub Desktop.
Save navsing/c83eec27afbc87bd28964b8922f04d2c to your computer and use it in GitHub Desktop.
Text Shimmer Sample
struct TextShimmer : View {
@State var show = false
var body : some View{
ZStack{
Text("Shimmer").fontWeight(.heavy).font(.largeTitle).foregroundColor(Color(UIColor.systemOrange)).redacted(reason: .placeholder)
Text("Shimmer").fontWeight(.heavy).font(.largeTitle).foregroundColor(.white)
.mask(
Capsule()
.fill(LinearGradient(gradient: .init(colors: [.clear,.white,.clear]), startPoint: .top, endPoint: .bottom))
.rotationEffect(.init(degrees: 60)) //just to tilt the shimmer a little to prettify it
.offset(x: self.show ? 180 : -120) //since auto reverse is false, it brings the shimmer back to start
)
}.onAppear {
withAnimation(Animation.default.speed(0.20).delay(0).repeatForever(autoreverses: false)){ //you can slow it down here with animation speed
self.show.toggle()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment