style in model for list item

This commit is contained in:
Pfeil, Scott Robert 2020-07-02 19:20:30 -04:00
parent 4c0cf1ae28
commit 573d6b2a98
15 changed files with 85 additions and 75 deletions

View File

@ -33,10 +33,9 @@ public class ListTwoColumnPriceDetailsModel: ListItemModel, MoleculeModelProtoco
//--------------------------------------------------
override public func setDefaults() {
style = ListItemStyle.none
super.setDefaults()
style = "none"
if leftLabel.textColor == nil {
leftLabel.textColor = Color(uiColor: .mvmCoolGray6)
}

View File

@ -33,8 +33,8 @@ public class ListFourColumnDataUsageDividerModel: ListItemModel, MoleculeModelPr
}
override public func setDefaults() {
style = .tallDivider
super.setDefaults()
style = "tallDivider"
}
//--------------------------------------------------

View File

@ -33,8 +33,8 @@ public class ListOneColumnFullWidthTextDividerSubsectionModel: ListItemModel, Mo
//--------------------------------------------------
override public func setDefaults() {
style = .tallDivider
super.setDefaults()
style = "tallDivider"
}
//--------------------------------------------------

View File

@ -33,8 +33,8 @@ public class ListOneColumnTextWithWhitespaceDividerShortModel: ListItemModel, Mo
//--------------------------------------------------
override public func setDefaults() {
style = .shortDivider
super.setDefaults()
style = "shortDivider"
}
//--------------------------------------------------

View File

@ -33,8 +33,8 @@ public class ListOneColumnTextWithWhitespaceDividerTallModel: ListItemModel, Mol
//--------------------------------------------------
override public func setDefaults() {
style = .tallDivider
super.setDefaults()
style = "tallDivider"
}
//--------------------------------------------------

View File

@ -35,8 +35,8 @@ public class ListThreeColumnBillChangesDividerModel: ListItemModel, MoleculeMode
//-----------------------------------------------------
override public func setDefaults() {
style = .tallDivider
super.setDefaults()
style = "tallDivider"
}
//-----------------------------------------------------

View File

@ -35,8 +35,8 @@ public class ListThreeColumnDataUsageDividerModel: ListItemModel, MoleculeModelP
//-----------------------------------------------------
override public func setDefaults() {
style = .tallDivider
super.setDefaults()
style = "tallDivider"
}
//-----------------------------------------------------

View File

@ -35,8 +35,8 @@ public class ListThreeColumnInternationalDataDividerModel: ListItemModel, Molecu
//------------------------------------------------------
override public func setDefaults() {
style = .tallDivider
super.setDefaults()
style = "tallDivider"
}
//------------------------------------------------------

View File

@ -35,8 +35,8 @@ public class ListThreeColumnPlanDataDividerModel: ListItemModel, MoleculeModelPr
//-----------------------------------------------------
override public func setDefaults() {
style = .tallDivider
super.setDefaults()
style = "tallDivider"
leftHeadlineBody.style = .itemHeader
centerHeadlineBody.style = .itemHeader
rightHeadlineBody.style = .itemHeader

View File

@ -35,8 +35,8 @@ public class ListThreeColumnSpeedTestDividerModel: ListItemModel, MoleculeModelP
//-----------------------------------------------------
override public func setDefaults() {
style = .tallDivider
super.setDefaults()
style = "tallDivider"
}
//-----------------------------------------------------

View File

@ -33,8 +33,8 @@ public class ListTwoColumnSubsectionDividerModel: ListItemModel, MoleculeModelPr
//------------------------------------------------------
override public func setDefaults() {
style = .tallDivider
super.setDefaults()
style = "tallDivider"
}
//------------------------------------------------------

View File

@ -24,10 +24,10 @@ import Foundation
/// Defaults to set
public override func setDefaults() {
style = .sectionFooter
super.setDefaults()
hideArrow = true
line = LineModel(type: .none)
style = "sectionFooter"
}
//--------------------------------------------------

View File

@ -11,6 +11,7 @@ import Foundation
@objcMembers open class ListItemModel: ContainerModel, ListItemModelProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
@ -19,7 +20,7 @@ import Foundation
public var action: ActionModelProtocol?
public var hideArrow: Bool?
public var line: LineModel?
public var style: String?
public var style: ListItemStyle? = .standard
//--------------------------------------------------
// MARK: - Keys
@ -39,17 +40,39 @@ import Foundation
/// Defaults to set
open override func setDefaults() {
if useHorizontalMargins == nil {
useHorizontalMargins = true
setByStyle()
}
/// Convenience function to set common values.
open func set(useHorizontalMargins: Bool? = true, useVerticalMargins: Bool? = true, topPadding: CGFloat? = nil, bottomPadding: CGFloat? = nil) {
if self.useHorizontalMargins == nil {
self.useHorizontalMargins = useHorizontalMargins
}
if useVerticalMargins == nil {
useVerticalMargins = true
if self.useVerticalMargins == nil {
self.useVerticalMargins = useVerticalMargins
}
if topPadding == nil {
topPadding = 24
if self.topPadding == nil {
self.topPadding = topPadding
}
if bottomPadding == nil {
bottomPadding = 24
if self.bottomPadding == nil {
self.bottomPadding = bottomPadding
}
}
/// Convenience function to set common values based on style.
open func setByStyle() {
guard let style = style else { return }
switch style {
case .standard:
set(topPadding: Padding.Component.VerticalMarginSpacing, bottomPadding: Padding.Component.VerticalMarginSpacing)
case .shortDivider:
set(topPadding: Padding.Component.LargeVerticalMarginSpacing, bottomPadding: Padding.Four)
case .tallDivider:
set(topPadding: Padding.Twelve, bottomPadding: Padding.Four)
case .sectionFooter:
set(topPadding: Padding.Component.VerticalMarginSpacing, bottomPadding: 0)
case ListItemStyle.none:
set(topPadding: 0, bottomPadding: 0)
}
}
@ -57,6 +80,12 @@ import Foundation
// MARK: - Initializer
//--------------------------------------------------
public init(style: ListItemStyle? = .standard, action: ActionModelProtocol?) {
self.style = style
self.action = action
super.init()
}
public override init(horizontalAlignment: UIStackView.Alignment? = nil, verticalAlignment: UIStackView.Alignment? = nil, useHorizontalMargins: Bool? = nil, leftPadding: CGFloat? = nil, rightPadding: CGFloat? = nil, useVerticalMargins: Bool? = nil, topPadding: CGFloat? = nil, bottomPadding: CGFloat? = nil) {
super.init(horizontalAlignment: horizontalAlignment, verticalAlignment: verticalAlignment, useHorizontalMargins: useHorizontalMargins, leftPadding: leftPadding, rightPadding: rightPadding, useVerticalMargins: useVerticalMargins, topPadding: topPadding, bottomPadding: bottomPadding)
}
@ -75,7 +104,9 @@ import Foundation
action = try typeContainer.decodeModelIfPresent(codingKey: .action)
hideArrow = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideArrow)
line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line)
style = try typeContainer.decodeIfPresent(String.self, forKey: .style)
if let style = try typeContainer.decodeIfPresent(ListItemStyle.self, forKey: .style) {
self.style = style
}
try super.init(from: decoder)
}

View File

@ -8,12 +8,19 @@
import Foundation
public enum ListItemStyle: String, Codable {
case standard
case shortDivider
case tallDivider
case sectionFooter
case none
}
public protocol ListItemModelProtocol: ContainerModelProtocol {
var line: LineModel? { get set }
var action: ActionModelProtocol? { get set }
var hideArrow: Bool? { get set }
var style: String? { get set }
var style: ListItemStyle? { get set }
}
// Not a strict requirement.
@ -24,7 +31,7 @@ public extension ListItemModelProtocol {
set { }
}
var style: String? {
var style: ListItemStyle? {
get { return nil }
set { }
}

View File

@ -31,60 +31,33 @@ import UIKit
private var initialSetupPerformed = false
// MARK: - Styling
open func style(with styleString: String?) {
guard let styleString = styleString else {
return
}
switch styleString {
case "standard":
styleStandard()
case "shortDivider":
styleShortDivider()
case "tallDivider":
styleTallDivider()
case "sectionFooter":
styleFooter()
case "none":
styleNone()
open func styleLine(with style: ListItemStyle?) {
switch style {
case .standard?:
topSeparatorView?.setStyle(.none)
bottomSeparatorView?.setStyle(.standard)
case .shortDivider?:
topSeparatorView?.setStyle(.none)
bottomSeparatorView?.setStyle(.thin)
case .tallDivider?:
topSeparatorView?.setStyle(.none)
bottomSeparatorView?.setStyle(.thin)
case .sectionFooter?:
topSeparatorView?.setStyle(.none)
bottomSeparatorView?.setStyle(.none)
case ListItemStyle.none?:
topSeparatorView?.setStyle(.none)
bottomSeparatorView?.setStyle(.none)
default: break
}
}
/// Default state.
open func styleStandard() {
listItemModel?.topPadding = 24
listItemModel?.bottomPadding = 24
topSeparatorView?.setStyle(.none)
bottomSeparatorView?.setStyle(.standard)
MFStyler.setMarginsFor(self, size: MVMCoreUIUtility.getWidth(), defaultHorizontal: true, top: Padding.Component.VerticalMarginSpacing, bottom: Padding.Component.VerticalMarginSpacing)
styleLine(with: .standard)
}
open func styleTallDivider() {
listItemModel?.topPadding = 48
listItemModel?.bottomPadding = 16
topSeparatorView?.setStyle(.none)
bottomSeparatorView?.setStyle(.thin)
}
open func styleShortDivider() {
listItemModel?.topPadding = 32
listItemModel?.bottomPadding = 16
topSeparatorView?.setStyle(.none)
bottomSeparatorView?.setStyle(.thin)
}
open func styleFooter() {
listItemModel?.topPadding = 24
listItemModel?.bottomPadding = 0
topSeparatorView?.setStyle(.none)
bottomSeparatorView?.setStyle(.none)
}
open func styleNone() {
listItemModel?.topPadding = 0
listItemModel?.bottomPadding = 0
topSeparatorView?.setStyle(.none)
bottomSeparatorView?.setStyle(.none)
}
/// Adds the molecule to the view.
open func addMolecule(_ molecule: MoleculeViewProtocol) {
contentView.addSubview(molecule)
@ -156,7 +129,7 @@ import UIKit
guard let model = model as? ListItemModelProtocol else { return }
self.listItemModel = model
style(with: model.style)
styleLine(with: model.style)
// Add the caret if there is an action and it's not declared hidden.
if !customAccessoryView {