Last active
August 25, 2024 07:19
-
-
Save nilshoenson/f9aeeca8c05386e481aa89e2a9733558 to your computer and use it in GitHub Desktop.
A wave animation built with shaders in SwiftUI.
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 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?
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
I saw your preview on Twitter and this is amazing. I'm brand new to coding and I'm using ChatGPT to play around with Swift. When I paste the Shader.metal code into Xcode, I get an error
'SwiftUI/SwiftUI_Metal.h' file not found
on line#include <SwiftUI/SwiftUI_Metal.h>
Do you know how I can fix this?