Skip to content

Commit 11a306c

Browse files
authored
Add reusable cancellables (#20)
1 parent 6192d12 commit 11a306c

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

Package.resolved

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

Sources/DynamicList/VersatileCell.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ extension CellHighlightAnimation where Self == DisabledCellHighlightAnimation {
5353
}
5454
}
5555

56+
import Combine
57+
5658
open class VersatileCell: UICollectionViewCell {
5759

5860
open override var isHighlighted: Bool {
@@ -68,6 +70,9 @@ open class VersatileCell: UICollectionViewCell {
6870

6971
private var _highlightAnimation: any CellHighlightAnimation = .disabled
7072

73+
/// In prepareForReuse this is going to be a new instance.
74+
public private(set) var reusableCancellables: Set<AnyCancellable> = .init()
75+
7176
public override init(
7277
frame: CGRect
7378
) {
@@ -91,6 +96,12 @@ open class VersatileCell: UICollectionViewCell {
9196
}
9297
}
9398

99+
open override func prepareForReuse() {
100+
super.prepareForReuse()
101+
102+
reusableCancellables = .init()
103+
}
104+
94105
open override var configurationState: UICellConfigurationState {
95106
let state = super.configurationState
96107
return state

0 commit comments

Comments
 (0)