add convenience initializers for creating a legacy footer

This commit is contained in:
Kyle Matthew Hedden 2020-03-25 12:59:26 -04:00
parent 18f86575e6
commit 11069d3f73
5 changed files with 112 additions and 3 deletions

View File

@ -110,6 +110,9 @@
0AE98BB323FF0934004C5109 /* ExternalLinkModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE98BB223FF0934004C5109 /* ExternalLinkModel.swift */; };
0AE98BB523FF18D2004C5109 /* Arrow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE98BB423FF18D2004C5109 /* Arrow.swift */; };
0AE98BB723FF18E9004C5109 /* ArrowModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE98BB623FF18E9004C5109 /* ArrowModel.swift */; };
279B1567242BBBF200921D6C /* LabelModelAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 279B1566242BBBF200921D6C /* LabelModelAdapter.swift */; };
279B1569242BBC2F00921D6C /* ActionModelAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 279B1568242BBC2F00921D6C /* ActionModelAdapter.swift */; };
279B156D242BBFF100921D6C /* FooterModelAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 279B156C242BBFF100921D6C /* FooterModelAdapter.swift */; };
31BE15CB23D8924D00452370 /* CheckboxLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */; };
31BE15CC23D8924D00452370 /* CheckboxModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15CA23D8924C00452370 /* CheckboxModel.swift */; };
522679C123FE886900906CBA /* ListLeftVariableCheckboxAllTextAndLinks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 522679BF23FE886900906CBA /* ListLeftVariableCheckboxAllTextAndLinks.swift */; };
@ -502,6 +505,9 @@
0AE98BB223FF0934004C5109 /* ExternalLinkModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExternalLinkModel.swift; sourceTree = "<group>"; };
0AE98BB423FF18D2004C5109 /* Arrow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Arrow.swift; sourceTree = "<group>"; };
0AE98BB623FF18E9004C5109 /* ArrowModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrowModel.swift; sourceTree = "<group>"; };
279B1566242BBBF200921D6C /* LabelModelAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelModelAdapter.swift; sourceTree = "<group>"; };
279B1568242BBC2F00921D6C /* ActionModelAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionModelAdapter.swift; sourceTree = "<group>"; };
279B156C242BBFF100921D6C /* FooterModelAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FooterModelAdapter.swift; sourceTree = "<group>"; };
31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxLabelModel.swift; sourceTree = "<group>"; };
31BE15CA23D8924C00452370 /* CheckboxModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxModel.swift; sourceTree = "<group>"; };
522679BF23FE886900906CBA /* ListLeftVariableCheckboxAllTextAndLinks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListLeftVariableCheckboxAllTextAndLinks.swift; sourceTree = "<group>"; };
@ -917,6 +923,16 @@
path = Link;
sourceTree = "<group>";
};
279B1565242BBB8500921D6C /* Adapters */ = {
isa = PBXGroup;
children = (
279B1566242BBBF200921D6C /* LabelModelAdapter.swift */,
279B1568242BBC2F00921D6C /* ActionModelAdapter.swift */,
279B156C242BBFF100921D6C /* FooterModelAdapter.swift */,
);
path = Adapters;
sourceTree = "<group>";
};
5206F150241144A900658DC5 /* Headers */ = {
isa = PBXGroup;
children = (
@ -1260,6 +1276,7 @@
D22D1F582204D2590077CEC0 /* Legacy */ = {
isa = PBXGroup;
children = (
279B1565242BBB8500921D6C /* Adapters */,
D213347523842FF5008E41B3 /* Views */,
D213347423842FE3008E41B3 /* Controllers */,
);
@ -2088,6 +2105,7 @@
C7F8012123E8303200396FBD /* ListRVWheel.swift in Sources */,
D29DF29521E7ADB8003B2FB9 /* MFProgrammaticScrollViewController.m in Sources */,
D2FB151B23A2B65B00C20E10 /* MoleculeContainer.swift in Sources */,
279B1569242BBC2F00921D6C /* ActionModelAdapter.swift in Sources */,
BB6C6AC0242232DF005F7224 /* ListOneColumnTextWithWhitespaceDividerTallModel.swift in Sources */,
D2A638FD22CA98280052ED1F /* HeadlineBody.swift in Sources */,
D29DF16121E69996003B2FB9 /* MFViewController.m in Sources */,
@ -2113,6 +2131,7 @@
D29DF28C21E7AC2B003B2FB9 /* ViewConstrainingView.m in Sources */,
0AE14F64238315D2005417F8 /* TextField.swift in Sources */,
D29DF17B21E69E1F003B2FB9 /* PrimaryButton.m in Sources */,
279B1567242BBBF200921D6C /* LabelModelAdapter.swift in Sources */,
D2C78CD224228BBD00B69FDE /* ActionOpenPanelModel.swift in Sources */,
017BEB4A236235BA0024EF95 /* ModelMoleculeViewProtocol.swift in Sources */,
C695A68123C9830D00BFB94E /* NumberedListModel.swift in Sources */,
@ -2203,6 +2222,7 @@
01509D932327ECFB00EF99AA /* ProgressBar.swift in Sources */,
D260106523D0CEA700764D80 /* StackModel.swift in Sources */,
D29770F521F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsViewController.m in Sources */,
279B156D242BBFF100921D6C /* FooterModelAdapter.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -42,18 +42,18 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormAction
public var updateUI: (() -> Void)?
init(with title: String, action: ActionModelProtocol) {
public init(with title: String, action: ActionModelProtocol) {
self.title = title
self.action = action
}
init(secondaryButtonWith title: String, action: ActionModelProtocol) {
public init(secondaryButtonWith title: String, action: ActionModelProtocol) {
self.title = title
self.action = action
style = .secondary
}
init(primaryButtonWith title: String, action: ActionModelProtocol) {
public init(primaryButtonWith title: String, action: ActionModelProtocol) {
self.title = title
self.action = action
style = .primary

View File

@ -0,0 +1,20 @@
//
// ActionModelAdapter.swift
// MVMCoreUI
//
// Created by Kyle on 3/25/20.
// Copyright © 2020 Verizon Wireless. All rights reserved.
//
public extension Dictionary {
func asActionModel() -> ActionModelProtocol? {
guard let castedSelf = self as? [String: Any],
let actionType = ModelRegistry.getType(for: castedSelf.stringForkey(KeyActionType), with: ActionModelProtocol.self),
let actionModel = try? actionType.decode(jsonDict: castedSelf) as? ActionModelProtocol else {
return nil
}
return actionModel
}
}

View File

@ -0,0 +1,36 @@
//
// FooterModelAdapter.swift
// MVMCoreUI
//
// Created by Kyle on 3/25/20.
// Copyright © 2020 Verizon Wireless. All rights reserved.
//
public extension FooterModel {
convenience init(withPrimaryAction primaryMap: [AnyHashable: Any]? = nil, secondaryAction secondaryMap: [AnyHashable: Any]? = nil, bottomLinkAction linkMap: [AnyHashable: Any]? = nil) {
var primaryButtonModel: ButtonModel?
var secondaryButtonModel: ButtonModel?
if let primaryActionModel = primaryMap?.asActionModel() {
primaryButtonModel = ButtonModel(primaryButtonWith: primaryActionModel.title ?? "", action: primaryActionModel)
}
if let secondaryActionModel = secondaryMap?.asActionModel() {
secondaryButtonModel = ButtonModel(secondaryButtonWith: secondaryActionModel.title ?? "", action: secondaryActionModel)
}
let twoButtonModel = TwoButtonViewModel(primaryButtonModel, secondaryButtonModel)
let footerContentModel: MoleculeModelProtocol
if let linkActionJSON = linkMap {
let labelModel = LabelModel(linkAction: linkActionJSON)
let moleculeStack = MoleculeStackModel(molecules: [MoleculeStackItemModel(with: twoButtonModel), MoleculeStackItemModel(with: labelModel)])
moleculeStack.spacing = MFStyler.defaultVerticalPaddingForApplicationWidth()
footerContentModel = moleculeStack
} else {
footerContentModel = twoButtonModel
}
self.init(with: footerContentModel)
}
}

View File

@ -0,0 +1,33 @@
//
// LabelModelAdapter.swift
// MVMCoreUI
//
// Created by Kyle on 3/25/20.
// Copyright © 2020 Verizon Wireless. All rights reserved.
//
public extension LabelModel {
convenience init(linkAction: [AnyHashable: Any]) {
// Concatentate the text.
var titlePrefix = linkAction.stringForkey(KeyTitlePrefix)
var titlePostfix = linkAction.stringForkey(KeyTitlePostfix)
if !titlePrefix.isEmpty {
titlePrefix += " "
}
if !titlePostfix.isEmpty {
titlePostfix += " "
}
let title = linkAction.optionalStringForKey(KeyTitle) ?? ""
let text = "\(titlePrefix)\(title)\(titlePostfix)"
// Initialize with text.
self.init(text: text)
// Add action attribute.
if let linkActionModel = linkAction.asActionModel() {
attributes = [LabelAttributeActionModel(titlePrefix.isEmpty ? 0 : titlePrefix.count, title.count, action: linkActionModel)]
}
}
}