refactored two link view
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
e1b6d82007
commit
83b2cb80ad
@ -7,77 +7,79 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import VDS
|
||||||
|
|
||||||
|
@objcMembers open class TwoLinkView: VDS.View, VDSMoleculeViewProtocol {
|
||||||
|
|
||||||
@objcMembers open class TwoLinkView: View, MVMCoreUIViewConstrainingProtocol {
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
open var viewModel: TwoLinkViewModel!
|
||||||
|
open var delegateObject: MVMCoreUIDelegateObject?
|
||||||
|
open var additionalData: [AnyHashable : Any]?
|
||||||
|
|
||||||
open var leftLink = Link()
|
open var leftLink = Link()
|
||||||
open var rightLink = Link()
|
open var rightLink = Link()
|
||||||
private var stack = UIStackView()
|
private var buttonGroup = VDS.ButtonGroup()
|
||||||
|
private var buttons: [Link] = []
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Lifecycle
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
open override func setup() {
|
||||||
|
super.setup()
|
||||||
|
isAccessibilityElement = false
|
||||||
|
addSubview(buttonGroup)
|
||||||
|
buttonGroup.pinToSuperView()
|
||||||
|
buttonGroup.alignment = .center
|
||||||
|
buttonGroup.rowQuantityPhone = 2
|
||||||
|
buttonGroup.rowQuantityTablet = 2
|
||||||
|
buttonGroup.childWidth = .percentage(50)
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - MVMCoreViewProtocol
|
// MARK: - MVMCoreViewProtocol
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
open override func reset() {
|
||||||
open override func updateView(_ size: CGFloat) {
|
super.reset()
|
||||||
super.updateView(size)
|
leftLink.reset()
|
||||||
stack.updateView(size)
|
rightLink.reset()
|
||||||
|
buttonGroup.reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func setupView() {
|
open func updateView(_ size: CGFloat) { }
|
||||||
super.setupView()
|
|
||||||
|
|
||||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
addSubview(stack)
|
|
||||||
stack.addArrangedSubview(leftLink)
|
|
||||||
stack.addArrangedSubview(rightLink)
|
|
||||||
NSLayoutConstraint.constraintPinSubview(toSuperview: stack)
|
|
||||||
stack.axis = .horizontal
|
|
||||||
stack.spacing = 8
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Stack Manipulation
|
// MARK: - Stack Manipulation
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public func showRightLink() {
|
public func showRightLink() {
|
||||||
if !stack.arrangedSubviews.contains(rightLink) {
|
if !buttons.contains(rightLink) {
|
||||||
stack.addArrangedSubview(rightLink)
|
buttons.insert(rightLink, at: buttons.count)
|
||||||
rightLink.isHidden = false
|
|
||||||
}
|
}
|
||||||
|
buttonGroup.buttons = buttons
|
||||||
}
|
}
|
||||||
|
|
||||||
public func showLeftLink() {
|
public func showLeftLink() {
|
||||||
if !stack.arrangedSubviews.contains(leftLink) {
|
if !buttons.contains(leftLink) {
|
||||||
stack.insertArrangedSubview(leftLink, at: 0)
|
buttons.insert(leftLink, at: 0)
|
||||||
leftLink.isHidden = false
|
|
||||||
}
|
}
|
||||||
|
buttonGroup.buttons = buttons
|
||||||
}
|
}
|
||||||
|
|
||||||
public func hideRightLink() {
|
public func hideRightLink() {
|
||||||
if rightLink.superview != nil {
|
if let index = buttons.firstIndex(of: rightLink) {
|
||||||
stack.removeArrangedSubview(rightLink)
|
buttons.remove(at: index)
|
||||||
rightLink.isHidden = true
|
|
||||||
}
|
}
|
||||||
|
buttonGroup.buttons = buttons
|
||||||
}
|
}
|
||||||
|
|
||||||
public func hideLeftLink() {
|
public func hideLeftLink() {
|
||||||
if leftLink.superview != nil {
|
if let index = buttons.firstIndex(of: leftLink) {
|
||||||
stack.removeArrangedSubview(leftLink)
|
buttons.remove(at: index)
|
||||||
leftLink.isHidden = true
|
|
||||||
}
|
}
|
||||||
}
|
buttonGroup.buttons = buttons
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - MoleculeViewProtocol
|
|
||||||
//--------------------------------------------------
|
|
||||||
|
|
||||||
open override func reset() {
|
|
||||||
super.reset()
|
|
||||||
stack.reset()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -92,27 +94,26 @@ import Foundation
|
|||||||
// MARK: - MoleculeViewProtocol
|
// MARK: - MoleculeViewProtocol
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
public static func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||||
return 16
|
guard let model = model as? TwoButtonViewModel,
|
||||||
|
let buttonModel = model.primaryButton ?? model.secondaryButton
|
||||||
|
else { return 0 }
|
||||||
|
|
||||||
|
return PillButton.estimatedHeight(with: buttonModel, delegateObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
public func viewModelDidUpdate() {
|
||||||
super.set(with: model, delegateObject, additionalData)
|
if let model = viewModel.leftLink {
|
||||||
|
|
||||||
guard let model = model as? TwoLinkViewModel else { return }
|
|
||||||
|
|
||||||
if let model = model.leftLink {
|
|
||||||
showLeftLink()
|
|
||||||
leftLink.set(with: model, delegateObject, additionalData)
|
leftLink.set(with: model, delegateObject, additionalData)
|
||||||
} else {
|
buttons.append(leftLink)
|
||||||
hideLeftLink()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let model = model.rightLink {
|
if let model = viewModel.rightLink {
|
||||||
showRightLink()
|
|
||||||
rightLink.set(with: model, delegateObject, additionalData)
|
rightLink.set(with: model, delegateObject, additionalData)
|
||||||
} else {
|
buttons.append(rightLink)
|
||||||
hideRightLink()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buttonGroup.buttons = buttons
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user