animation(nil) replacement in SwiftUI 3.0 (iOS 15)

Prior to iOS 15, setting .animation(nil) removed all animations which would occur to the view. However, animation(_:) was depracated in iOS 15. What is the replacement for this now? Thanks in advance.

Answered by OOPer in 686125022

The doc of animation(_:) says

Deprecated

Use withAnimation or animation(_:value:) instead.

Have you tried?

Accepted Answer

The doc of animation(_:) says

Deprecated

Use withAnimation or animation(_:value:) instead.

Have you tried?

You can use something like this as a general replacement to avoid figuring out a value:

extension View {
	func withoutAnimation() -> some View {
		self.animation(nil, value: UUID())
	}
}

I found this on SwiftLee's website that seemed to be the most compact solution. Just use in place of .animation(nil) :

.transaction { transaction in
    transaction.animation = nil
}

Happy coding!

animation(nil) replacement in SwiftUI 3.0 (iOS 15)
 
 
Q