Skip to content

Commit

Permalink
chore: small refactoring in UIViewAnimation to use a set of keys inst…
Browse files Browse the repository at this point in the history
…eadof a dictionary
  • Loading branch information
mohammedDehairy committed Jun 29, 2021
1 parent 17b9b71 commit d3eb9bd
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Adyen/Helpers/UIViewAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extension UIView {

/// :nodoc:
@objc internal func animate(context: AnimationContext) {
if animationsMap[context.animationKey] == true {
if animationsMap.contains(context.animationKey) {
perform(#selector(animate(context:)), with: context, afterDelay: 0.1)
return
}
Expand All @@ -71,43 +71,43 @@ extension UIView {

/// :nodoc:
@objc internal func animateKeyframes(context: KeyFrameAnimationContext) {
if animationsMap[context.animationKey] == true {
if animationsMap.contains(context.animationKey) {
perform(#selector(animateKeyframes(context:)), with: context, afterDelay: 0.1)
return
}
animateKeyframesSynchronized(context: context)
}

@objc private func animateSynchronized(context: AnimationContext) {
animationsMap[context.animationKey] = true
animationsMap.insert(context.animationKey)
UIView.animate(withDuration: context.duration,
delay: context.delay,
options: context.options,
animations: context.animations,
completion: {
context.completion?($0)
self.animationsMap[context.animationKey] = false
self.animationsMap.remove(context.animationKey)
})
}

@objc private func animateKeyframesSynchronized(context: KeyFrameAnimationContext) {
animationsMap[context.animationKey] = true
animationsMap.insert(context.animationKey)

UIView.animateKeyframes(withDuration: context.duration,
delay: context.delay,
options: context.keyFrameOptions,
animations: context.animations,
completion: {
context.completion?($0)
self.animationsMap[context.animationKey] = false
self.animationsMap.remove(context.animationKey)
})
}

/// :nodoc:
private var animationsMap: [String: Bool] {
private var animationsMap: Set<String> {
get {
guard let value = objc_getAssociatedObject(self, &AssociatedKeys.animations) as? [String: Bool] else {
return [String: Bool]()
guard let value = objc_getAssociatedObject(self, &AssociatedKeys.animations) as? Set<String> else {
return Set<String>()
}
return value
}
Expand Down

0 comments on commit d3eb9bd

Please sign in to comment.