Merge branch 'feature/model_fixes' into 'develop'
fixes See merge request BPHV_MIPS/mvm_core_ui!262
This commit is contained in:
commit
6d819897bd
@ -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 = "<group>"; };
|
||||
012CA9992384A687003F810F /* MFTextField+ModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFTextField+ModelExtension.swift"; sourceTree = "<group>"; };
|
||||
012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFView+ModelExtension.swift"; sourceTree = "<group>"; };
|
||||
013F801823FB4A8E00AD8013 /* UIContentMode+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIContentMode+Extension.swift"; sourceTree = "<group>"; };
|
||||
014AA72123C501E2006F3E93 /* MoleculeContainerModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoleculeContainerModel.swift; sourceTree = "<group>"; };
|
||||
014AA72223C501E2006F3E93 /* ContainerModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContainerModel.swift; sourceTree = "<group>"; };
|
||||
014AA72323C501E2006F3E93 /* ContainerModelProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContainerModelProtocol.swift; sourceTree = "<group>"; };
|
||||
@ -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 */,
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
98
MVMCoreUI/Categories/UIContentMode+Extension.swift
Normal file
98
MVMCoreUI/Categories/UIContentMode+Extension.swift
Normal file
@ -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)
|
||||
}
|
||||
}
|
||||
@ -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()
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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?
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user