187 lines
7.5 KiB
Swift
187 lines
7.5 KiB
Swift
//
|
|
// ActionDetailWithImage.swift
|
|
// MVMCoreUI
|
|
//
|
|
// Created by Christiano, Kevin on 6/20/19.
|
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
|
|
@objcMembers open class ActionDetailWithImage: ViewConstrainingView {
|
|
//------------------------------------------------------
|
|
// MARK: - Outlets
|
|
//------------------------------------------------------
|
|
|
|
let title = Label.commonLabelH3(true)
|
|
let message = Label.commonLabelB3(true)
|
|
let button = PrimaryButton.primaryTinyButton(false)!
|
|
let imageLoader = MFLoadImageView(pinnedEdges: .all)
|
|
let leftContainer = ViewConstrainingView.empty()
|
|
|
|
//------------------------------------------------------
|
|
// MARK: - Properties
|
|
//------------------------------------------------------
|
|
|
|
var bottomTitlePadding: CGFloat = PaddingOne
|
|
|
|
//------------------------------------------------------
|
|
// MARK: - Constraints
|
|
//------------------------------------------------------
|
|
|
|
var imageLeadingConstraint: NSLayoutConstraint?
|
|
var buttonTopConstraint: NSLayoutConstraint?
|
|
var messageTopConstraint: NSLayoutConstraint?
|
|
|
|
//------------------------------------------------------
|
|
// MARK: - Initialization
|
|
//------------------------------------------------------
|
|
|
|
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(json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
|
self.init()
|
|
setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// MARK: - View Lifecycle
|
|
//------------------------------------------------------
|
|
|
|
override open func setupView() {
|
|
super.setupView()
|
|
|
|
guard subviews.isEmpty else { return }
|
|
|
|
setDefaultState()
|
|
|
|
addSubview(leftContainer)
|
|
addSubview(imageLoader)
|
|
leftContainer.addSubview(title)
|
|
leftContainer.addSubview(message)
|
|
leftContainer.addSubview(button)
|
|
|
|
leftContainer.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
|
|
leftContainer.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true
|
|
|
|
layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: leftContainer.bottomAnchor).isActive = true
|
|
let leftContainerBottom = leftContainer.bottomAnchor.constraint(equalTo: bottomAnchor)
|
|
leftContainerBottom.priority = UILayoutPriority(249)
|
|
leftContainerBottom.isActive = true
|
|
|
|
title.topAnchor.constraint(equalTo: leftContainer.topAnchor).isActive = true
|
|
title.leadingAnchor.constraint(equalTo: leftContainer.leadingAnchor).isActive = true
|
|
leftContainer.trailingAnchor.constraint(equalTo: title.trailingAnchor).isActive = true
|
|
|
|
messageTopConstraint = message.topAnchor.constraint(equalTo: title.bottomAnchor, constant: PaddingOne)
|
|
messageTopConstraint?.isActive = true
|
|
|
|
message.leadingAnchor.constraint(equalTo: leftContainer.leadingAnchor).isActive = true
|
|
leftContainer.trailingAnchor.constraint(equalTo: message.trailingAnchor).isActive = true
|
|
|
|
buttonTopConstraint = button.topAnchor.constraint(equalTo: message.bottomAnchor, constant: PaddingTwo)
|
|
buttonTopConstraint?.isActive = true
|
|
|
|
button.leadingAnchor.constraint(equalTo: leftContainer.leadingAnchor).isActive = true
|
|
leftContainer.bottomAnchor.constraint(equalTo: button.bottomAnchor).isActive = true
|
|
leftContainer.trailingAnchor.constraint(greaterThanOrEqualTo: button.trailingAnchor).isActive = true
|
|
|
|
imageLoader.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
|
|
layoutMarginsGuide.trailingAnchor.constraint(equalTo: imageLoader.trailingAnchor).isActive = true
|
|
imageLeadingConstraint = imageLoader.leadingAnchor.constraint(greaterThanOrEqualTo: leftContainer.trailingAnchor, constant: 16)
|
|
imageLeadingConstraint?.isActive = true
|
|
imageLoader.topAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.topAnchor).isActive = true
|
|
|
|
layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: imageLoader.bottomAnchor).isActive = true
|
|
let imageloaderBottom = imageLoader.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor)
|
|
imageloaderBottom.priority = UILayoutPriority(249)
|
|
imageloaderBottom.isActive = true
|
|
}
|
|
|
|
override open func updateView(_ size: CGFloat) {
|
|
super.updateView(size)
|
|
|
|
title.updateView(size)
|
|
message.updateView(size)
|
|
button.updateView(size)
|
|
imageLoader.updateView(size)
|
|
leftContainer.updateView(size)
|
|
|
|
|
|
messageTopConstraint?.constant = title.hasText && message.hasText ? bottomTitlePadding : 0
|
|
buttonTopConstraint?.constant = message.hasText || title.hasText ? PaddingTwo : 0
|
|
}
|
|
|
|
public override static func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
|
return 197
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// MARK: - Methods
|
|
//------------------------------------------------------
|
|
|
|
private func setDefaultState() {
|
|
|
|
title.font = MFStyler.fontH3()
|
|
message.font = MFStyler.fontB3()
|
|
button.setAsSecondaryCustom()
|
|
button.isHidden = false
|
|
imageLoader.imageView.contentMode = .scaleAspectFit
|
|
imageLoader.addSizeConstraintsForAspectRatio = true
|
|
bottomTitlePadding = PaddingOne
|
|
}
|
|
|
|
override open func reset() {
|
|
super.reset()
|
|
|
|
title.reset()
|
|
message.reset()
|
|
button.reset()
|
|
imageLeadingConstraint?.constant = 16
|
|
imageLoader.reset()
|
|
|
|
setDefaultState()
|
|
}
|
|
|
|
open override func setAsMolecule() {
|
|
super.setAsMolecule()
|
|
|
|
title.setAsMolecule()
|
|
message.setAsMolecule()
|
|
button.setAsMolecule()
|
|
imageLoader.setAsMolecule()
|
|
|
|
setDefaultState()
|
|
}
|
|
|
|
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
|
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
|
|
|
guard let dictionary = json else { return }
|
|
|
|
if let padding = dictionary.optionalCGFloatForKey("bottomTitlePadding") {
|
|
bottomTitlePadding = padding
|
|
}
|
|
|
|
title.setWithJSON(dictionary.optionalDictionaryForKey("title"), delegateObject: delegateObject, additionalData: additionalData)
|
|
message.setWithJSON(dictionary.optionalDictionaryForKey("message"), delegateObject: delegateObject, additionalData: additionalData)
|
|
imageLoader.setWithJSON(dictionary.optionalDictionaryForKey("image"), delegateObject: delegateObject, additionalData: additionalData)
|
|
if let buttonDictionary = dictionary.optionalDictionaryForKey("button") {
|
|
button.setWithJSON(buttonDictionary, delegateObject: delegateObject, additionalData: additionalData)
|
|
} else {
|
|
button.isHidden = true
|
|
}
|
|
}
|
|
}
|