// // CollectionView.swift // VDS // // Created by Matt Bruce on 8/25/22. // import Foundation import UIKit import Combine open class CollectionView: UICollectionView, ModelHandlerable, ViewProtocol, Resettable { //-------------------------------------------------- // MARK: - Combine Properties //-------------------------------------------------- public var subject = PassthroughSubject() public var subscribers = Set() //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- private var initialSetupPerformed = false open var surface: Surface = .light { didSet { subject.send() }} open var disabled: Bool = false { didSet { isEnabled = !disabled } } open var isEnabled: Bool { get { !disabled } set { if disabled != !newValue { disabled = !newValue } isUserInteractionEnabled = isEnabled subject.send() } } //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- required public init() { super.init(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()) initialSetup() } public required init(collectionViewLayout layout: UICollectionViewLayout) { super.init(frame: .zero, collectionViewLayout: layout) initialSetup() } public override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) { super.init(frame: frame, collectionViewLayout: layout) initialSetup() } public required init?(coder: NSCoder) { super.init(coder: coder) initialSetup() } //-------------------------------------------------- // MARK: - Setup //-------------------------------------------------- open func initialSetup() { if !initialSetupPerformed { initialSetupPerformed = true setupUpdateView() setup() updateView() } } //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- open func updateView() { fatalError("Implement updateView") } open func reset() { backgroundColor = .clear surface = .light disabled = false } // MARK: - ViewProtocol /// Will be called only once. open func setup() { translatesAutoresizingMaskIntoConstraints = false insetsLayoutMarginsFromSafeArea = false } }