97 lines
2.8 KiB
Swift
97 lines
2.8 KiB
Swift
//
|
|
// 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<AnyCancellable>()
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Properties
|
|
//--------------------------------------------------
|
|
private var initialSetupPerformed = false
|
|
|
|
/// Key of whether or not updateView() is called in setNeedsUpdate()
|
|
open var shouldUpdateView: Bool = true
|
|
|
|
/// Dictionary for keeping information for this Control use only Primitives
|
|
open var userInfo = [String: Primitive]()
|
|
|
|
/// Current Surface used within this Control and used to passdown to child views
|
|
open var surface: Surface = .light { didSet { setNeedsUpdate() } }
|
|
|
|
/// Control is disabled or not
|
|
open var disabled: Bool = false { didSet { setNeedsUpdate(); isUserInteractionEnabled = !disabled } }
|
|
|
|
//--------------------------------------------------
|
|
// 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
|
|
//--------------------------------------------------
|
|
|
|
/// Executed on initialization for this View
|
|
open func initialSetup() {
|
|
if !initialSetupPerformed {
|
|
initialSetupPerformed = true
|
|
setup()
|
|
setNeedsUpdate()
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Overrides
|
|
//--------------------------------------------------
|
|
|
|
/// Update this view based off of property changes
|
|
open func updateView() {
|
|
updateAccessibilityLabel()
|
|
}
|
|
|
|
/// Used to update any Accessibility properties
|
|
open func updateAccessibilityLabel() {
|
|
|
|
}
|
|
|
|
/// Resets to the Views default values
|
|
open func reset() {
|
|
backgroundColor = .clear
|
|
surface = .light
|
|
disabled = false
|
|
}
|
|
|
|
/// Will be called only once and should be overridden in subclasses to setup UI or defaults
|
|
open func setup() {
|
|
backgroundColor = .clear
|
|
translatesAutoresizingMaskIntoConstraints = false
|
|
insetsLayoutMarginsFromSafeArea = false
|
|
}
|
|
}
|