Skip to content

Commit 450c49a

Browse files
committed
Add children property to CellViewModel
1 parent 44ade67 commit 450c49a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Sources/CellViewModel.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public protocol CellViewModel: DiffableViewModel, ViewRegistrationProvider {
3838
/// This corresponds to the delegate method `collectionView(_:contextMenuConfigurationForItemAt:point:)`.
3939
var contextMenuConfiguration: UIContextMenuConfiguration? { get }
4040

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+
4145
/// Configures the provided cell for display in the collection.
4246
/// - Parameter cell: The cell to configure.
4347
@MainActor
@@ -90,6 +94,9 @@ extension CellViewModel {
9094
/// Default implementation. Returns `true`.
9195
public var shouldHighlight: Bool { true }
9296

97+
/// Default implementation. Returns `[]`.
98+
public var children: [AnyCellViewModel] { [] }
99+
93100
/// Default implementation. Returns `nil`.
94101
public var contextMenuConfiguration: UIContextMenuConfiguration? { nil }
95102

@@ -198,6 +205,9 @@ public struct AnyCellViewModel: CellViewModel {
198205
/// :nodoc:
199206
public var shouldHighlight: Bool { self._shouldHighlight }
200207

208+
/// :nodoc:
209+
public var children: [AnyCellViewModel] { self._children }
210+
201211
/// :nodoc:
202212
public var contextMenuConfiguration: UIContextMenuConfiguration? { self._contextMenuConfiguration }
203213

@@ -251,6 +261,7 @@ public struct AnyCellViewModel: CellViewModel {
251261
private let _shouldDeselect: Bool
252262
private let _shouldHighlight: Bool
253263
private let _contextMenuConfiguration: UIContextMenuConfiguration?
264+
private let _children: [AnyCellViewModel]
254265
private let _configure: @Sendable @MainActor (CellType) -> Void
255266
private let _didSelect: @Sendable @MainActor (CellEventCoordinator?) -> Void
256267
private let _didDeselect: @Sendable @MainActor (CellEventCoordinator?) -> Void
@@ -276,6 +287,7 @@ public struct AnyCellViewModel: CellViewModel {
276287
self._shouldSelect = viewModel.shouldSelect
277288
self._shouldDeselect = viewModel.shouldDeselect
278289
self._shouldHighlight = viewModel.shouldHighlight
290+
self._children = viewModel.children
279291
self._contextMenuConfiguration = viewModel.contextMenuConfiguration
280292
self._configure = {
281293
viewModel._configureGeneric(cell: $0)

0 commit comments

Comments
 (0)