Skip to content

Commit 2715a3c

Browse files
Revert "Fix CollectionViewLayout delegate lifetime" (#612)
Reverts #611 Which was accidentally automerged
2 parents c3245d3 + 790d5b3 commit 2715a3c

4 files changed

Lines changed: 16 additions & 83 deletions

File tree

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
### Fixed
44

5-
- Fixed a crash in `CollectionViewLayout` when the delegate was deallocated before the layout. The delegate is now held weakly rather than unowned.
6-
75
### Added
86

97
### Removed

ListableUI/Sources/Layout/CollectionViewLayout.swift

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class CollectionViewLayout : UICollectionViewLayout
1414
// MARK: Properties
1515
//
1616

17-
private(set) weak var delegate : CollectionViewLayoutDelegate?
17+
unowned let delegate : CollectionViewLayoutDelegate
1818

1919
var layoutDescription : LayoutDescription
2020

@@ -221,10 +221,8 @@ final class CollectionViewLayout : UICollectionViewLayout
221221
/// processing any further updates 🥴.
222222
///
223223

224-
let delegate = self.delegate
225-
226-
OperationQueue.main.addOperation { [weak delegate] in
227-
delegate?.listViewShouldEndQueueingEditsForReorder()
224+
OperationQueue.main.addOperation {
225+
self.delegate.listViewShouldEndQueueingEditsForReorder()
228226
}
229227
}
230228

@@ -392,10 +390,6 @@ final class CollectionViewLayout : UICollectionViewLayout
392390

393391
self.changesDuringCurrentUpdate = UpdateItems(with: [])
394392

395-
guard let delegate = self.delegate else {
396-
return
397-
}
398-
399393
let size = self.collectionView?.bounds.size ?? .zero
400394

401395
self.neededLayoutType.update(with: {
@@ -408,18 +402,18 @@ final class CollectionViewLayout : UICollectionViewLayout
408402
case .none:
409403
return true
410404
case .relayout:
411-
self.performLayout(delegate: delegate)
405+
self.performLayout()
412406
case .rebuild:
413-
self.performRebuild(andLayout: shouldLayout, delegate: delegate)
407+
self.performRebuild(andLayout: shouldLayout)
414408
}
415409

416410
return true
417411
}())
418412

419-
self.performLayoutUpdate(delegate: delegate)
413+
self.performLayoutUpdate()
420414

421415
if self.isReordering == false {
422-
delegate.listViewLayoutDidLayoutContents()
416+
self.delegate.listViewLayoutDidLayoutContents()
423417
}
424418
}
425419

@@ -445,15 +439,15 @@ final class CollectionViewLayout : UICollectionViewLayout
445439
// MARK: Performing Layouts
446440
//
447441

448-
private func performRebuild(andLayout layout : Bool, delegate : CollectionViewLayoutDelegate)
442+
private func performRebuild(andLayout layout : Bool)
449443
{
450444
self.previousLayout = self.layout
451445

452446
self.layout = self.layoutDescription.configuration.createPopulatedLayout(
453447
appearance: self.appearance,
454448
behavior: self.behavior,
455449
content: {
456-
delegate.listLayoutContent(defaults: $0)
450+
self.delegate.listLayoutContent(defaults: $0)
457451
}
458452
)
459453

@@ -465,34 +459,34 @@ final class CollectionViewLayout : UICollectionViewLayout
465459
)
466460

467461
if layout {
468-
self.performLayout(delegate: delegate)
462+
self.performLayout()
469463
}
470464
}
471465

472-
private func performLayout(delegate : CollectionViewLayoutDelegate)
466+
private func performLayout()
473467
{
474468
let view = self.collectionView!
475469

476470
let context = ListLayoutLayoutContext(
477471
collectionView: view,
478-
environment: delegate.listViewLayoutCurrentEnvironment()
472+
environment: self.delegate.listViewLayoutCurrentEnvironment()
479473
)
480474

481475
self.layout.performLayout(
482-
with: delegate,
476+
with: self.delegate,
483477
in: context
484478
)
485479

486480
self.viewProperties = CollectionViewLayoutProperties(collectionView: view)
487481
}
488482

489-
private func performLayoutUpdate(delegate : CollectionViewLayoutDelegate)
483+
private func performLayoutUpdate()
490484
{
491485
let view = self.collectionView!
492486

493487
let context = ListLayoutLayoutContext(
494488
collectionView: view,
495-
environment: delegate.listViewLayoutCurrentEnvironment()
489+
environment: self.delegate.listViewLayoutCurrentEnvironment()
496490
)
497491

498492
self.layout.positionStickyListHeaderIfNeeded(in: context)

ListableUI/Sources/ListView/ListView.LayoutManager.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,8 @@ extension ListView
4545
self.collectionViewLayout.setNeedsRebuild(animated: animated)
4646
}
4747
} else {
48-
guard let delegate = self.collectionViewLayout.delegate else {
49-
listableInternalFatal("Cannot swap layout when the previous layout's delegate has been deallocated.")
50-
}
51-
5248
self.collectionViewLayout = CollectionViewLayout(
53-
delegate: delegate,
49+
delegate: self.collectionViewLayout.delegate,
5450
layoutDescription: layout,
5551
appearance: self.collectionViewLayout.appearance,
5652
behavior: self.collectionViewLayout.behavior

ListableUI/Tests/Layout/CollectionViewLayoutTests.swift

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)