Last active
October 6, 2022 18:22
-
-
Save emin-grbo/05a538cb9b829739341a00c6e25eb9d4 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
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)) | |
} | |
} |
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!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works. Previously it change Equatable from
some
toany
in the ViewModifier, but now both treat it assome
.Also when returning content and content.animation it yields 2 different views, so it could not conform to
some View
, that's why I changed it to return animation withnil
on reducedMotion insteadLastly, previously it animated when
isReduceMotionEnabled
was true, I swapped it around to only animate when its set to false