From cfecae528b95f30e9ba4aca4d871c0bc5e5dbd3e Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 30 Aug 2022 14:35:16 -0500 Subject: [PATCH] updated cell Signed-off-by: Matt Bruce --- VDS/Classes/CollectionViewCell.swift | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/VDS/Classes/CollectionViewCell.swift b/VDS/Classes/CollectionViewCell.swift index 4f2eca85..bb2169ac 100644 --- a/VDS/Classes/CollectionViewCell.swift +++ b/VDS/Classes/CollectionViewCell.swift @@ -9,8 +9,8 @@ import Foundation import UIKit import Combine -open class CollectionViewCell: UICollectionViewCell, ModelHandlerable, ViewProtocol, Resettable { - +open class CollectionViewCell: UICollectionViewCell, ModelHandlerable, ViewProtocol, Resettable { + public typealias ModelType = ModelHandlerType.ModelType //-------------------------------------------------- // MARK: - Combine Properties //-------------------------------------------------- @@ -23,6 +23,8 @@ open class CollectionViewCell: UICollectionViewCell, Model //-------------------------------------------------- private var initialSetupPerformed = false + public var modelHandler: ModelHandlerType = ModelHandlerType() + @Proxy(\.model.surface) open var surface: Surface @@ -85,11 +87,11 @@ open class CollectionViewCell: UICollectionViewCell, Model // MARK: - Overrides //-------------------------------------------------- open func shouldUpdateView(viewModel: ModelType) -> Bool { - fatalError("Implement shouldUpdateView") + return modelHandler.shouldUpdateView(viewModel: viewModel) } open func updateView(viewModel: ModelType) { - fatalError("Implement updateView") + modelHandler.updateView(viewModel: viewModel) } open func reset() { @@ -99,10 +101,22 @@ open class CollectionViewCell: UICollectionViewCell, Model } } + public func set(with model: ModelType) { + self.model = model + modelHandler.set(with: model) + } + // MARK: - ViewProtocol /// Will be called only once. open func setup() { translatesAutoresizingMaskIntoConstraints = false insetsLayoutMarginsFromSafeArea = false + + addSubview(modelHandler) + + modelHandler.topAnchor.constraint(equalTo: topAnchor).isActive = true + modelHandler.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true + modelHandler.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true + modelHandler.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true } }