Skip to content

Commit ecf541b

Browse files
authored
Merge pull request #23 from jtrivedi/janum/fix-block-retain-cycle
Block-based animations can create a retain cycle #22
2 parents 5d2d783 + 46ce271 commit ecf541b

2 files changed

Lines changed: 28 additions & 14 deletions

File tree

Sources/Wave/Internal/LayerAnimator.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ extension LayerAnimator {
5656
self?.layer.cornerRadius = value
5757
}
5858

59+
let groupUUID = animation.groupUUID
5960
animation.completion = { [weak self] event in
6061
switch event {
6162
case .finished:
6263
self?.layer.animators.removeValue(forKey: animationType)
63-
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
64+
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
6465
default:
6566
break
6667
}
@@ -102,11 +103,12 @@ extension LayerAnimator {
102103
self?.layer.opacity = Float(clipUnit(value: value))
103104
}
104105

106+
let groupUUID = animation.groupUUID
105107
animation.completion = { [weak self] event in
106108
switch event {
107109
case .finished:
108110
self?.layer.animators.removeValue(forKey: animationType)
109-
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
111+
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
110112
default:
111113
break
112114
}
@@ -176,11 +178,12 @@ extension LayerAnimator {
176178
self?.layer.borderColor = components.uiColor.cgColor
177179
}
178180

181+
let groupUUID = animation.groupUUID
179182
animation.completion = { [weak self] event in
180183
switch event {
181184
case .finished(at: _):
182185
self?.layer.animators.removeValue(forKey: animationType)
183-
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
186+
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
184187
default:
185188
break
186189
}
@@ -223,11 +226,12 @@ extension LayerAnimator {
223226
self?.layer.borderWidth = value
224227
}
225228

229+
let groupUUID = animation.groupUUID
226230
animation.completion = { [weak self] event in
227231
switch event {
228232
case .finished:
229233
self?.layer.animators.removeValue(forKey: animationType)
230-
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
234+
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
231235
default:
232236
break
233237
}
@@ -270,11 +274,12 @@ extension LayerAnimator {
270274
self?.layer.shadowOpacity = clippedValue
271275
}
272276

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

352+
let groupUUID = animation.groupUUID
347353
animation.completion = { [weak self] event in
348354
switch event {
349355
case .finished(at: _):
350356
self?.layer.animators.removeValue(forKey: animationType)
351-
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
357+
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
352358
default:
353359
break
354360
}
@@ -391,11 +397,12 @@ extension LayerAnimator {
391397
self?.layer.shadowOffset = value
392398
}
393399

400+
let groupUUID = animation.groupUUID
394401
animation.completion = { [weak self] event in
395402
switch event {
396403
case .finished:
397404
self?.layer.animators.removeValue(forKey: animationType)
398-
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
405+
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
399406
default:
400407
break
401408
}
@@ -437,11 +444,12 @@ extension LayerAnimator {
437444
self?.layer.shadowRadius = max(0, value)
438445
}
439446

447+
let groupUUID = animation.groupUUID
440448
animation.completion = { [weak self] event in
441449
switch event {
442450
case .finished:
443451
self?.layer.animators.removeValue(forKey: animationType)
444-
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
452+
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
445453
default:
446454
break
447455
}

Sources/Wave/Internal/ViewAnimator.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,12 @@ extension ViewAnimator {
109109
self?.view.center = value
110110
}
111111

112+
let groupUUID = animation.groupUUID
112113
animation.completion = { [weak self] event in
113114
switch event {
114115
case .finished:
115116
self?.view.animators.removeValue(forKey: animationType)
116-
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
117+
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
117118
case .retargeted:
118119
break
119120
}
@@ -156,11 +157,12 @@ extension ViewAnimator {
156157
self?.view.bounds.origin = boundsOrigin
157158
}
158159

160+
let groupUUID = animation.groupUUID
159161
animation.completion = { [weak self] event in
160162
switch event {
161163
case .finished:
162164
self?.view.animators.removeValue(forKey: animationType)
163-
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
165+
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
164166
default:
165167
break
166168
}
@@ -204,11 +206,12 @@ extension ViewAnimator {
204206
strongSelf.view.bounds = CGRect(origin: strongSelf.view.bounds.origin, size: size)
205207
}
206208

209+
let groupUUID = animation.groupUUID
207210
animation.completion = { [weak self] event in
208211
switch event {
209212
case .finished:
210213
self?.view.animators.removeValue(forKey: animationType)
211-
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
214+
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
212215
case .retargeted:
213216
break
214217
}
@@ -267,11 +270,12 @@ extension ViewAnimator {
267270
self?.view.backgroundColor = components.uiColor
268271
}
269272

273+
let groupUUID = animation.groupUUID
270274
animation.completion = { [weak self] event in
271275
switch event {
272276
case .finished(at: _):
273277
self?.view.animators.removeValue(forKey: animationType)
274-
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
278+
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
275279
default:
276280
break
277281
}
@@ -386,11 +390,12 @@ extension ViewAnimator {
386390
strongSelf.view.transform = transform
387391
}
388392

393+
let groupUUID = animation.groupUUID
389394
animation.completion = { [weak self] event in
390395
switch event {
391396
case .finished:
392397
self?.view.animators.removeValue(forKey: animationType)
393-
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
398+
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
394399
default:
395400
break
396401
}
@@ -437,11 +442,12 @@ extension ViewAnimator {
437442
strongSelf.view.transform = transform
438443
}
439444

445+
let groupUUID = animation.groupUUID
440446
animation.completion = { [weak self] event in
441447
switch event {
442448
case .finished:
443449
self?.view.animators.removeValue(forKey: animationType)
444-
AnimationController.shared.executeHandler(uuid: animation.groupUUID, finished: true, retargeted: false)
450+
AnimationController.shared.executeHandler(uuid: groupUUID, finished: true, retargeted: false)
445451
default:
446452
break
447453
}

0 commit comments

Comments
 (0)