// // Control.swift // MVMCoreUI // // Created by Scott Pfeil on 10/23/19. // Copyright © 2019 Verizon Wireless. All rights reserved. // import UIKit @objcMembers open class Control: UIControl, MoleculeViewProtocol { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- open var model: MoleculeModelProtocol? private var initialSetupPerformed = false //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- public override init(frame: CGRect) { super.init(frame: .zero) initialSetup() } public init() { super.init(frame: .zero) initialSetup() } public required init?(coder: NSCoder) { super.init(coder: coder) fatalError("Control does not support xib.") } //-------------------------------------------------- // MARK: - Setup //-------------------------------------------------- public func initialSetup() { if !initialSetupPerformed { initialSetupPerformed = true setupView() } } // MARK:- MoleculeViewProtocol open func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { self.model = model if let backgroundColor = model.backgroundColor { self.backgroundColor = backgroundColor.uiColor } } open class func nameForReuse(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> String? { return model.moleculeName } open class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { return nil } open class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { return nil } open func reset() { backgroundColor = .clear } } // MARK: - AppleGuidelinesProtocol extension Control: AppleGuidelinesProtocol { override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool { return Self.acceptablyOutsideBounds(point: point, bounds: bounds) } } // MARK: - MVMCoreViewProtocol extension Control: MVMCoreViewProtocol { open func updateView(_ size: CGFloat) { } /// Will be called only once. open func setupView() { translatesAutoresizingMaskIntoConstraints = false insetsLayoutMarginsFromSafeArea = false } }