latest take on listitemwithimage.
This commit is contained in:
parent
ae7d757dbc
commit
9444df4d7c
@ -17,15 +17,13 @@ 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(pinnedEdges: .all)
|
||||||
let leftContainer = ViewConstrainingView.empty()
|
let leftContainer = ViewConstrainingView.empty()
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - Constraints
|
// MARK: - Constraints
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
var imageWidthConstraint: NSLayoutConstraint?
|
|
||||||
var imageHeightConstraint: NSLayoutConstraint?
|
|
||||||
var imageLeadingConstraint: NSLayoutConstraint?
|
var imageLeadingConstraint: NSLayoutConstraint?
|
||||||
var buttonTopConstraint: NSLayoutConstraint?
|
var buttonTopConstraint: NSLayoutConstraint?
|
||||||
var messageTopConstraint: NSLayoutConstraint?
|
var messageTopConstraint: NSLayoutConstraint?
|
||||||
@ -58,6 +56,8 @@ import UIKit
|
|||||||
override open func setupView() {
|
override open func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
|
|
||||||
|
imageLoader.addSizeConstraintsForAspectRatio = true
|
||||||
|
|
||||||
guard subviews.isEmpty else { return }
|
guard subviews.isEmpty else { return }
|
||||||
|
|
||||||
button.setAsSecondaryCustom()
|
button.setAsSecondaryCustom()
|
||||||
@ -96,16 +96,10 @@ import UIKit
|
|||||||
|
|
||||||
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
|
||||||
imageLeadingConstraint = imageLoader.leadingAnchor.constraint(greaterThanOrEqualTo: leftContainer.trailingAnchor, constant: 16)
|
imageLeadingConstraint = imageLoader.leadingAnchor.constraint(equalTo: leftContainer.trailingAnchor, constant: 16)
|
||||||
imageLeadingConstraint?.isActive = true
|
imageLeadingConstraint?.isActive = true
|
||||||
imageLoader.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).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
|
|
||||||
|
|
||||||
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)
|
||||||
@ -123,19 +117,18 @@ import UIKit
|
|||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------
|
||||||
|
// MARK: - Methods
|
||||||
|
//------------------------------------------------------
|
||||||
|
|
||||||
override open func reset() {
|
override open func reset() {
|
||||||
super.reset()
|
super.reset()
|
||||||
|
|
||||||
title.text = ""
|
title.text = ""
|
||||||
message.text = ""
|
message.text = ""
|
||||||
imageLoader.imageView.image = nil
|
imageLoader.imageView.image = nil
|
||||||
imageWidthConstraint?.constant = 0
|
|
||||||
imageLeadingConstraint?.constant = 16
|
imageLeadingConstraint?.constant = 16
|
||||||
backgroundColor = nil
|
backgroundColor = nil
|
||||||
}
|
}
|
||||||
@ -149,10 +142,5 @@ import UIKit
|
|||||||
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") {
|
|
||||||
imageWidthConstraint?.constant = CGFloat(imageJSON.floatForKey("width"))
|
|
||||||
imageHeightConstraint?.constant = CGFloat(imageJSON.floatForKey("height"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user