94 lines
2.7 KiB
Swift
94 lines
2.7 KiB
Swift
//
|
|
// ButtonView.swift
|
|
// MVMCoreUI
|
|
//
|
|
// Created by Scott Pfeil on 3/21/19.
|
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
@objcMembers open class ButtonView: ViewConstrainingView {
|
|
open var primaryButton: PrimaryButton? = PrimaryButton.button()
|
|
|
|
// MARK: - Inits
|
|
public init() {
|
|
super.init(frame: .zero)
|
|
}
|
|
|
|
public override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
}
|
|
|
|
required public init?(coder aDecoder: NSCoder) {
|
|
super.init(coder: aDecoder)
|
|
}
|
|
|
|
public convenience init(buttonSmall small: Bool, enabled: Bool) {
|
|
self.init()
|
|
primaryButton?.setAsSmall(small)
|
|
primaryButton?.isEnabled = enabled
|
|
}
|
|
|
|
public init(withJSON json: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) {
|
|
super.init(frame: .zero)
|
|
setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
|
}
|
|
|
|
// MARK: - MVMCoreViewProtocol
|
|
open override func reset() {
|
|
primaryButton?.reset()
|
|
}
|
|
|
|
open override func updateView(_ size: CGFloat) {
|
|
super.updateView(size)
|
|
MVMCoreDispatchUtility.performBlock(onMainThread: {
|
|
self.primaryButton?.updateView(size)
|
|
})
|
|
}
|
|
|
|
open override func setupView() {
|
|
super.setupView()
|
|
setupButton()
|
|
alignCenterHorizontal()
|
|
}
|
|
|
|
// MARK: - MVMCoreUIMoleculeViewProtocol
|
|
open override func setAsMolecule() {
|
|
super.setAsMolecule()
|
|
primaryButton?.setAsMolecule()
|
|
}
|
|
|
|
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
|
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
|
primaryButton?.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
|
}
|
|
|
|
public override static func estimatedHeight(forRow json: [AnyHashable : Any]?) -> CGFloat {
|
|
return 42
|
|
}
|
|
|
|
// MARK: - Constraining
|
|
func setupButton() {
|
|
if let primaryButton = primaryButton, !subviews.contains(primaryButton) {
|
|
addSubview(primaryButton)
|
|
pinView(toSuperView: primaryButton)
|
|
}
|
|
}
|
|
|
|
open override func setLeftPinConstant(_ constant: CGFloat) {
|
|
super.setLeftPinConstant(constant)
|
|
alignCenterLeftPin?.constant = constant
|
|
}
|
|
|
|
open override func setRightPinConstant(_ constant: CGFloat) {
|
|
super.setRightPinConstant(constant)
|
|
alignCenterRightPin?.constant = constant
|
|
}
|
|
|
|
open override func resetConstraints() {
|
|
super.resetConstraints()
|
|
primaryButton?.isEnabled = false
|
|
}
|
|
}
|