Last active
June 28, 2024 20:51
-
-
Save nilshoenson/f9aeeca8c05386e481aa89e2a9733558 to your computer and use it in GitHub Desktop.
A wave animation built with shaders in SwiftUI.
This file contains 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 WavesAnimationView: View { | |
let start = Date() | |
var body: some View { | |
VStack { | |
TimelineView(.animation) { context in | |
RoundedRectangle(cornerRadius: 12) | |
.wavesAnimation( | |
seconds: context.date.timeIntervalSince1970 - self.start.timeIntervalSince1970 | |
) | |
.clipShape(RoundedRectangle(cornerRadius: 12)) | |
} | |
} | |
.ignoresSafeArea() | |
} | |
} | |
extension View { | |
func wavesAnimation(seconds: Double) -> some View { | |
self.colorEffect( | |
ShaderLibrary.default.wavesAnimation(.boundingRect, .float(seconds)) | |
) | |
} | |
} | |
#Preview { | |
WavesAnimationView() | |
} |
Oh I'm guessing I need to have the Xcode 15 beta for this to work?
Yeah this is Xcode 15 & iOS 17 only for now.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh I'm guessing I need to have the Xcode 15 beta for this to work?