92 lines
2.7 KiB
Swift
92 lines
2.7 KiB
Swift
//
|
|
// ImageView.swift
|
|
// MVMCoreUI
|
|
//
|
|
// Created by Kevin Christiano on 2/13/20.
|
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
open class ImageView: UIImageView, MoleculeViewProtocol {
|
|
//--------------------------------------------------
|
|
// MARK: - Properties
|
|
//--------------------------------------------------
|
|
|
|
open var model: MoleculeModelProtocol?
|
|
|
|
private var initialSetupPerformed = false
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Initialization
|
|
//--------------------------------------------------
|
|
|
|
public override init(frame: CGRect) {
|
|
super.init(frame: .zero)
|
|
initialSetup()
|
|
}
|
|
|
|
override init(image: UIImage?) {
|
|
super.init(image: image)
|
|
initialSetup()
|
|
}
|
|
|
|
public convenience init() {
|
|
self.init(frame: .zero)
|
|
}
|
|
|
|
public required init?(coder: NSCoder) {
|
|
super.init(coder: coder)
|
|
initialSetup()
|
|
}
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Lifecycle
|
|
//--------------------------------------------------
|
|
|
|
public func initialSetup() {
|
|
if !initialSetupPerformed {
|
|
initialSetupPerformed = true
|
|
setupView()
|
|
}
|
|
}
|
|
|
|
/// Will be called only once.
|
|
open func setupView() {
|
|
translatesAutoresizingMaskIntoConstraints = false
|
|
insetsLayoutMarginsFromSafeArea = false
|
|
MVMCoreUIUtility.setMarginsFor(self, leading: 0, top: 0, trailing: 0, bottom: 0)
|
|
}
|
|
|
|
open func reset() {
|
|
backgroundColor = .clear
|
|
}
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - MoleculeViewProtocol
|
|
//--------------------------------------------------
|
|
|
|
public 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(_ 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
|
|
}
|
|
|
|
open func updateView(_ size: CGFloat) { }
|
|
|
|
open func setAsMolecule() { }
|
|
}
|