improvements made.

This commit is contained in:
Kevin G Christiano 2019-07-01 12:28:28 -04:00
parent d79dc3e8ab
commit b821250042

View File

@ -27,6 +27,7 @@ import UIKit
var imageWidthConstraint: NSLayoutConstraint?
var imageHeightConstraint: NSLayoutConstraint?
var buttonTopConstraint: NSLayoutConstraint?
var messageTopConstraint: NSLayoutConstraint?
//------------------------------------------------------
// MARK: - Initialization
@ -44,7 +45,7 @@ import UIKit
super.init(coder: aDecoder)
}
public convenience init(json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) {
public convenience init(json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
self.init()
setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
}
@ -79,12 +80,12 @@ import UIKit
title.topAnchor.constraint(equalTo: leftContainer.topAnchor).isActive = true
title.leadingAnchor.constraint(equalTo: leftContainer.leadingAnchor).isActive = true
title.trailingAnchor.constraint(equalTo: leftContainer.trailingAnchor).isActive = true
title.widthAnchor.constraint(equalTo: leftContainer.widthAnchor).isActive = true
message.topAnchor.constraint(equalTo: title.bottomAnchor, constant: PaddingOne).isActive = true
messageTopConstraint = message.topAnchor.constraint(equalTo: title.bottomAnchor, constant: PaddingOne)
messageTopConstraint?.isActive = true
message.leadingAnchor.constraint(equalTo: leftContainer.leadingAnchor).isActive = true
message.trailingAnchor.constraint(equalTo: leftContainer.trailingAnchor).isActive = true
message.widthAnchor.constraint(equalTo: leftContainer.widthAnchor).isActive = true
buttonTopConstraint = button.topAnchor.constraint(equalTo: message.bottomAnchor, constant: PaddingTwo)
buttonTopConstraint?.isActive = true
@ -96,10 +97,11 @@ import UIKit
imageloader.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
layoutMarginsGuide.trailingAnchor.constraint(equalTo: imageloader.trailingAnchor).isActive = true
imageloader.leadingAnchor.constraint(equalTo: leftContainer.trailingAnchor, constant: 16).isActive = true
imageloader.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true
imageHeightConstraint = imageloader.heightAnchor.constraint(equalToConstant: 0)
imageHeightConstraint?.isActive = true
imageWidthConstraint = imageloader.widthAnchor.constraint(equalToConstant: 0)
imageWidthConstraint?.isActive = true
@ -107,7 +109,7 @@ import UIKit
let imageloaderBottom = imageloader.bottomAnchor.constraint(equalTo: bottomAnchor)
imageloaderBottom.priority = UILayoutPriority(249)
imageloaderBottom.isActive = true
title.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 901), for: .horizontal)
message.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 902), for: .horizontal)
@ -124,7 +126,15 @@ import UIKit
imageloader.updateView(size)
leftContainer.updateView(size)
buttonTopConstraint?.constant = message.hasText ? PaddingTwo : PaddingOne
messageTopConstraint?.constant = title.hasText ? PaddingOne : 0
if message.hasText {
buttonTopConstraint?.constant = PaddingTwo
} else if title.hasText {
buttonTopConstraint?.constant = PaddingOne
} else {
buttonTopConstraint?.constant = 0
}
}
override open func reset() {
@ -137,31 +147,19 @@ import UIKit
backgroundColor = nil
}
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: DelegateObject?, additionalData: [AnyHashable: Any]?) {
super.setWithJSON(json, delegateObject: delegateObject as? MVMCoreUIDelegateObject, additionalData: additionalData)
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 }
title.setWithJSON(dictionary.optionalDictionaryForKey("title"), delegateObject: delegateObject as? MVMCoreUIDelegateObject, additionalData: additionalData)
message.setWithJSON(dictionary.optionalDictionaryForKey("message"), delegateObject: delegateObject as? MVMCoreUIDelegateObject, additionalData: additionalData)
button.setWithJSON(dictionary.optionalDictionaryForKey("button"), delegateObject: delegateObject as? MVMCoreUIDelegateObject, additionalData: additionalData)
imageloader.setWithJSON(dictionary.optionalDictionaryForKey("imageView"), delegateObject: delegateObject as? MVMCoreUIDelegateObject, additionalData: additionalData)
title.setWithJSON(dictionary.optionalDictionaryForKey("title"), delegateObject: delegateObject, additionalData: additionalData)
message.setWithJSON(dictionary.optionalDictionaryForKey("message"), delegateObject: delegateObject, additionalData: additionalData)
button.setWithJSON(dictionary.optionalDictionaryForKey("button"), delegateObject: delegateObject, additionalData: additionalData)
imageloader.setWithJSON(dictionary.optionalDictionaryForKey("image"), delegateObject: delegateObject, additionalData: additionalData)
if let imageJSON = dictionary.optionalDictionaryForKey("imageView") {
let width = CGFloat(imageJSON.floatForKey("width"))
let height = CGFloat(imageJSON.floatForKey("height"))
imageloader.loadImage(withName: imageJSON.optionalStringForKey("image"),
format: imageJSON.optionalStringForKey("imageFormat"),
width: width as NSNumber,
height: height as NSNumber)
imageWidthConstraint?.constant = width
imageHeightConstraint?.constant = height
}
if let backgroundColorHex = dictionary[KeyBackgroundColor] as? String {
backgroundColor = UIColor.mfGet(forHex: backgroundColorHex)
if let imageJSON = dictionary.optionalDictionaryForKey("image") {
imageWidthConstraint?.constant = CGFloat(imageJSON.floatForKey("width"))
imageHeightConstraint?.constant = CGFloat(imageJSON.floatForKey("height"))
}
}
}