104 lines
3.2 KiB
Swift
104 lines
3.2 KiB
Swift
//
|
|
// 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, ModelMoleculeViewProtocol {
|
|
//--------------------------------------------------
|
|
// MARK: - Properties
|
|
//--------------------------------------------------
|
|
open var json: [AnyHashable: Any]?
|
|
public 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:- ModelMoleculeViewProtocol
|
|
open func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
|
self.model = model
|
|
if let backgroundColor = model?.backgroundColor {
|
|
self.backgroundColor = backgroundColor.uiColor
|
|
}
|
|
}
|
|
|
|
open class func nameForReuse(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
|
return model?.moleculeName
|
|
}
|
|
|
|
open class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
|
return nil
|
|
}
|
|
|
|
open class func requiredModules(_ molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// 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 {
|
|
|
|
public func updateView(_ size: CGFloat) {}
|
|
|
|
/// Will be called only once.
|
|
public func setupView() {
|
|
translatesAutoresizingMaskIntoConstraints = false
|
|
insetsLayoutMarginsFromSafeArea = false
|
|
}
|
|
}
|
|
|
|
// MARK: - MVMCoreUIMoleculeViewProtocol
|
|
extension Control: MVMCoreUIMoleculeViewProtocol {
|
|
open func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
|
self.json = json
|
|
|
|
if let backgroundColorString = json?.optionalStringForKey(KeyBackgroundColor) {
|
|
backgroundColor = UIColor.mfGet(forHex: backgroundColorString)
|
|
}
|
|
}
|
|
|
|
public func reset() {
|
|
backgroundColor = .clear
|
|
}
|
|
}
|