fixes for the banner
This commit is contained in:
parent
d7f955c991
commit
4a194d4e6f
@ -7,13 +7,15 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
@objcMembers public class HeadLineBodyCaretLinkImage: View {
|
@objcMembers public class HeadLineBodyCaretLinkImage: Container {
|
||||||
|
|
||||||
let headlineBody = HeadlineBody(frame: .zero)
|
let headlineBody = HeadlineBody(frame: .zero)
|
||||||
let caretButton = CaretButton(frame: .zero)
|
let caretButton = CaretButton(frame: .zero)
|
||||||
let backgroundImageView = MFLoadImageView()
|
let backgroundImageView = MFLoadImageView(pinnedEdges: .all)
|
||||||
var spaceBetweenConstant: CGFloat = 104.0
|
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
|
// MARK: - MVMCoreViewProtocol
|
||||||
open override func updateView(_ size: CGFloat) {
|
open override func updateView(_ size: CGFloat) {
|
||||||
super.updateView(size)
|
super.updateView(size)
|
||||||
@ -29,25 +31,28 @@ import Foundation
|
|||||||
guard subviews.count == 0 else {
|
guard subviews.count == 0 else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let view = MVMCoreUICommonViewsUtility.commonView()
|
heightConstraint = heightAnchor.constraint(equalToConstant: Self.heightConstant)
|
||||||
addSubview(view)
|
heightConstraint?.isActive = true
|
||||||
NSLayoutConstraint.constraintPinSubview(toSuperview: view)
|
|
||||||
view.addSubview(headlineBody)
|
let container = MVMCoreUICommonViewsUtility.commonView()
|
||||||
view.addSubview(caretButton)
|
addAndContain(container)
|
||||||
|
|
||||||
|
container.addSubview(headlineBody)
|
||||||
|
container.addSubview(caretButton)
|
||||||
|
|
||||||
//Headline view
|
//Headline view
|
||||||
headlineBody.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
|
headlineBody.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 0).isActive = true
|
||||||
headlineBody.topAnchor.constraint(equalTo: view.topAnchor, constant: PaddingDefault).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.priority = .defaultHigh
|
||||||
headLineBodyWidth.isActive = true
|
headLineBodyWidth.isActive = true
|
||||||
headlineBody.widthAnchor.constraint(lessThanOrEqualToConstant: maxWidth).isActive = true
|
headlineBody.widthAnchor.constraint(lessThanOrEqualToConstant: maxWidth).isActive = true
|
||||||
|
|
||||||
//Caret view
|
//Caret view
|
||||||
caretButton.translatesAutoresizingMaskIntoConstraints = false
|
caretButton.translatesAutoresizingMaskIntoConstraints = false
|
||||||
caretButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
|
caretButton.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 0).isActive = true
|
||||||
view.bottomAnchor.constraint(equalTo: caretButton.bottomAnchor, constant: PaddingDefault).isActive = true
|
container.bottomAnchor.constraint(equalTo: caretButton.bottomAnchor, constant: 0).isActive = true
|
||||||
|
|
||||||
caretButton.topAnchor.constraint(greaterThanOrEqualTo: headlineBody.bottomAnchor, constant: spaceBetweenConstant).isActive = true
|
caretButton.topAnchor.constraint(greaterThanOrEqualTo: headlineBody.bottomAnchor, constant: spaceBetweenConstant).isActive = true
|
||||||
|
|
||||||
@ -56,9 +61,9 @@ import Foundation
|
|||||||
backgroundImageView.imageView.contentMode = .scaleAspectFill
|
backgroundImageView.imageView.contentMode = .scaleAspectFill
|
||||||
backgroundImageView.alignFillHorizontal()
|
backgroundImageView.alignFillHorizontal()
|
||||||
backgroundImageView.alignFillVertical()
|
backgroundImageView.alignFillVertical()
|
||||||
view.addSubview(backgroundImageView)
|
addSubview(backgroundImageView)
|
||||||
NSLayoutConstraint.constraintPinSubview(toSuperview: backgroundImageView)
|
NSLayoutConstraint.constraintPinSubview(toSuperview: backgroundImageView)
|
||||||
view.sendSubviewToBack(backgroundImageView)
|
sendSubviewToBack(backgroundImageView)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||||
|
|||||||
@ -8,10 +8,64 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public class HeadlineBodyCaretLinkImageModel: MoleculeModelProtocol {
|
public class HeadlineBodyCaretLinkImageModel: ContainerModel, MoleculeModelProtocol {
|
||||||
public static var identifier: String = "headlineBodyCaretLinkImage"
|
public static var identifier: String = "headlineBodyCaretLinkImage"
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var caretLink: CaretLinkModel?
|
public var caretLink: CaretLinkModel?
|
||||||
public var headlineBody: HeadlineBodyModel
|
public var headlineBody: HeadlineBodyModel
|
||||||
public var image: ImageViewModel
|
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