111 lines
4.4 KiB
Swift
111 lines
4.4 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: layoutMarginsGuide.leftAnchor)
|
|
leftConstraintTwoButton?.isActive = true
|
|
|
|
rightConstraintTwoButton = layoutMarginsGuide.rightAnchor.constraint(equalTo: twoButtonView.rightAnchor)
|
|
rightConstraintTwoButton?.isActive = true
|
|
|
|
leftConstraintTextButton = textButton.leftAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.leftAnchor)
|
|
leftConstraintTextButton?.isActive = true
|
|
|
|
rightConstraintTextButton = layoutMarginsGuide.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()
|
|
}
|
|
|
|
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
|
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
|
twoButtonView.setWithJSON(json?.optionalDictionaryForKey("twoButtonView"), delegateObject: delegateObject, additionalData: additionalData)
|
|
textButton.setWithJSON(json?.optionalDictionaryForKey("textButton"), delegateObject: delegateObject, additionalData: additionalData)
|
|
}
|
|
|
|
public override func reset() {
|
|
twoButtonView.reset()
|
|
textButton.reset()
|
|
}
|
|
|
|
public override static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
|
return 42
|
|
}
|
|
}
|