-
-
Save sturdysturge/02dcb2cae951f29cbf13055a7be48067 to your computer and use it in GitHub Desktop.
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 RectangleView: View { | |
| let colour: Color | |
| var body: some View { | |
| Rectangle() | |
| .foregroundColor(colour) | |
| .animation(.linear, value: colour) | |
| } | |
| } | |
| struct ContentView: View { | |
| @State private var colour: Color = .blue | |
| @State var animationEnabled = false | |
| var body: some View { | |
| VStack { | |
| Toggle("Ease In", isOn: $animationEnabled) | |
| RectangleView(colour: colour) | |
| .onTapGesture { | |
| var transaction = Transaction(animation: .easeIn(duration: 1)) | |
| transaction.disablesAnimations = animationEnabled | |
| withTransaction(transaction) { | |
| if colour == .blue { colour = .red } | |
| else { colour = .blue } | |
| } | |
| } | |
| } | |
| .padding() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment