Updated variable name. removed padding if image is not there.

This commit is contained in:
Kevin G Christiano 2019-07-09 13:53:49 -04:00
parent 55f20e0633
commit ae7d757dbc

View File

@ -17,7 +17,7 @@ import UIKit
let title = Label.commonLabelH3(true) let title = Label.commonLabelH3(true)
let message = Label.commonLabelB3(true) let message = Label.commonLabelB3(true)
let button = PrimaryButton.primaryTinyButton(false)! let button = PrimaryButton.primaryTinyButton(false)!
let imageloader = MFLoadImageView() let imageLoader = MFLoadImageView()
let leftContainer = ViewConstrainingView.empty() let leftContainer = ViewConstrainingView.empty()
//------------------------------------------------------ //------------------------------------------------------
@ -26,6 +26,7 @@ import UIKit
var imageWidthConstraint: NSLayoutConstraint? var imageWidthConstraint: NSLayoutConstraint?
var imageHeightConstraint: NSLayoutConstraint? var imageHeightConstraint: NSLayoutConstraint?
var imageLeadingConstraint: NSLayoutConstraint?
var buttonTopConstraint: NSLayoutConstraint? var buttonTopConstraint: NSLayoutConstraint?
var messageTopConstraint: NSLayoutConstraint? var messageTopConstraint: NSLayoutConstraint?
@ -60,11 +61,10 @@ import UIKit
guard subviews.isEmpty else { return } guard subviews.isEmpty else { return }
button.setAsSecondaryCustom() button.setAsSecondaryCustom()
imageLoader.imageView.contentMode = .scaleAspectFit
imageloader.imageView.contentMode = .scaleAspectFit
addSubview(leftContainer) addSubview(leftContainer)
addSubview(imageloader) addSubview(imageLoader)
leftContainer.addSubview(title) leftContainer.addSubview(title)
leftContainer.addSubview(message) leftContainer.addSubview(message)
leftContainer.addSubview(button) leftContainer.addSubview(button)
@ -94,19 +94,20 @@ import UIKit
button.bottomAnchor.constraint(equalTo: leftContainer.bottomAnchor).isActive = true button.bottomAnchor.constraint(equalTo: leftContainer.bottomAnchor).isActive = true
leftContainer.trailingAnchor.constraint(greaterThanOrEqualTo: button.trailingAnchor).isActive = true leftContainer.trailingAnchor.constraint(greaterThanOrEqualTo: button.trailingAnchor).isActive = true
imageloader.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true imageLoader.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
layoutMarginsGuide.trailingAnchor.constraint(equalTo: imageloader.trailingAnchor).isActive = true layoutMarginsGuide.trailingAnchor.constraint(equalTo: imageLoader.trailingAnchor).isActive = true
imageloader.leadingAnchor.constraint(equalTo: leftContainer.trailingAnchor, constant: 16).isActive = true imageLeadingConstraint = imageLoader.leadingAnchor.constraint(greaterThanOrEqualTo: leftContainer.trailingAnchor, constant: 16)
imageloader.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true imageLeadingConstraint?.isActive = true
imageLoader.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true
imageHeightConstraint = imageloader.heightAnchor.constraint(equalToConstant: 0) imageHeightConstraint = imageLoader.heightAnchor.constraint(equalToConstant: 0)
imageHeightConstraint?.isActive = true imageHeightConstraint?.isActive = true
imageWidthConstraint = imageloader.widthAnchor.constraint(equalToConstant: 0) imageWidthConstraint = imageLoader.widthAnchor.constraint(equalToConstant: 0)
imageWidthConstraint?.isActive = true imageWidthConstraint?.isActive = true
bottomAnchor.constraint(greaterThanOrEqualTo: imageloader.bottomAnchor).isActive = true bottomAnchor.constraint(greaterThanOrEqualTo: imageLoader.bottomAnchor).isActive = true
let imageloaderBottom = imageloader.bottomAnchor.constraint(equalTo: bottomAnchor) let imageloaderBottom = imageLoader.bottomAnchor.constraint(equalTo: bottomAnchor)
imageloaderBottom.priority = UILayoutPriority(249) imageloaderBottom.priority = UILayoutPriority(249)
imageloaderBottom.isActive = true imageloaderBottom.isActive = true
} }
@ -117,11 +118,15 @@ import UIKit
title.updateView(size) title.updateView(size)
message.updateView(size) message.updateView(size)
button.updateView(size) button.updateView(size)
imageloader.updateView(size) imageLoader.updateView(size)
leftContainer.updateView(size) leftContainer.updateView(size)
messageTopConstraint?.constant = title.hasText ? PaddingOne : 0 messageTopConstraint?.constant = title.hasText ? PaddingOne : 0
buttonTopConstraint?.constant = message.hasText ? PaddingTwo : (title.hasText ? PaddingOne : 0) buttonTopConstraint?.constant = message.hasText ? PaddingTwo : (title.hasText ? PaddingOne : 0)
if imageWidthConstraint?.constant == 0 {
imageLeadingConstraint?.constant = 0
}
} }
override open func reset() { override open func reset() {
@ -129,8 +134,9 @@ import UIKit
title.text = "" title.text = ""
message.text = "" message.text = ""
imageloader.imageView.image = nil imageLoader.imageView.image = nil
imageWidthConstraint?.constant = 0 imageWidthConstraint?.constant = 0
imageLeadingConstraint?.constant = 16
backgroundColor = nil backgroundColor = nil
} }
@ -142,7 +148,7 @@ import UIKit
title.setWithJSON(dictionary.optionalDictionaryForKey("title"), delegateObject: delegateObject, additionalData: additionalData) title.setWithJSON(dictionary.optionalDictionaryForKey("title"), delegateObject: delegateObject, additionalData: additionalData)
message.setWithJSON(dictionary.optionalDictionaryForKey("message"), delegateObject: delegateObject, additionalData: additionalData) message.setWithJSON(dictionary.optionalDictionaryForKey("message"), delegateObject: delegateObject, additionalData: additionalData)
button.setWithJSON(dictionary.optionalDictionaryForKey("button"), delegateObject: delegateObject, additionalData: additionalData) button.setWithJSON(dictionary.optionalDictionaryForKey("button"), delegateObject: delegateObject, additionalData: additionalData)
imageloader.setWithJSON(dictionary.optionalDictionaryForKey("image"), delegateObject: delegateObject, additionalData: additionalData) imageLoader.setWithJSON(dictionary.optionalDictionaryForKey("image"), delegateObject: delegateObject, additionalData: additionalData)
if let imageJSON = dictionary.optionalDictionaryForKey("image") { if let imageJSON = dictionary.optionalDictionaryForKey("image") {
imageWidthConstraint?.constant = CGFloat(imageJSON.floatForKey("width")) imageWidthConstraint?.constant = CGFloat(imageJSON.floatForKey("width"))