115 lines
4.6 KiB
Swift
115 lines
4.6 KiB
Swift
//
|
|
// StandardFooterView.swift
|
|
// MVMCoreUI
|
|
//
|
|
// Created by Scott Pfeil on 3/11/19.
|
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
public class StandardFooterView: ViewConstrainingView {
|
|
let twoButtonView = TwoButtonView(frame: .zero)
|
|
var textButton = MFTextButton(nil, constrainHeight: true, forWidth: MVMCoreUIUtility.getWidth())
|
|
var spaceBetweenButtons: NSLayoutConstraint?
|
|
var leftConstraintTwoButton: NSLayoutConstraint?
|
|
var rightConstraintTwoButton: NSLayoutConstraint?
|
|
var leftConstraintTextButton: NSLayoutConstraint?
|
|
var rightConstraintTextButton: NSLayoutConstraint?
|
|
var centerAlignTextButton: NSLayoutConstraint?
|
|
private var heightConstraint: NSLayoutConstraint?
|
|
|
|
public override func updateView(_ size: CGFloat) {
|
|
super.updateView(size)
|
|
twoButtonView.updateView(size)
|
|
textButton.updateView(size)
|
|
setSpacing()
|
|
}
|
|
|
|
public override func setupView() {
|
|
super.setupView()
|
|
guard subviews.count == 0 else {
|
|
return
|
|
}
|
|
translatesAutoresizingMaskIntoConstraints = false
|
|
backgroundColor = .clear
|
|
clipsToBounds = true
|
|
setContentHuggingPriority(UILayoutPriority.required, for: NSLayoutConstraint.Axis.vertical)
|
|
setContentCompressionResistancePriority(UILayoutPriority.required, for: NSLayoutConstraint.Axis.vertical)
|
|
|
|
addSubview(twoButtonView)
|
|
addSubview(textButton)
|
|
|
|
topPin = twoButtonView.topAnchor.constraint(equalTo: topAnchor, constant: PaddingDefaultVerticalSpacing)
|
|
topPin?.isActive = true
|
|
|
|
spaceBetweenButtons = textButton.topAnchor.constraint(equalTo: twoButtonView.bottomAnchor, constant: PaddingTwo)
|
|
spaceBetweenButtons?.isActive = true
|
|
|
|
leftConstraintTwoButton = twoButtonView.leftAnchor.constraint(equalTo: leftAnchor)
|
|
leftConstraintTwoButton?.isActive = true
|
|
|
|
rightConstraintTwoButton = rightAnchor.constraint(equalTo: twoButtonView.rightAnchor)
|
|
rightConstraintTwoButton?.isActive = true
|
|
|
|
leftConstraintTextButton = textButton.leftAnchor.constraint(greaterThanOrEqualTo: leftAnchor)
|
|
leftConstraintTextButton?.isActive = true
|
|
|
|
rightConstraintTextButton = rightAnchor.constraint(greaterThanOrEqualTo: textButton.rightAnchor)
|
|
rightConstraintTextButton?.isActive = true
|
|
|
|
centerAlignTextButton = textButton.centerXAnchor.constraint(equalTo: centerXAnchor)
|
|
centerAlignTextButton?.isActive = true
|
|
|
|
bottomPin = bottomAnchor.constraint(equalTo: textButton.bottomAnchor, constant: PaddingDefaultVerticalSpacing)
|
|
bottomPin?.isActive = true
|
|
|
|
heightConstraint = heightAnchor.constraint(equalToConstant: 0)
|
|
}
|
|
|
|
public func setSpacing() {
|
|
if !(twoButtonView.heightConstraint?.isActive ?? false) && textButton.title(for: UIControl.State.normal)?.count ?? 0 > 0 {
|
|
spaceBetweenButtons?.constant = PaddingTwo
|
|
show()
|
|
} else if !(twoButtonView.heightConstraint?.isActive ?? false) || textButton.title(for: UIControl.State.normal)?.count ?? 0 > 0 {
|
|
spaceBetweenButtons?.constant = 0
|
|
show()
|
|
} else {
|
|
hide()
|
|
}
|
|
}
|
|
|
|
public override func show() {
|
|
super.show()
|
|
heightConstraint?.isActive = false
|
|
topPin?.isActive = true
|
|
layoutIfNeeded()
|
|
}
|
|
|
|
public override func hide() {
|
|
super.hide()
|
|
heightConstraint?.isActive = true
|
|
topPin?.isActive = false
|
|
layoutIfNeeded()
|
|
}
|
|
|
|
public override func setLeftPinConstant(_ constant: CGFloat) {
|
|
leftConstraintTwoButton?.constant = constant
|
|
leftConstraintTextButton?.constant = constant
|
|
}
|
|
|
|
public override func setRightPinConstant(_ constant: CGFloat) {
|
|
rightConstraintTwoButton?.constant = constant
|
|
rightConstraintTextButton?.constant = constant
|
|
}
|
|
|
|
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) {
|
|
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
|
if let colorString = json?.optionalStringForKey(KeyBackgroundColor) {
|
|
backgroundColor = .mfGet(forHex: colorString)
|
|
}
|
|
twoButtonView.setWithJSON(json?.optionalDictionaryForKey("twoButtonView"), delegateObject: delegateObject, additionalData: additionalData)
|
|
textButton.setWithJSON(json?.optionalDictionaryForKey("textButton"), delegateObject: delegateObject, additionalData: additionalData)
|
|
}
|
|
}
|