Last active
April 27, 2022 11:46
-
-
Save NikolajMosbaek/c65dcf0620b4403b1f47b29baef3c715 to your computer and use it in GitHub Desktop.
Use this method to support reduced motion from accessibility
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
@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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// From 100 Days of SwiftUI (Day 87) by Paul Hudson: https://www.hackingwithswift.com/books/ios-swiftui/supporting-specific-accessibility-needs-with-swiftui