Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created January 10, 2023 02:02
Show Gist options
  • Select an option

  • Save sturdysturge/02dcb2cae951f29cbf13055a7be48067 to your computer and use it in GitHub Desktop.

Select an option

Save sturdysturge/02dcb2cae951f29cbf13055a7be48067 to your computer and use it in GitHub Desktop.
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