diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index d114d2ae..03743382 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -27,6 +27,7 @@ 012A88F123985E0100FE3DA1 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88F023985E0100FE3DA1 /* Color.swift */; }; 012CA99A2384A687003F810F /* MFTextField+ModelExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA9992384A687003F810F /* MFTextField+ModelExtension.swift */; }; 012CA99E2385A2D3003F810F /* MFView+ModelExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */; }; + 013F801923FB4A8E00AD8013 /* UIContentMode+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 013F801823FB4A8E00AD8013 /* UIContentMode+Extension.swift */; }; 014AA72423C501E2006F3E93 /* MoleculeContainerModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 014AA72123C501E2006F3E93 /* MoleculeContainerModel.swift */; }; 014AA72523C501E2006F3E93 /* ContainerModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 014AA72223C501E2006F3E93 /* ContainerModel.swift */; }; 014AA72623C501E2006F3E93 /* ContainerModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 014AA72323C501E2006F3E93 /* ContainerModelProtocol.swift */; }; @@ -359,6 +360,7 @@ 012A88F023985E0100FE3DA1 /* Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = ""; }; 012CA9992384A687003F810F /* MFTextField+ModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFTextField+ModelExtension.swift"; sourceTree = ""; }; 012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFView+ModelExtension.swift"; sourceTree = ""; }; + 013F801823FB4A8E00AD8013 /* UIContentMode+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIContentMode+Extension.swift"; sourceTree = ""; }; 014AA72123C501E2006F3E93 /* MoleculeContainerModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoleculeContainerModel.swift; sourceTree = ""; }; 014AA72223C501E2006F3E93 /* ContainerModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContainerModel.swift; sourceTree = ""; }; 014AA72323C501E2006F3E93 /* ContainerModelProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContainerModelProtocol.swift; sourceTree = ""; }; @@ -1142,6 +1144,7 @@ D29DF11021E6805F003B2FB9 /* Categories */ = { isa = PBXGroup; children = ( + 013F801823FB4A8E00AD8013 /* UIContentMode+Extension.swift */, D29DF11121E6805F003B2FB9 /* UIColor+MFConvenience.h */, D29DF11321E6805F003B2FB9 /* UIColor+MFConvenience.m */, D29DF11221E6805F003B2FB9 /* NSLayoutConstraint+MFConvenience.h */, @@ -1801,6 +1804,7 @@ 943784F6236B77BB006A1E82 /* GraphViewAnimationHandler.swift in Sources */, D29DF2AA21E7B2F9003B2FB9 /* MVMCoreUIConstants.m in Sources */, 948DB67E2326DCD90011F916 /* MultiProgress.swift in Sources */, + 013F801923FB4A8E00AD8013 /* UIContentMode+Extension.swift in Sources */, D2A5146122121FBF00345BFB /* MoleculeStackTemplate.swift in Sources */, D2E2A9A323E096B1000B42E6 /* DisableableModelProtocol.swift in Sources */, D29DF11821E6805F003B2FB9 /* NSLayoutConstraint+MFConvenience.m in Sources */, diff --git a/MVMCoreUI/Atoms/Buttons/ButtonModel.swift b/MVMCoreUI/Atoms/Buttons/ButtonModel.swift index cfe8bb2f..f02eaf5c 100644 --- a/MVMCoreUI/Atoms/Buttons/ButtonModel.swift +++ b/MVMCoreUI/Atoms/Buttons/ButtonModel.swift @@ -20,7 +20,6 @@ public enum ButtonSize: String, Codable { public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol { public static var identifier: String = "button" - public var moleculeName: String? public var backgroundColor: Color? public var title: String public var action: ActionModelProtocol @@ -46,6 +45,12 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol { self.action = action style = .secondary } + + init(primaryButtonWith title: String, action: ActionModelProtocol) { + self.title = title + self.action = action + style = .primary + } private enum CodingKeys: String, CodingKey { case moleculeName @@ -67,7 +72,6 @@ public class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol { required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - moleculeName = try typeContainer.decodeIfPresent(String.self, forKey: .moleculeName) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) title = try typeContainer.decode(String.self, forKey: .title) diff --git a/MVMCoreUI/Atoms/Views/ImageViewModel.swift b/MVMCoreUI/Atoms/Views/ImageViewModel.swift index ce46a930..97f31ad2 100644 --- a/MVMCoreUI/Atoms/Views/ImageViewModel.swift +++ b/MVMCoreUI/Atoms/Views/ImageViewModel.swift @@ -11,11 +11,15 @@ import Foundation @objcMembers public class ImageViewModel: MoleculeModelProtocol { public static var identifier: String = "image" public var backgroundColor: Color? - public var image: String public var accessibilityText: String? public var fallbackImage: String? public var imageFormat: String? public var width: CGFloat? public var height: CGFloat? + public var contentMode: UIView.ContentMode? + + public init(image: String) { + self.image = image + } } diff --git a/MVMCoreUI/Atoms/Views/Label/LabelAttributeModel.swift b/MVMCoreUI/Atoms/Views/Label/LabelAttributeModel.swift index 22bb10d8..3c073b2f 100644 --- a/MVMCoreUI/Atoms/Views/Label/LabelAttributeModel.swift +++ b/MVMCoreUI/Atoms/Views/Label/LabelAttributeModel.swift @@ -28,7 +28,13 @@ import Foundation var type: String var location: Int var length: Int - + + init(_ type: String, _ location: Int, _ length: Int) { + self.type = type + self.location = location + self.length = length + } + //-------------------------------------------------- // MARK: - Keys //-------------------------------------------------- diff --git a/MVMCoreUI/Atoms/Views/Label/LabelModel.swift b/MVMCoreUI/Atoms/Views/Label/LabelModel.swift index 731b23da..d7fb4fa3 100644 --- a/MVMCoreUI/Atoms/Views/Label/LabelModel.swift +++ b/MVMCoreUI/Atoms/Views/Label/LabelModel.swift @@ -11,9 +11,7 @@ import Foundation @objcMembers public class LabelModel: MoleculeModelProtocol { public static var identifier: String = "label" - public var moleculeName: String? public var backgroundColor: Color? - public var text: String public var accessibilityText: String? public var textColor: String? @@ -45,10 +43,13 @@ import Foundation enum AttributeTypeKey: String, CodingKey { case type } - + + public init(text: String) { + self.text = text + } + required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - moleculeName = try typeContainer.decodeIfPresent(String.self, forKey: .moleculeName) text = try typeContainer.decode(String.self, forKey: .text) accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText) textColor = try typeContainer.decodeIfPresent(String.self, forKey: .textColor) diff --git a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift index 1c54b891..5e8cedc8 100644 --- a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift +++ b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift @@ -232,6 +232,10 @@ import UIKit imageView.animatedImage = nil loadImage(withName: imageModel.image, format: imageModel.imageFormat, width: width as NSNumber?, height: height as NSNumber?, customFallbackImage: imageModel.fallbackImage) } + + if let contentMode = imageModel.contentMode { + imageView.contentMode = contentMode + } } // MARK: - MVMCoreUIMoleculeViewProtocol functions diff --git a/MVMCoreUI/BaseClasses/Button.swift b/MVMCoreUI/BaseClasses/Button.swift index a780151a..60e0ab1a 100644 --- a/MVMCoreUI/BaseClasses/Button.swift +++ b/MVMCoreUI/BaseClasses/Button.swift @@ -91,7 +91,7 @@ public typealias ButtonAction = (Button) -> () if let backgroundColor = model?.backgroundColor { self.backgroundColor = backgroundColor.uiColor } - + guard let model = model as? ButtonModelProtocol else { return } isEnabled = model.enabled set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) diff --git a/MVMCoreUI/Categories/UIContentMode+Extension.swift b/MVMCoreUI/Categories/UIContentMode+Extension.swift new file mode 100644 index 00000000..19cf523b --- /dev/null +++ b/MVMCoreUI/Categories/UIContentMode+Extension.swift @@ -0,0 +1,98 @@ +// +// UIContentMode+Extension.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 2/17/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + +enum ContentModeError: Error { + case notAContentMode +} + +extension UIView.ContentMode: RawRepresentable { + + init?(rawValue: String) { + switch rawValue { + case "scaleToFill": + self = .scaleToFill + case "scaleAspectFit": + self = .scaleAspectFit + case "scaleAspectFill": + self = .scaleAspectFill + case "redraw": + self = .redraw + case "center": + self = .center + case "top": + self = .top + case "bottom": + self = .bottom + case "left": + self = .left + case "right": + self = .right + case "topLeft": + self = .topLeft + case "topRight": + self = .topRight + case "bottomLeft": + self = .bottomLeft + case "bottomRight": + self = .bottomRight + default: + return nil + } + } + + var rawValueString: String { + switch self { + case .scaleToFill: + return "scaleToFill" + case .scaleAspectFit: + return "scaleAspectFit" + case .scaleAspectFill: + return "scaleAspectFill" + case .redraw: + return "redraw" + case .center: + return "center" + case .top: + return "top" + case .bottom: + return "bottom" + case .left: + return "left" + case .right: + return "right" + case .topLeft: + return "topLeft" + case .topRight: + return "topRight" + case .bottomLeft: + return "bottomLeft" + case .bottomRight: + return "bottomRight" + @unknown default: + return "" + } + } +} + +extension UIView.ContentMode: Codable { + public init(from decoder: Decoder) throws { + let typeContainer = try decoder.singleValueContainer() + let string = try typeContainer.decode(String.self) + guard let mode = UIView.ContentMode(rawValue: string) else { + throw ContentModeError.notAContentMode + } + self = mode + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(rawValueString) + } +} diff --git a/MVMCoreUI/CustomPrimitives/Color.swift b/MVMCoreUI/CustomPrimitives/Color.swift index a34fbd45..165fa8ad 100644 --- a/MVMCoreUI/CustomPrimitives/Color.swift +++ b/MVMCoreUI/CustomPrimitives/Color.swift @@ -49,7 +49,7 @@ public final class Color: Codable { // MARK: - Class Initializers //-------------------------------------------------- - init(uiColor: UIColor) { + public init(uiColor: UIColor) { self.uiColor = uiColor hex = UIColor.hexString(for: uiColor) ?? "" determineRGBA() diff --git a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift index 5938692b..057203e9 100644 --- a/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift +++ b/MVMCoreUI/Molecules/HorizontalCombinationViews/TwoButtonViewModel.swift @@ -21,6 +21,11 @@ public class TwoButtonViewModel: MoleculeModelProtocol { case secondaryButton } + public init(_ primaryButton: ButtonModel?, _ secondaryButton: ButtonModel?) { + self.primaryButton = primaryButton + self.secondaryButton = secondaryButton + } + required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) diff --git a/MVMCoreUI/Molecules/Items/MoleculeStackItemModel.swift b/MVMCoreUI/Molecules/Items/MoleculeStackItemModel.swift index 4731ef34..dc01fd11 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeStackItemModel.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeStackItemModel.swift @@ -25,7 +25,7 @@ import Foundation public override init(with moleculeModel: MoleculeModelProtocol) { super.init(with: moleculeModel) } - + required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) spacing = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .spacing) diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift index 1fbe98e7..fd5be23a 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBodyModel.swift @@ -10,7 +10,6 @@ import Foundation @objcMembers public class HeadlineBodyModel: MoleculeModelProtocol { public static var identifier: String = "headlineBody" - public var moleculeName: String? public var headline: LabelModel? public var body: LabelModel? public var style: String? diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIViewControllerMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIViewControllerMappingObject.m index 7bdccc8e..5b9592cc 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIViewControllerMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIViewControllerMappingObject.m @@ -22,8 +22,7 @@ @"stack" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[MoleculeStackTemplate class]], @"centerMoleculeStack" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[MoleculeStackCenteredTemplate class]], @"list" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[MoleculeListTemplate class]], - @"threeLayer" : - [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[ThreeLayerTemplate class]] + @"threeLayer" : [[MVMCoreViewControllerProgrammaticMappingObject alloc] initWithClass:[ThreeLayerTemplate class]] } mutableCopy]; }); return viewControllerMapping;