Created
January 5, 2023 23:48
-
-
Save navsing/c83eec27afbc87bd28964b8922f04d2c to your computer and use it in GitHub Desktop.
Text Shimmer Sample
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
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