vds_ios/VDS/BaseClasses/View.swift
Matt Bruce a043bd33f2 added shouldUpdateAccessibility
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2024-06-05 16:15:35 -05:00

97 lines
2.5 KiB
Swift

//
// 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<AnyCancellable>()
//--------------------------------------------------
// 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()
}
}