From 46ce271393ea178c25ca3be2c39b0f486c0ea2bc Mon Sep 17 00:00:00 2001 From: Janum Trivedi Date: Fri, 11 Nov 2022 20:30:44 -0800 Subject: [PATCH] Fix retain cycle --- Sources/Wave/Internal/LayerAnimator.swift | 24 +++++++++++++++-------- Sources/Wave/Internal/ViewAnimator.swift | 18 +++++++++++------ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Sources/Wave/Internal/LayerAnimator.swift b/Sources/Wave/Internal/LayerAnimator.swift index a5eb794..74b0198 100644 --- a/Sources/Wave/Internal/LayerAnimator.swift +++ b/Sources/Wave/Internal/LayerAnimator.swift @@ -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 } diff --git a/Sources/Wave/Internal/ViewAnimator.swift b/Sources/Wave/Internal/ViewAnimator.swift index d26b6c2..a7d3976 100644 --- a/Sources/Wave/Internal/ViewAnimator.swift +++ b/Sources/Wave/Internal/ViewAnimator.swift @@ -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 }