Last active
October 6, 2022 18:22
-
-
Save emin-grbo/05a538cb9b829739341a00c6e25eb9d4 to your computer and use it in GitHub Desktop.
This file contains 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 AnimationWithReduceMotion<V: Equatable>: ViewModifier { | |
@Environment(\.accessibilityReduceMotion) | |
private var reduceMotion | |
var animation: Animation? | |
let value: V | |
func body(content: Content) -> some View { | |
content | |
.animation(reduceMotion ? nil : animation, value: value) | |
} | |
} | |
extension View { | |
func animationWithReducedMotion<V>(_ animation: Animation?, | |
value: V) -> some View where V : Equatable { | |
modifier(AnimationWithReduceMotion(animation: animation, value: value)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ohhhh snap...bloody briliant!! 😅
Not sure how it completely slipped my mind to introduce it at struct signature level 🤦♂️
I Just made a small adjustment with @env var
Thank you!