Skip to content

Instantly share code, notes, and snippets.

@Matt54
Created January 15, 2024 19:54
Show Gist options
  • Select an option

  • Save Matt54/d115020f9fcbfe958c626594e9eaead2 to your computer and use it in GitHub Desktop.

Select an option

Save Matt54/d115020f9fcbfe958c626594e9eaead2 to your computer and use it in GitHub Desktop.
SwiftUI repeated fade between two views
struct RepeatedFadeBetweenViews<ViewA: View, ViewB: View>: View {
var animationDuration: Double = 2.0
let viewA: () -> ViewA
let viewB: () -> ViewB
@State private var isViewAVisible = false
var body: some View {
Group {
if isViewAVisible {
viewA()
} else {
viewB()
}
}
.onAppear {
withAnimation(.easeInOut(duration: animationDuration).repeatForever(autoreverses: true)) {
isViewAVisible = true
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment