Skip to content

Commit

Permalink
Merge pull request #23 from jtrivedi/janum/fix-block-retain-cycle
Browse files Browse the repository at this point in the history
Block-based animations can create a retain cycle #22
jtrivedi authored Nov 12, 2022
2 parents 5d2d783 + 46ce271 commit ecf541b
Showing 2 changed files with 28 additions and 14 deletions.
24 changes: 16 additions & 8 deletions Sources/Wave/Internal/LayerAnimator.swift
Original file line number Diff line number Diff line change
@@ -56,11 +56,12 @@ extension LayerAnimator {
self?.layer.cornerRadius = value
}

let groupUUID = animation.groupUUID
animation.completion = { [weak self] event in
switch event {
case .finished:
self?.layer.animators.removeValue(forKey: animationType)
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
default:
break
}
@@ -102,11 +103,12 @@ extension LayerAnimator {
self?.layer.opacity = Float(clipUnit(value: value))
}

let groupUUID = animation.groupUUID
animation.completion = { [weak self] event in
switch event {
case .finished:
self?.layer.animators.removeValue(forKey: animationType)
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
default:
break
}
@@ -176,11 +178,12 @@ extension LayerAnimator {
self?.layer.borderColor = components.uiColor.cgColor
}

let groupUUID = animation.groupUUID
animation.completion = { [weak self] event in
switch event {
case .finished(at: _):
self?.layer.animators.removeValue(forKey: animationType)
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
default:
break
}
@@ -223,11 +226,12 @@ extension LayerAnimator {
self?.layer.borderWidth = value
}

let groupUUID = animation.groupUUID
animation.completion = { [weak self] event in
switch event {
case .finished:
self?.layer.animators.removeValue(forKey: animationType)
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
default:
break
}
@@ -270,11 +274,12 @@ extension LayerAnimator {
self?.layer.shadowOpacity = clippedValue
}

let groupUUID = animation.groupUUID
animation.completion = { [weak self] event in
switch event {
case .finished:
self?.layer.animators.removeValue(forKey: animationType)
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
default:
break
}
@@ -344,11 +349,12 @@ extension LayerAnimator {
self?.layer.shadowColor = components.uiColor.cgColor
}

let groupUUID = animation.groupUUID
animation.completion = { [weak self] event in
switch event {
case .finished(at: _):
self?.layer.animators.removeValue(forKey: animationType)
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
default:
break
}
@@ -391,11 +397,12 @@ extension LayerAnimator {
self?.layer.shadowOffset = value
}

let groupUUID = animation.groupUUID
animation.completion = { [weak self] event in
switch event {
case .finished:
self?.layer.animators.removeValue(forKey: animationType)
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
default:
break
}
@@ -437,11 +444,12 @@ extension LayerAnimator {
self?.layer.shadowRadius = max(0, value)
}

let groupUUID = animation.groupUUID
animation.completion = { [weak self] event in
switch event {
case .finished:
self?.layer.animators.removeValue(forKey: animationType)
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
default:
break
}
18 changes: 12 additions & 6 deletions Sources/Wave/Internal/ViewAnimator.swift
Original file line number Diff line number Diff line change
@@ -109,11 +109,12 @@ extension ViewAnimator {
self?.view.center = value
}

let groupUUID = animation.groupUUID
animation.completion = { [weak self] event in
switch event {
case .finished:
self?.view.animators.removeValue(forKey: animationType)
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
case .retargeted:
break
}
@@ -156,11 +157,12 @@ extension ViewAnimator {
self?.view.bounds.origin = boundsOrigin
}

let groupUUID = animation.groupUUID
animation.completion = { [weak self] event in
switch event {
case .finished:
self?.view.animators.removeValue(forKey: animationType)
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
default:
break
}
@@ -204,11 +206,12 @@ extension ViewAnimator {
strongSelf.view.bounds = CGRect(origin: strongSelf.view.bounds.origin, size: size)
}

let groupUUID = animation.groupUUID
animation.completion = { [weak self] event in
switch event {
case .finished:
self?.view.animators.removeValue(forKey: animationType)
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
case .retargeted:
break
}
@@ -267,11 +270,12 @@ extension ViewAnimator {
self?.view.backgroundColor = components.uiColor
}

let groupUUID = animation.groupUUID
animation.completion = { [weak self] event in
switch event {
case .finished(at: _):
self?.view.animators.removeValue(forKey: animationType)
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
default:
break
}
@@ -386,11 +390,12 @@ extension ViewAnimator {
strongSelf.view.transform = transform
}

let groupUUID = animation.groupUUID
animation.completion = { [weak self] event in
switch event {
case .finished:
self?.view.animators.removeValue(forKey: animationType)
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
default:
break
}
@@ -437,11 +442,12 @@ extension ViewAnimator {
strongSelf.view.transform = transform
}

let groupUUID = animation.groupUUID
animation.completion = { [weak self] event in
switch event {
case .finished:
self?.view.animators.removeValue(forKey: animationType)
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
default:
break
}

0 comments on commit ecf541b

Please sign in to comment.