fixes for the banner
This commit is contained in:
parent
d7f955c991
commit
4a194d4e6f
@ -7,13 +7,15 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
@objcMembers public class HeadLineBodyCaretLinkImage: View {
|
||||
|
||||
@objcMembers public class HeadLineBodyCaretLinkImage: Container {
|
||||
let headlineBody = HeadlineBody(frame: .zero)
|
||||
let caretButton = CaretButton(frame: .zero)
|
||||
let backgroundImageView = MFLoadImageView()
|
||||
let backgroundImageView = MFLoadImageView(pinnedEdges: .all)
|
||||
var spaceBetweenConstant: CGFloat = 104.0
|
||||
let maxWidth : CGFloat = 350.0
|
||||
let maxWidth: CGFloat = 350.0
|
||||
static let heightConstant: CGFloat = 320.0
|
||||
var heightConstraint: NSLayoutConstraint?
|
||||
|
||||
// MARK: - MVMCoreViewProtocol
|
||||
open override func updateView(_ size: CGFloat) {
|
||||
super.updateView(size)
|
||||
@ -29,25 +31,28 @@ import Foundation
|
||||
guard subviews.count == 0 else {
|
||||
return
|
||||
}
|
||||
let view = MVMCoreUICommonViewsUtility.commonView()
|
||||
addSubview(view)
|
||||
NSLayoutConstraint.constraintPinSubview(toSuperview: view)
|
||||
view.addSubview(headlineBody)
|
||||
view.addSubview(caretButton)
|
||||
heightConstraint = heightAnchor.constraint(equalToConstant: Self.heightConstant)
|
||||
heightConstraint?.isActive = true
|
||||
|
||||
let container = MVMCoreUICommonViewsUtility.commonView()
|
||||
addAndContain(container)
|
||||
|
||||
container.addSubview(headlineBody)
|
||||
container.addSubview(caretButton)
|
||||
|
||||
//Headline view
|
||||
headlineBody.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
|
||||
headlineBody.topAnchor.constraint(equalTo: view.topAnchor, constant: PaddingDefault).isActive = true
|
||||
headlineBody.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 0).isActive = true
|
||||
headlineBody.topAnchor.constraint(equalTo: container.topAnchor, constant: 0).isActive = true
|
||||
|
||||
let headLineBodyWidth = headlineBody.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.85)
|
||||
let headLineBodyWidth = headlineBody.widthAnchor.constraint(equalTo: container.widthAnchor, multiplier: 0.85)
|
||||
headLineBodyWidth.priority = .defaultHigh
|
||||
headLineBodyWidth.isActive = true
|
||||
headlineBody.widthAnchor.constraint(lessThanOrEqualToConstant: maxWidth).isActive = true
|
||||
|
||||
//Caret view
|
||||
caretButton.translatesAutoresizingMaskIntoConstraints = false
|
||||
caretButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
|
||||
view.bottomAnchor.constraint(equalTo: caretButton.bottomAnchor, constant: PaddingDefault).isActive = true
|
||||
caretButton.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 0).isActive = true
|
||||
container.bottomAnchor.constraint(equalTo: caretButton.bottomAnchor, constant: 0).isActive = true
|
||||
|
||||
caretButton.topAnchor.constraint(greaterThanOrEqualTo: headlineBody.bottomAnchor, constant: spaceBetweenConstant).isActive = true
|
||||
|
||||
@ -56,9 +61,9 @@ import Foundation
|
||||
backgroundImageView.imageView.contentMode = .scaleAspectFill
|
||||
backgroundImageView.alignFillHorizontal()
|
||||
backgroundImageView.alignFillVertical()
|
||||
view.addSubview(backgroundImageView)
|
||||
addSubview(backgroundImageView)
|
||||
NSLayoutConstraint.constraintPinSubview(toSuperview: backgroundImageView)
|
||||
view.sendSubviewToBack(backgroundImageView)
|
||||
sendSubviewToBack(backgroundImageView)
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||
|
||||
@ -8,10 +8,64 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
public class HeadlineBodyCaretLinkImageModel: MoleculeModelProtocol {
|
||||
public class HeadlineBodyCaretLinkImageModel: ContainerModel, MoleculeModelProtocol {
|
||||
public static var identifier: String = "headlineBodyCaretLinkImage"
|
||||
public var backgroundColor: Color?
|
||||
public var caretLink: CaretLinkModel?
|
||||
public var headlineBody: HeadlineBodyModel
|
||||
public var image: ImageViewModel
|
||||
|
||||
init(headlineBody: HeadlineBodyModel, image: ImageViewModel) {
|
||||
self.headlineBody = headlineBody
|
||||
self.image = image
|
||||
super.init()
|
||||
setDefaults()
|
||||
}
|
||||
|
||||
/// Defaults to set
|
||||
func setDefaults() {
|
||||
if useHorizontalMargins == nil {
|
||||
useHorizontalMargins = true
|
||||
}
|
||||
if useVerticalMargins == nil {
|
||||
useVerticalMargins = true
|
||||
}
|
||||
if topMarginPadding == nil {
|
||||
topMarginPadding = PaddingDefault
|
||||
}
|
||||
if bottomMarginPadding == nil {
|
||||
bottomMarginPadding = PaddingDefault
|
||||
}
|
||||
if image.height == nil {
|
||||
image.height = HeadLineBodyCaretLinkImage.heightConstant
|
||||
}
|
||||
}
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case moleculeName
|
||||
case backgroundColor
|
||||
case headlineBody
|
||||
case image
|
||||
case caretLink
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
headlineBody = try typeContainer.decode(HeadlineBodyModel.self, forKey: .headlineBody)
|
||||
image = try typeContainer.decode(ImageViewModel.self, forKey: .image)
|
||||
caretLink = try typeContainer.decodeIfPresent(CaretLinkModel.self, forKey: .caretLink)
|
||||
try super.init(from: decoder)
|
||||
setDefaults()
|
||||
}
|
||||
|
||||
public override func encode(to encoder: Encoder) throws {
|
||||
try super.encode(to: encoder)
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(HeadlineBodyCaretLinkImageModel.identifier, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
try container.encode(headlineBody, forKey: .headlineBody)
|
||||
try container.encode(image, forKey: .image)
|
||||
try container.encodeIfPresent(caretLink, forKey: .caretLink)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user