mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Consider tests for animations (#1779)
This commit is contained in:
@@ -21,9 +21,22 @@ public extension Animation {
|
||||
/// Animation to be used to disable animations.
|
||||
static let noAnimation: Animation = .linear(duration: 0)
|
||||
|
||||
/// `noAnimation` if running UI tests, otherwise `default` animation.
|
||||
/// `noAnimation` if running tests, otherwise `default` animation if `UIAccessibility.isReduceMotionEnabled` is false
|
||||
static var elementDefault: Animation {
|
||||
Tests.isRunningUITests ? .noAnimation : (UIAccessibility.isReduceMotionEnabled ? .noAnimation : .default)
|
||||
let animation: Animation = Tests.isRunningTests ? .noAnimation : .default
|
||||
return animation.disabledIfReduceMotionEnabled()
|
||||
}
|
||||
|
||||
// `noAnimation` if running tests, otherwise `self` if `UIAccessibility.isReduceMotionEnabled` is false
|
||||
func disabledDuringTests() -> Self {
|
||||
let animation: Animation = Tests.isRunningTests ? .noAnimation : self
|
||||
return animation.disabledIfReduceMotionEnabled()
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func disabledIfReduceMotionEnabled() -> Self {
|
||||
UIAccessibility.isReduceMotionEnabled ? .noAnimation : self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +46,5 @@ public extension Animation {
|
||||
/// - animation: Animation
|
||||
/// - body: operations to be animated
|
||||
public func withElementAnimation<Result>(_ animation: Animation? = .default, _ body: () throws -> Result) rethrows -> Result {
|
||||
if Tests.isRunningUITests {
|
||||
return try withAnimation(.noAnimation, body)
|
||||
}
|
||||
return try withAnimation(animation, body)
|
||||
try withAnimation(animation?.disabledDuringTests(), body)
|
||||
}
|
||||
|
||||
@@ -41,7 +41,10 @@ struct ShimmerModifier: ViewModifier {
|
||||
private let regularColor = Color.white
|
||||
|
||||
/// A slow linear animation which auto-repeats after a delay.
|
||||
private let animation: Animation = Tests.isRunningUITests ? .noAnimation : .linear(duration: 1.75).delay(0.5).repeatForever(autoreverses: false)
|
||||
private let animation: Animation = .linear(duration: 1.75)
|
||||
.delay(0.5)
|
||||
.repeatForever(autoreverses: false)
|
||||
.disabledDuringTests()
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
|
||||
Reference in New Issue
Block a user