merge line

This commit is contained in:
Scott Pfeil 2023-09-28 17:05:16 -04:00
commit 7630299e69
14 changed files with 122 additions and 165 deletions

View File

@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 54;
objects = {
/* Begin PBXBuildFile section */
@ -588,6 +588,7 @@
EAB14BC327D9378D0012AB2C /* RuleAnyModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB14BC227D9378D0012AB2C /* RuleAnyModelProtocol.swift */; };
EABFC1412763BB8D00E78B40 /* FormLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EABFC1402763BB8D00E78B40 /* FormLabel.swift */; };
EABFC152276913E800E78B40 /* FormLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EABFC151276913E800E78B40 /* FormLabelModel.swift */; };
EACCF38C2ABB346700E0F104 /* VDS-Interpreters.swift in Sources */ = {isa = PBXBuildFile; fileRef = EACCF38B2ABB346700E0F104 /* VDS-Interpreters.swift */; };
FD99130028E21E4900542CC3 /* RuleNotEqualsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD9912FF28E21E4900542CC3 /* RuleNotEqualsModel.swift */; };
/* End PBXBuildFile section */
@ -1176,6 +1177,7 @@
EAB14BC227D9378D0012AB2C /* RuleAnyModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleAnyModelProtocol.swift; sourceTree = "<group>"; };
EABFC1402763BB8D00E78B40 /* FormLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormLabel.swift; sourceTree = "<group>"; };
EABFC151276913E800E78B40 /* FormLabelModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormLabelModel.swift; sourceTree = "<group>"; };
EACCF38B2ABB346700E0F104 /* VDS-Interpreters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "VDS-Interpreters.swift"; sourceTree = "<group>"; };
FD9912FF28E21E4900542CC3 /* RuleNotEqualsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleNotEqualsModel.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -2418,6 +2420,7 @@
011B58EE23A2AA850085F53C /* ModelProtocols */,
27559EFB27D691D3000836C1 /* ViewMaskingProtocol.swift */,
EAA7801F290081320057DFDF /* VDSMoleculeViewProtocol.swift */,
EACCF38B2ABB346700E0F104 /* VDS-Interpreters.swift */,
);
path = Protocols;
sourceTree = "<group>";
@ -2976,6 +2979,7 @@
D28BA741248025A300B75CB8 /* TabBarModel.swift in Sources */,
D224798A2314445E003FCCF9 /* LabelToggle.swift in Sources */,
D2A92882241AAB67004E01C6 /* ScrollingViewController.swift in Sources */,
EACCF38C2ABB346700E0F104 /* VDS-Interpreters.swift in Sources */,
C695A67F23C9830600BFB94E /* UnOrderedListModel.swift in Sources */,
0AE98BB523FF18D2004C5109 /* Arrow.swift in Sources */,
D2FA83D22513EA6900564112 /* NotificationXButton.swift in Sources */,

View File

@ -7,116 +7,96 @@
//
import UIKit
import VDS
@objcMembers open class Line: View {
@objcMembers open class Line: VDS.Line, VDSMoleculeViewProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
var lineModel: LineModel? {
get { return model as? LineModel }
}
//--------------------------------------------------
// MARK: - Constraints
//--------------------------------------------------
public var heightConstraint: NSLayoutConstraint?
public var widthConstraint: NSLayoutConstraint?
open func updateLineConstraints(constant: CGFloat) {
if let useVerticalLine = lineModel?.useVerticalLine, useVerticalLine {
heightConstraint?.isActive = false
widthConstraint?.isActive = true
widthConstraint?.constant = constant
} else {
widthConstraint?.isActive = false
heightConstraint?.isActive = true
heightConstraint?.constant = constant
}
}
open var viewModel: LineModel!
open var delegateObject: MVMCoreUIDelegateObject?
open var additionalData: [AnyHashable : Any]?
//--------------------------------------------------
// MARK: - Initializer
//--------------------------------------------------
//--------------------------------------------------
public convenience init(pinTo view: UIView, edge: UIRectEdge, useMargin: Bool) {
self.init(frame: .zero)
addLine(to: view, edge: edge, useMargin: useMargin)
}
public init() {
super.init(frame: .zero)
model = LineModel(type: .secondary)
setStyle(.secondary)
public required init() {
super.init()
viewModel = LineModel(type: .primary)
}
public override init(frame: CGRect) {
super.init(frame: frame)
model = LineModel(type: .secondary)
setStyle(.secondary)
viewModel = LineModel(type: .primary)
}
public required init?(coder: NSCoder) {
super.init(coder: coder)
model = LineModel(type: .secondary)
setStyle(.secondary)
viewModel = LineModel(type: .primary)
}
public required init(model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
super.init(model: model, delegateObject, additionalData)
}
//--------------------------------------------------
// MARK: - Methods
//--------------------------------------------------
open func setStyle(_ style: LineModel.Style) {
lineModel?.type = style
backgroundColor = lineModel?.backgroundColor?.uiColor
updateLineConstraints(constant: lineModel?.thickness ?? 1)
}
open func shouldBeVisible() -> Bool {
guard let type = lineModel?.type else { return false }
guard let type = viewModel?.type else { return false }
return type != .none
}
//--------------------------------------------------
// MARK: - MoleculeViewProtocol
//--------------------------------------------------
open func setStyle(_ style: LineModel.Style) {
viewModel.type = style
update(viewModel: viewModel)
}
open func addLine(to view: UIView, edge: UIRectEdge, useMargin: Bool) {
view.addSubview(self)
NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: self, useMargins: useMargin, pinTop: edge != .bottom, pinBottom: edge != .top, pinLeft: edge != .right, pinRight: edge != .left).values))
NSLayoutConstraint.activate(
Array(
NSLayoutConstraint.pinView(toSuperview: self,
useMargins: useMargin,
pinTop: edge != .bottom,
pinBottom: edge != .top,
pinLeft: edge != .right,
pinRight: edge != .left).values
)
)
}
open override func setupView() {
super.setupView()
heightConstraint = heightAnchor.constraint(equalToConstant: 1)
heightConstraint?.isActive = true
widthConstraint = widthAnchor.constraint(equalToConstant: 1)
widthConstraint?.isActive = false
open override func draw(_ rect: CGRect) {
guard viewModel.type != .none else { return }
super.draw(rect)
}
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
super.set(with: model, delegateObject, additionalData)
//--------------------------------------------------
// MARK: - VDSMoleculeViewProtocol
//--------------------------------------------------
open func viewModelDidUpdate() {
surface = viewModel.surface
style = VDS.Line.Style(rawValue: viewModel.type.rawValue) ?? .primary
orientation = viewModel.orientation
}
if let lineModel = model as? LineModel {
setStyle(lineModel.type)
}
//--------------------------------------------------
// MARK: - MoleculeViewProtocol
//--------------------------------------------------
public func updateView(_ size: CGFloat) {
setNeedsDisplay()
}
open override func reset() {
setStyle(.secondary)
}
public override static func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
return (model as? LineModel)?.thickness ?? 1
public static func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
return 1
}
}
//--------------------------------------------------
// MARK: - MVMCoreUIViewConstrainingProtocol
//--------------------------------------------------
extension Line: MVMCoreUIViewConstrainingProtocol {
open func needsToBeConstrained() -> Bool {

View File

@ -8,8 +8,9 @@
import UIKit
import VDSColorTokens
import VDS
@objcMembers public class LineModel: MoleculeModelProtocol {
@objcMembers public class LineModel: MoleculeModelProtocol, Invertable {
//--------------------------------------------------
// MARK: - Enums
//--------------------------------------------------
@ -28,23 +29,9 @@ import VDSColorTokens
case between
}
/**
The style of the line:
- secondary (1 height, silver)
- primary (1 height, black)
- standard (1 height, silver) - deprecated
- thin (1 height, black) - deprecated
- medium (2 height, black)
- heavy (4 height, black)
- none (hidden)
*/
public enum Style: String, Codable {
case secondary
case primary
case standard
case thin
case medium
case heavy
case none
}
@ -54,53 +41,14 @@ import VDSColorTokens
public static var identifier: String = "line"
public var id: String = UUID().uuidString
public var type: Style = .secondary
public var backgroundColor: Color?
public var type: Style = .primary
public var frequency: Frequency? = .allExceptTop
//TODO: use color insted of backgroundColor. Needs server changes
// public var color: Color?
private var _backgroundColor: Color?
public var backgroundColor: Color? {
get {
if let backgroundColor = _backgroundColor { return backgroundColor }
if inverted {
if type == .secondary || type == .standard { return Color(uiColor: VDSColor.paletteGray20) }
return Color(uiColor: VDSColor.elementsPrimaryOndark)
}
if type == .secondary || type == .standard { return Color(uiColor: VDSColor.paletteGray85) }
return Color(uiColor: VDSColor.elementsPrimaryOnlight)
}
set {
_backgroundColor = newValue
}
}
private var _thickness: CGFloat?
public var thickness: CGFloat {
get {
if let thickness = _thickness { return thickness }
switch type {
case .heavy:
return 4
case .medium:
return 2
case .none:
return 0
default:
return 1
}
}
set {
_thickness = newValue
}
}
public var inverted: Bool = false
// Use this to show vertical line
// Default is false
public var useVerticalLine: Bool?
public var orientation: VDS.Line.Orientation = .horizontal
//--------------------------------------------------
// MARK: - Initializer
@ -108,13 +56,10 @@ import VDSColorTokens
public init(type: Style) {
self.type = type
self.useVerticalLine = false
}
public init(verticalLineOf type: Style, backgroundColor: Color? = nil) {
self.type = type
self.backgroundColor = backgroundColor
self.useVerticalLine = true
}
//--------------------------------------------------
@ -125,13 +70,10 @@ import VDSColorTokens
case id
case moleculeName
case type
case backgroundColor
case backgroundColor_inverted
case color
case frequency
case inverted
case useVerticalLine
case thickness
case orientation
}
//--------------------------------------------------
@ -155,9 +97,12 @@ import VDSColorTokens
self.inverted = inverted
}
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
useVerticalLine = try typeContainer.decodeIfPresent(Bool.self, forKey: .useVerticalLine)
_thickness = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .thickness)
/// adding code to look for the old useVerticalLine or the new orientation
if let useVerticalLine = try typeContainer.decodeIfPresent(Bool.self, forKey: .useVerticalLine) {
orientation = useVerticalLine ? .vertical : .horizontal
}else if let orientation = try typeContainer.decodeIfPresent(VDS.Line.Orientation.self, forKey: .orientation) {
self.orientation = orientation
}
}
public func encode(to encoder: Encoder) throws {
@ -167,8 +112,6 @@ import VDSColorTokens
try container.encode(type, forKey: .type)
try container.encode(inverted, forKey: .inverted)
try container.encodeIfPresent(frequency, forKey: .frequency)
try container.encodeIfPresent(_backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(useVerticalLine, forKey: .useVerticalLine)
try container.encodeIfPresent(_thickness, forKey: .thickness)
try container.encodeIfPresent(orientation == .vertical, forKey: .useVerticalLine)
}
}

View File

@ -22,3 +22,5 @@ extension VDS.Button.Size: RawRepresentableCodable {
public static var defaultValue: VDS.Button.Size? { nil }
}
extension TextLink.Size: Codable {}
extension VDS.Line.Style: Codable {}
extension VDS.Line.Orientation: Codable {}

View File

@ -42,6 +42,13 @@ import Foundation
return Stack<StackModel>.createStack(with: [headline, horizontalStack], spacing: 8)
}()
//-------------------------------------------------------
// MARK: - Constraints
//-------------------------------------------------------
public var verticalLine1HeightConstraint: NSLayoutConstraint?
public var verticalLine2HeightConstraint: NSLayoutConstraint?
//-------------------------------------------------------
// MARK: - Lifecycle
//-------------------------------------------------------
@ -51,11 +58,10 @@ import Foundation
body.lineBreakMode = .byTruncatingTail
body2.lineBreakMode = .byTruncatingTail
body3.lineBreakMode = .byTruncatingTail
verticalLine1.widthConstraint?.isActive = true
verticalLine1.backgroundColor = .mvmBlack
verticalLine2.widthConstraint?.isActive = true
verticalLine2.backgroundColor = .mvmBlack
// setup lines
verticalLine1.orientation = .vertical
verticalLine2.orientation = .vertical
addMolecule(stack)
stack.restack()
@ -80,13 +86,13 @@ import Foundation
}
open func setLineHeight() {
verticalLine1.heightConstraint?.isActive = false
verticalLine1.heightConstraint = verticalLine1.heightAnchor.constraint(equalTo: body2.heightAnchor, multiplier: 1)
verticalLine1.heightConstraint?.isActive = true
verticalLine1HeightConstraint?.isActive = false
verticalLine1HeightConstraint = verticalLine1.heightAnchor.constraint(equalTo: body2.heightAnchor, multiplier: 1)
verticalLine1HeightConstraint?.isActive = true
verticalLine2.heightConstraint?.isActive = false
verticalLine2.heightConstraint = verticalLine2.heightAnchor.constraint(equalTo: body3.heightAnchor, multiplier: 1)
verticalLine2.heightConstraint?.isActive = true
verticalLine2HeightConstraint?.isActive = false
verticalLine2HeightConstraint = verticalLine2.heightAnchor.constraint(equalTo: body3.heightAnchor, multiplier: 1)
verticalLine2HeightConstraint?.isActive = true
}
//----------------------------------------------------

View File

@ -102,7 +102,7 @@
leftHeadline.styleB1(true)
leftBody.styleB2(true)
rightLabel.styleB2(true)
rightBar.setStyle(.medium)
rightBar.setStyle(.primary)
}
//------------------------------------------------------

View File

@ -39,7 +39,7 @@ public class ListProgressBarThinModel: ListItemModel, MoleculeModelProtocol {
override public func setDefaults() {
super.setDefaults()
rightBar.type = .medium
rightBar.type = .primary
if rightBar.backgroundColor == nil {
rightBar.backgroundColor = Color(uiColor: .gray)

View File

@ -44,7 +44,7 @@
override open func setupView() {
super.setupView()
bar.setStyle(.heavy)
bar.setStyle(.primary)
bar.widthAnchor.constraint(equalToConstant: 20).isActive = true
rightLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal)
addMolecule(stack)
@ -74,7 +74,7 @@
super.reset()
leftLabel.setFontStyle(.BoldBodySmall)
rightLabel.setFontStyle(.RegularBodySmall)
bar.setStyle(.heavy)
bar.setStyle(.primary)
}
//--------------------------------------------------

View File

@ -24,7 +24,7 @@ public class ListRightVariableTotalDataModel: ListItemModel, MoleculeModelProtoc
override public func setDefaults() {
super.setDefaults()
rightLabel.hero = 0
bar.type = .heavy
bar.type = .primary
if bar.backgroundColor == nil {
bar.backgroundColor = Color(uiColor: .mvmBlue)

View File

@ -50,7 +50,7 @@ import VDSColorTokens
setItems(tabs, animated: false)
selectedItem = tabs[model.selectedTab]
guard let lineModel = line.lineModel else { return }
guard let lineModel = line.viewModel else { return }
lineModel.inverted = model.style == .dark
line.set(with: lineModel, delegateObject, additionalData)
}

View File

@ -174,7 +174,7 @@ import VDSColorTokens
self.additionalData = additionalData
selectedIndex = tabsModel?.selectedIndex ?? 0
selectionLine.backgroundColor = tabsModel?.selectedBarColor.uiColor
let lineModel = bottomLine.lineModel ?? LineModel(type: .secondary)
let lineModel = bottomLine.viewModel ?? LineModel(type: .secondary)
lineModel.inverted = tabsModel?.style == .dark
bottomLine.set(with: lineModel, delegateObject, additionalData)
reloadData()

View File

@ -0,0 +1,18 @@
//
// VDS-Interpreters.swift
// MVMCoreUI
//
// Created by Matt Bruce on 9/20/23.
// Copyright © 2023 Verizon Wireless. All rights reserved.
//
import Foundation
import VDS
public protocol Invertable {
var inverted: Bool { get set }
}
extension Invertable {
public var surface: Surface { return inverted ? .dark : .light }
}

View File

@ -28,5 +28,9 @@ extension VDSMoleculeViewProtocol {
viewModel = castedModel
viewModelDidUpdate()
}
public func update(viewModel: ViewModel){
set(with: viewModel, delegateObject, additionalData)
}
}

View File

@ -84,9 +84,9 @@ public extension UINavigationController {
/// Returns a ShadowImage based on the line property of NavigationItemModelProtocol
func getNavigationBarShadowImage(for navigationItemModel: NavigationItemModelProtocol) -> UIImage? {
guard let thickness = navigationItemModel.line?.thickness,
let backgroundColor = navigationItemModel.line?.backgroundColor else { return nil }
return backgroundColor.uiColor.image(CGSize(width: thickness, height: thickness))
guard let model = navigationItemModel.line else { return nil }
let line = Line(model: model, nil, nil)
return line.lineColor.image(CGSize(width: line.lineWidth, height: line.lineWidth))
}
/// Convenience function for setting the navigation bar ui