updated cell

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-08-30 14:35:16 -05:00
parent 6ce40e1a39
commit cfecae528b

View File

@ -9,8 +9,8 @@ import Foundation
import UIKit
import Combine
open class CollectionViewCell<ModelType: Modelable>: UICollectionViewCell, ModelHandlerable, ViewProtocol, Resettable {
open class CollectionViewCell<ModelHandlerType: ModelHandlerable & UIView>: UICollectionViewCell, ModelHandlerable, ViewProtocol, Resettable {
public typealias ModelType = ModelHandlerType.ModelType
//--------------------------------------------------
// MARK: - Combine Properties
//--------------------------------------------------
@ -23,6 +23,8 @@ open class CollectionViewCell<ModelType: Modelable>: 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<ModelType: Modelable>: 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<ModelType: Modelable>: 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
}
}