Skip to content

Instantly share code, notes, and snippets.

@emin-grbo
Last active October 6, 2022 18:22
Show Gist options
  • Save emin-grbo/05a538cb9b829739341a00c6e25eb9d4 to your computer and use it in GitHub Desktop.
Save emin-grbo/05a538cb9b829739341a00c6e25eb9d4 to your computer and use it in GitHub Desktop.
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))
}
}
@emin-grbo
Copy link
Author

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