Skip to content

Instantly share code, notes, and snippets.

@NikolajMosbaek
Last active April 27, 2022 11:46
Show Gist options
  • Save NikolajMosbaek/c65dcf0620b4403b1f47b29baef3c715 to your computer and use it in GitHub Desktop.
Save NikolajMosbaek/c65dcf0620b4403b1f47b29baef3c715 to your computer and use it in GitHub Desktop.
Use this method to support reduced motion from accessibility
@Environment(\.accessibilityReduceMotion) var reduceMotion
func withOptionalAnimation<Result>(_ animation: Animation? = .default, _ body: () throws -> Result) rethrows -> Result {
if UIAccessibility.isReduceMotionEnabled {
return try body()
} else {
return try withAnimation(animation, body)
}
}
@NikolajMosbaek
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment