@@ -38,6 +38,10 @@ public protocol CellViewModel: DiffableViewModel, ViewRegistrationProvider {
38
38
/// This corresponds to the delegate method `collectionView(_:contextMenuConfigurationForItemAt:point:)`.
39
39
var contextMenuConfiguration : UIContextMenuConfiguration ? { get }
40
40
41
+ /// Returns an array of children for the cell.
42
+ /// These children correspond to the items that have been appended to this item as part of a `NSDiffableDataSourceSectionSnapshot`.
43
+ var children : [ AnyCellViewModel ] { get }
44
+
41
45
/// Configures the provided cell for display in the collection.
42
46
/// - Parameter cell: The cell to configure.
43
47
@MainActor
@@ -90,6 +94,9 @@ extension CellViewModel {
90
94
/// Default implementation. Returns `true`.
91
95
public var shouldHighlight : Bool { true }
92
96
97
+ /// Default implementation. Returns `[]`.
98
+ public var children : [ AnyCellViewModel ] { [ ] }
99
+
93
100
/// Default implementation. Returns `nil`.
94
101
public var contextMenuConfiguration : UIContextMenuConfiguration ? { nil }
95
102
@@ -198,6 +205,9 @@ public struct AnyCellViewModel: CellViewModel {
198
205
/// :nodoc:
199
206
public var shouldHighlight : Bool { self . _shouldHighlight }
200
207
208
+ /// :nodoc:
209
+ public var children : [ AnyCellViewModel ] { self . _children }
210
+
201
211
/// :nodoc:
202
212
public var contextMenuConfiguration : UIContextMenuConfiguration ? { self . _contextMenuConfiguration }
203
213
@@ -251,6 +261,7 @@ public struct AnyCellViewModel: CellViewModel {
251
261
private let _shouldDeselect : Bool
252
262
private let _shouldHighlight : Bool
253
263
private let _contextMenuConfiguration : UIContextMenuConfiguration ?
264
+ private let _children : [ AnyCellViewModel ]
254
265
private let _configure : @Sendable @MainActor ( CellType ) -> Void
255
266
private let _didSelect : @Sendable @MainActor ( CellEventCoordinator ? ) -> Void
256
267
private let _didDeselect : @Sendable @MainActor ( CellEventCoordinator ? ) -> Void
@@ -276,6 +287,7 @@ public struct AnyCellViewModel: CellViewModel {
276
287
self . _shouldSelect = viewModel. shouldSelect
277
288
self . _shouldDeselect = viewModel. shouldDeselect
278
289
self . _shouldHighlight = viewModel. shouldHighlight
290
+ self . _children = viewModel. children
279
291
self . _contextMenuConfiguration = viewModel. contextMenuConfiguration
280
292
self . _configure = {
281
293
viewModel. _configureGeneric ( cell: $0)
0 commit comments