Created
August 14, 2024 19:07
-
-
Save praveentcom/dbb0fa625e6bb04a5ce43cd661b2f1ca to your computer and use it in GitHub Desktop.
AnimatedGradientView
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 AnimatedGradientView: View { | |
| var colors: [Color] | |
| @State private var startPoint = UnitPoint.topLeading | |
| @State private var endPoint = UnitPoint.bottomTrailing | |
| var body: some View { | |
| LinearGradient( | |
| gradient: Gradient(colors: colors), | |
| startPoint: startPoint, | |
| endPoint: endPoint | |
| ) | |
| .blur(radius: 80) | |
| .edgesIgnoringSafeArea(.all) | |
| .onAppear { | |
| animateGradient() | |
| } | |
| } | |
| func animateGradient() { | |
| withAnimation( | |
| Animation.timingCurve(0.5, 0, 0.5, 1, duration: 6) | |
| .repeatForever(autoreverses: true) | |
| ) { | |
| startPoint = UnitPoint(x: 0.5, y: 0.2) | |
| endPoint = UnitPoint(x: 0.2, y: 0.5) | |
| } | |
| DispatchQueue.main.asyncAfter(deadline: .now() + 6) { | |
| withAnimation( | |
| Animation.timingCurve(0.5, 0, 0.5, 1, duration: 6) | |
| .repeatForever(autoreverses: true) | |
| ) { | |
| startPoint = UnitPoint.bottomTrailing | |
| endPoint = UnitPoint.topLeading | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment