137 lines
5.2 KiB
Swift
137 lines
5.2 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 headlineBodyButton = HeadlineBodyButton(frame: .zero)
|
|
let imageLoader = MFLoadImageView(pinnedEdges: .all)
|
|
|
|
//------------------------------------------------------
|
|
// MARK: - Properties
|
|
//------------------------------------------------------
|
|
|
|
var buttonHeaderPadding: CGFloat = PaddingTwo
|
|
|
|
//------------------------------------------------------
|
|
// MARK: - Constraints
|
|
//------------------------------------------------------
|
|
|
|
var imageLeadingConstraint: 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(imageLoader)
|
|
addSubview(headlineBodyButton)
|
|
|
|
headlineBodyButton.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
|
|
headlineBodyButton.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true
|
|
|
|
layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: headlineBodyButton.bottomAnchor).isActive = true
|
|
let leftContainerBottom = headlineBodyButton.bottomAnchor.constraint(equalTo: bottomAnchor)
|
|
leftContainerBottom.priority = UILayoutPriority(249)
|
|
leftContainerBottom.isActive = true
|
|
|
|
imageLoader.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
|
|
layoutMarginsGuide.trailingAnchor.constraint(equalTo: imageLoader.trailingAnchor).isActive = true
|
|
imageLeadingConstraint = imageLoader.leadingAnchor.constraint(greaterThanOrEqualTo: headlineBodyButton.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)
|
|
|
|
headlineBodyButton.updateView(size)
|
|
imageLoader.updateView(size)
|
|
}
|
|
|
|
public override class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
|
return 197
|
|
}
|
|
|
|
//------------------------------------------------------
|
|
// MARK: - Methods
|
|
//------------------------------------------------------
|
|
|
|
private func setDefaultState() {
|
|
|
|
headlineBodyButton.headlineBody.headlineLabel.font = MFStyler.fontH3()
|
|
headlineBodyButton.headlineBody.messageLabel.font = MFStyler.fontB3()
|
|
imageLoader.imageView.contentMode = .scaleAspectFit
|
|
imageLoader.addSizeConstraintsForAspectRatio = true
|
|
buttonHeaderPadding = PaddingTwo
|
|
}
|
|
|
|
override open func reset() {
|
|
super.reset()
|
|
|
|
headlineBodyButton.reset()
|
|
imageLeadingConstraint?.constant = 16
|
|
imageLoader.reset()
|
|
setDefaultState()
|
|
}
|
|
|
|
open override func setAsMolecule() {
|
|
super.setAsMolecule()
|
|
|
|
headlineBodyButton.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 }
|
|
|
|
headlineBodyButton.setWithJSON(dictionary.optionalDictionaryForKey("headlineBodyButton"), delegateObject: delegateObject, additionalData: additionalData)
|
|
imageLoader.setWithJSON(dictionary.optionalDictionaryForKey("image"), delegateObject: delegateObject, additionalData: additionalData)
|
|
}
|
|
}
|