Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Conform to this protocol if you need to save animation in tests. It's window.layer.speed won't be affected
- protocol AnimationsInTestSupportable: AnyObject {}
- private var fastAnimationsWasSetUp = false
- public final class AnimationRemoverForQaAutomation: NSObject {
- @objc public static func setUpSwizzling() {
- guard FeatureToggle.features.speedUpAnimationsInE2ETests != fastAnimationsWasSetUp
- else { return }
- guard let originalMethod = class_getInstanceMethod(
- UIView.self,
- #selector(UIView.didMoveToSuperview)
- ) else { return }
- guard let swizzledMethod = class_getInstanceMethod(
- UIView.self,
- #selector(UIView.swizzled_didMoveToSuperview_AnimationRemoverForQaAutomation)
- ) else { return }
- method_exchangeImplementations(originalMethod, swizzledMethod)
- fastAnimationsWasSetUp = FeatureToggle.features.speedUpAnimationsInE2ETests
- }
- }
- extension UIView {
- @objc func swizzled_didMoveToSuperview_AnimationRemoverForQaAutomation() {
- swizzled_didMoveToSuperview_AnimationRemoverForQaAutomation()
- // I tried 1e+20, got black screen.
- // I tried 1_000_000, got many other problems.
- // I tried 10_000, got some problems.
- if !(self is AnimationsInTestSupportable) {
- let bigNumberButNotSoBig: Float = 100
- self.window?.layer.speed = bigNumberButNotSoBig
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement