diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 49ac139e..3b64a728 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -407,6 +407,8 @@ DBC4391B224421A0001AB423 /* CaretLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391A224421A0001AB423 /* CaretLink.swift */; }; DBC4392122491730001AB423 /* LabelWithInternalButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391C2245232D001AB423 /* LabelWithInternalButton.swift */; }; DBEFFA04225A829700230692 /* Label.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB891E822253FA8500022516 /* Label.swift */; }; + EA5124FD243601600051A3A4 /* BGImageHeadlineBodyButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5124FC243601600051A3A4 /* BGImageHeadlineBodyButton.swift */; }; + EA5124FF2436018E0051A3A4 /* BGImageHeadlineBodyButtonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5124FE2436018E0051A3A4 /* BGImageHeadlineBodyButtonModel.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -813,6 +815,8 @@ DBC4391722442197001AB423 /* DashLine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DashLine.swift; sourceTree = ""; }; DBC4391A224421A0001AB423 /* CaretLink.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaretLink.swift; sourceTree = ""; }; DBC4391C2245232D001AB423 /* LabelWithInternalButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelWithInternalButton.swift; sourceTree = ""; }; + EA5124FC243601600051A3A4 /* BGImageHeadlineBodyButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BGImageHeadlineBodyButton.swift; sourceTree = ""; }; + EA5124FE2436018E0051A3A4 /* BGImageHeadlineBodyButtonModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BGImageHeadlineBodyButtonModel.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -1157,6 +1161,8 @@ C7192E7C23C301750050C2A0 /* HeadLineBodyCaretLinkImage.swift */, D2E2A99923D8D6B4000B42E6 /* HeadlineBodyButtonModel.swift */, 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */, + EA5124FE2436018E0051A3A4 /* BGImageHeadlineBodyButtonModel.swift */, + EA5124FC243601600051A3A4 /* BGImageHeadlineBodyButton.swift */, ); path = VerticalCombinationViews; sourceTree = ""; @@ -2032,6 +2038,7 @@ D29E28D823D21AB800ACEA85 /* StringAndMoleculeView.swift in Sources */, 01EB369023609801006832FA /* MoleculeListItemModel.swift in Sources */, D28A838323CCBD3F00DFE4FC /* CircleProgressModel.swift in Sources */, + EA5124FF2436018E0051A3A4 /* BGImageHeadlineBodyButtonModel.swift in Sources */, D268C70C2386DFFD007F2C1C /* MoleculeStackItemModel.swift in Sources */, DBEFFA04225A829700230692 /* Label.swift in Sources */, D2D6CD4022E78C1A00D701B8 /* Scroller.swift in Sources */, @@ -2224,6 +2231,7 @@ C6FA7D5223C77A4A00A3614A /* UnOrderedList.swift in Sources */, 01509D8F2327EC6F00EF99AA /* MoleculeTableViewCell.swift in Sources */, 0A6682A22434DB4F00AD3CA1 /* ListLeftVariableRadioButtonBodyText.swift in Sources */, + EA5124FD243601600051A3A4 /* BGImageHeadlineBodyButton.swift in Sources */, 0105618D224BBE7700E1557D /* FormValidator.swift in Sources */, 01509D912327ECE600EF99AA /* CornerLabels.swift in Sources */, D22D1F1B220341F60077CEC0 /* MVMCoreUICheckBox.m in Sources */, diff --git a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift index 438f652b..53f8fbcf 100644 --- a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift +++ b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift @@ -92,6 +92,7 @@ import Foundation MoleculeObjectMapping.shared()?.register(viewClass: EyebrowHeadlineBodyLink.self, viewModelClass: EyebrowHeadlineBodyLinkModel.self) MoleculeObjectMapping.shared()?.register(viewClass: HeadlineBodyLink.self, viewModelClass: HeadlineBodyLinkModel.self) MoleculeObjectMapping.shared()?.register(viewClass: HeadlineBodyButton.self, viewModelClass: HeadlineBodyButtonModel.self) + MoleculeObjectMapping.shared()?.register(viewClass: BGImageHeadlineBodyButton.self, viewModelClass: BGImageHeadlineBodyButtonModel.self) // Left Right Molecules MoleculeObjectMapping.shared()?.register(viewClass: CornerLabels.self, viewModelClass: CornerLabelsModel.self) diff --git a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/BGImageHeadlineBodyButton.swift b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/BGImageHeadlineBodyButton.swift new file mode 100644 index 00000000..8a62409b --- /dev/null +++ b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/BGImageHeadlineBodyButton.swift @@ -0,0 +1,90 @@ +// +// BGImageHeadlineBodyButton.swift +// MVMCoreUI +// +// Created by Khan, Arshad on 02/04/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + +@objcMembers public class BGImageHeadlineBodyButton: Container { + let headlineBody = HeadlineBody(frame: .zero) + let button = PillButton(frame: .zero) + let backgroundImageView = MFLoadImageView(pinnedEdges: .all) + 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) + headlineBody.updateView(size) + button.updateView(size) + backgroundImageView.updateView(size) + backgroundImageView.alignFillHorizontal() + backgroundImageView.alignFillVertical() + } + + open override func setupView() { + super.setupView() + heightConstraint = heightAnchor.constraint(equalToConstant: Self.heightConstant) + heightConstraint?.isActive = true + + backgroundImageView.addSizeConstraintsForAspectRatio = true + + let container = MVMCoreUICommonViewsUtility.commonView() + addAndContain(container) + + container.addSubview(headlineBody) + container.addSubview(button) + + //Headline view + headlineBody.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 0).isActive = true + headlineBody.topAnchor.constraint(equalTo: container.topAnchor, constant: 0).isActive = true + + headlineBody.widthAnchor.constraint(equalTo: container.widthAnchor, multiplier: 0.67).isActive = true + let headLineBodyWidth = headlineBody.widthAnchor.constraint(lessThanOrEqualToConstant: maxWidth) + headLineBodyWidth.priority = UILayoutPriority(250) + headLineBodyWidth.isActive = true + + //Caret view + button.translatesAutoresizingMaskIntoConstraints = false + button.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 0).isActive = true + container.bottomAnchor.constraint(greaterThanOrEqualTo: button.bottomAnchor, constant: 0).isActive = true + + button.topAnchor.constraint(equalTo: headlineBody.bottomAnchor, constant: PaddingDefault).isActive = true + + //Background image view + backgroundImageView.translatesAutoresizingMaskIntoConstraints = false + backgroundImageView.imageView.contentMode = .scaleAspectFill + backgroundImageView.alignFillHorizontal() + backgroundImageView.alignFillVertical() + addSubview(backgroundImageView) + NSLayoutConstraint.constraintPinSubview(toSuperview: backgroundImageView) + sendSubviewToBack(backgroundImageView) + } + + // MARK: - MoleculeViewProtocol + open override func reset() { + super.reset() + headlineBody.reset() + backgroundImageView.reset() + } + + // MARK:- MoleculeViewProtocol + public override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + return 320 + } + + public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + super.set(with: model, delegateObject, additionalData) + guard let model = model as? BGImageHeadlineBodyButtonModel else { return } + headlineBody.set(with: model.headlineBody, delegateObject, additionalData) + button.setOptional(with: model.button, delegateObject, additionalData) + button.isHidden = model.button == nil + backgroundImageView.set(with: model.image, delegateObject, additionalData) + backgroundImageView.alignFillHorizontal() + backgroundImageView.alignFillVertical() + } +} diff --git a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/BGImageHeadlineBodyButtonModel.swift b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/BGImageHeadlineBodyButtonModel.swift new file mode 100644 index 00000000..650e4875 --- /dev/null +++ b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/BGImageHeadlineBodyButtonModel.swift @@ -0,0 +1,75 @@ +// +// BGImageHeadlineBodyButtonModel.swift +// MVMCoreUI +// +// Created by Khan, Arshad on 02/04/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation +import UIKit + +public class BGImageHeadlineBodyButtonModel: ContainerModel, MoleculeModelProtocol { + public static var identifier: String = "bgImageHeadlineBodyButton" + public var backgroundColor: Color? + public var button: ButtonModel? + 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 = BGImageHeadlineBodyButton.heightConstant + } + button?.size = .tiny + button?.style = .secondary + } + + private enum CodingKeys: String, CodingKey { + case moleculeName + case backgroundColor + case headlineBody + case image + case button + } + + 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) + button = try typeContainer.decodeIfPresent(ButtonModel.self, forKey: .button) + 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(moleculeName, forKey: .moleculeName) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encode(headlineBody, forKey: .headlineBody) + try container.encode(image, forKey: .image) + try container.encodeIfPresent(button, forKey: .button) + } +} +