Skip to content

Instantly share code, notes, and snippets.

@praveentcom
Created August 14, 2024 19:07
Show Gist options
  • Select an option

  • Save praveentcom/dbb0fa625e6bb04a5ce43cd661b2f1ca to your computer and use it in GitHub Desktop.

Select an option

Save praveentcom/dbb0fa625e6bb04a5ce43cd661b2f1ca to your computer and use it in GitHub Desktop.
AnimatedGradientView
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