Created
January 15, 2024 19:54
-
-
Save Matt54/d115020f9fcbfe958c626594e9eaead2 to your computer and use it in GitHub Desktop.
SwiftUI repeated fade between two views
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
| 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