mvm_core_ui/MVMCoreUI/BaseClasses/View.swift
Pfeil, Scott Robert e98a0ce76b update pr comments
2019-10-29 15:23:44 -04:00

62 lines
1.4 KiB
Swift

//
// View.swift
// MVMCoreUI
//
// Created by Scott Pfeil on 10/23/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
import UIKit
@objcMembers open class View: UIView {
open var json: [AnyHashable: Any]?
private var initialSetupPerformed = false
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)
initialSetup()
}
public func initialSetup() {
if !initialSetupPerformed {
initialSetupPerformed = true
setupView()
}
}
}
extension View: MVMCoreViewProtocol {
open func updateView(_ size: CGFloat) {}
/// Will be called only once.
open func setupView() {
translatesAutoresizingMaskIntoConstraints = false
insetsLayoutMarginsFromSafeArea = false
}
}
extension View: 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)
}
}
open func reset() {
backgroundColor = .clear
}
}