// // Control.swift // VDS // // Created by Matt Bruce on 7/22/22. // import Foundation import UIKit import Combine /// Base Class used to build Views. @objc(VDSView) open class View: UIView, ViewProtocol, UserInfoable { //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- required public init() { super.init(frame: .zero) initialSetup() } public override init(frame: CGRect) { super.init(frame: .zero) initialSetup() } public required init?(coder: NSCoder) { super.init(coder: coder) initialSetup() } //-------------------------------------------------- // MARK: - Combine Properties //-------------------------------------------------- open var subscribers = Set() //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- private var initialSetupPerformed = false //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- open var shouldUpdateView: Bool = true open var shouldUpdateAccessibility: Bool = true /// Dictionary for keeping information for this Control use only Primitives. open var userInfo = [String: Primitive]() open var surface: Surface = .light { didSet { setNeedsUpdate() } } open var isEnabled: Bool = true { didSet { setNeedsUpdate() } } //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- open func initialSetup() { if !initialSetupPerformed { initialSetupPerformed = true setup() setNeedsUpdate() } } open func setup() { backgroundColor = .clear translatesAutoresizingMaskIntoConstraints = false insetsLayoutMarginsFromSafeArea = false } open func updateView() { } open func updateAccessibility() { if isEnabled { accessibilityTraits.remove(.notEnabled) } else { accessibilityTraits.insert(.notEnabled) } } open func reset() { backgroundColor = .clear surface = .light isEnabled = true } open override func layoutSubviews() { super.layoutSubviews() setNeedsUpdate() } }