Advertisement
Guest User

Speeding up animations in iOS

a guest
May 11th, 2022
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.50 KB | None | 0 0
  1. // Conform to this protocol if you need to save animation in tests. It's window.layer.speed won't be affected
  2. protocol AnimationsInTestSupportable: AnyObject {}
  3.  
  4. private var fastAnimationsWasSetUp = false
  5.  
  6. public final class AnimationRemoverForQaAutomation: NSObject {
  7.     @objc public static func setUpSwizzling() {
  8.         guard FeatureToggle.features.speedUpAnimationsInE2ETests != fastAnimationsWasSetUp
  9.         else { return }
  10.        
  11.         guard let originalMethod = class_getInstanceMethod(
  12.             UIView.self,
  13.             #selector(UIView.didMoveToSuperview)
  14.         ) else { return }
  15.        
  16.         guard let swizzledMethod = class_getInstanceMethod(
  17.             UIView.self,
  18.             #selector(UIView.swizzled_didMoveToSuperview_AnimationRemoverForQaAutomation)
  19.         ) else { return }
  20.        
  21.         method_exchangeImplementations(originalMethod, swizzledMethod)
  22.        
  23.         fastAnimationsWasSetUp = FeatureToggle.features.speedUpAnimationsInE2ETests
  24.     }
  25. }
  26.  
  27. extension UIView {
  28.     @objc func swizzled_didMoveToSuperview_AnimationRemoverForQaAutomation() {
  29.         swizzled_didMoveToSuperview_AnimationRemoverForQaAutomation()
  30.        
  31.         // I tried 1e+20, got black screen.
  32.         // I tried 1_000_000, got many other problems.
  33.         // I tried 10_000, got some problems.
  34.         if !(self is AnimationsInTestSupportable) {
  35.             let bigNumberButNotSoBig: Float = 100
  36.             self.window?.layer.speed = bigNumberButNotSoBig
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement