// // Control.swift // VDS // // Created by Matt Bruce on 7/22/22. // import Foundation import UIKit import Combine @objc(VDSView) open class View: UIView, Handlerable, ViewProtocol, Resettable, UserInfoable { //-------------------------------------------------- // MARK: - Combine Properties //-------------------------------------------------- public var subscribers = Set() //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- private var initialSetupPerformed = false open var shouldUpdateView: Bool = true open var userInfo = [String: Primitive]() open var surface: Surface = .light { didSet { setNeedsUpdate() }} open var disabled: Bool = false { didSet { isEnabled = !disabled } } open var isEnabled: Bool { get { !disabled } set { if disabled != !newValue { disabled = !newValue } isUserInteractionEnabled = isEnabled setNeedsUpdate() } } //-------------------------------------------------- // 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: - Setup //-------------------------------------------------- open func initialSetup() { if !initialSetupPerformed { initialSetupPerformed = true setup() setNeedsUpdate() } } //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- open func updateView() { updateAccessibilityLabel() } open func updateAccessibilityLabel() { } open func reset() { backgroundColor = .clear surface = .light disabled = false } // MARK: - ViewProtocol /// Will be called only once. open func setup() { backgroundColor = .clear translatesAutoresizingMaskIntoConstraints = false insetsLayoutMarginsFromSafeArea = false } }