style in model for list item
This commit is contained in:
parent
4c0cf1ae28
commit
573d6b2a98
@ -33,10 +33,9 @@ public class ListTwoColumnPriceDetailsModel: ListItemModel, MoleculeModelProtoco
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
override public func setDefaults() {
|
override public func setDefaults() {
|
||||||
|
style = ListItemStyle.none
|
||||||
super.setDefaults()
|
super.setDefaults()
|
||||||
|
|
||||||
style = "none"
|
|
||||||
|
|
||||||
if leftLabel.textColor == nil {
|
if leftLabel.textColor == nil {
|
||||||
leftLabel.textColor = Color(uiColor: .mvmCoolGray6)
|
leftLabel.textColor = Color(uiColor: .mvmCoolGray6)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,8 +33,8 @@ public class ListFourColumnDataUsageDividerModel: ListItemModel, MoleculeModelPr
|
|||||||
}
|
}
|
||||||
|
|
||||||
override public func setDefaults() {
|
override public func setDefaults() {
|
||||||
|
style = .tallDivider
|
||||||
super.setDefaults()
|
super.setDefaults()
|
||||||
style = "tallDivider"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -33,8 +33,8 @@ public class ListOneColumnFullWidthTextDividerSubsectionModel: ListItemModel, Mo
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
override public func setDefaults() {
|
override public func setDefaults() {
|
||||||
|
style = .tallDivider
|
||||||
super.setDefaults()
|
super.setDefaults()
|
||||||
style = "tallDivider"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -33,8 +33,8 @@ public class ListOneColumnTextWithWhitespaceDividerShortModel: ListItemModel, Mo
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
override public func setDefaults() {
|
override public func setDefaults() {
|
||||||
|
style = .shortDivider
|
||||||
super.setDefaults()
|
super.setDefaults()
|
||||||
style = "shortDivider"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -33,8 +33,8 @@ public class ListOneColumnTextWithWhitespaceDividerTallModel: ListItemModel, Mol
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
override public func setDefaults() {
|
override public func setDefaults() {
|
||||||
|
style = .tallDivider
|
||||||
super.setDefaults()
|
super.setDefaults()
|
||||||
style = "tallDivider"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -35,8 +35,8 @@ public class ListThreeColumnBillChangesDividerModel: ListItemModel, MoleculeMode
|
|||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
|
|
||||||
override public func setDefaults() {
|
override public func setDefaults() {
|
||||||
|
style = .tallDivider
|
||||||
super.setDefaults()
|
super.setDefaults()
|
||||||
style = "tallDivider"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
|
|||||||
@ -35,8 +35,8 @@ public class ListThreeColumnDataUsageDividerModel: ListItemModel, MoleculeModelP
|
|||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
|
|
||||||
override public func setDefaults() {
|
override public func setDefaults() {
|
||||||
|
style = .tallDivider
|
||||||
super.setDefaults()
|
super.setDefaults()
|
||||||
style = "tallDivider"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
|
|||||||
@ -35,8 +35,8 @@ public class ListThreeColumnInternationalDataDividerModel: ListItemModel, Molecu
|
|||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
override public func setDefaults() {
|
override public func setDefaults() {
|
||||||
|
style = .tallDivider
|
||||||
super.setDefaults()
|
super.setDefaults()
|
||||||
style = "tallDivider"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|||||||
@ -35,8 +35,8 @@ public class ListThreeColumnPlanDataDividerModel: ListItemModel, MoleculeModelPr
|
|||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
|
|
||||||
override public func setDefaults() {
|
override public func setDefaults() {
|
||||||
|
style = .tallDivider
|
||||||
super.setDefaults()
|
super.setDefaults()
|
||||||
style = "tallDivider"
|
|
||||||
leftHeadlineBody.style = .itemHeader
|
leftHeadlineBody.style = .itemHeader
|
||||||
centerHeadlineBody.style = .itemHeader
|
centerHeadlineBody.style = .itemHeader
|
||||||
rightHeadlineBody.style = .itemHeader
|
rightHeadlineBody.style = .itemHeader
|
||||||
|
|||||||
@ -35,8 +35,8 @@ public class ListThreeColumnSpeedTestDividerModel: ListItemModel, MoleculeModelP
|
|||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
|
|
||||||
override public func setDefaults() {
|
override public func setDefaults() {
|
||||||
|
style = .tallDivider
|
||||||
super.setDefaults()
|
super.setDefaults()
|
||||||
style = "tallDivider"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
|
|||||||
@ -33,8 +33,8 @@ public class ListTwoColumnSubsectionDividerModel: ListItemModel, MoleculeModelPr
|
|||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
override public func setDefaults() {
|
override public func setDefaults() {
|
||||||
|
style = .tallDivider
|
||||||
super.setDefaults()
|
super.setDefaults()
|
||||||
style = "tallDivider"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|||||||
@ -24,10 +24,10 @@ import Foundation
|
|||||||
|
|
||||||
/// Defaults to set
|
/// Defaults to set
|
||||||
public override func setDefaults() {
|
public override func setDefaults() {
|
||||||
|
style = .sectionFooter
|
||||||
super.setDefaults()
|
super.setDefaults()
|
||||||
hideArrow = true
|
hideArrow = true
|
||||||
line = LineModel(type: .none)
|
line = LineModel(type: .none)
|
||||||
style = "sectionFooter"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import Foundation
|
|||||||
|
|
||||||
|
|
||||||
@objcMembers open class ListItemModel: ContainerModel, ListItemModelProtocol {
|
@objcMembers open class ListItemModel: ContainerModel, ListItemModelProtocol {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -19,7 +20,7 @@ import Foundation
|
|||||||
public var action: ActionModelProtocol?
|
public var action: ActionModelProtocol?
|
||||||
public var hideArrow: Bool?
|
public var hideArrow: Bool?
|
||||||
public var line: LineModel?
|
public var line: LineModel?
|
||||||
public var style: String?
|
public var style: ListItemStyle? = .standard
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Keys
|
// MARK: - Keys
|
||||||
@ -39,17 +40,39 @@ import Foundation
|
|||||||
|
|
||||||
/// Defaults to set
|
/// Defaults to set
|
||||||
open override func setDefaults() {
|
open override func setDefaults() {
|
||||||
if useHorizontalMargins == nil {
|
setByStyle()
|
||||||
useHorizontalMargins = true
|
}
|
||||||
|
|
||||||
|
/// 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 {
|
if self.useVerticalMargins == nil {
|
||||||
useVerticalMargins = true
|
self.useVerticalMargins = useVerticalMargins
|
||||||
}
|
}
|
||||||
if topPadding == nil {
|
if self.topPadding == nil {
|
||||||
topPadding = 24
|
self.topPadding = topPadding
|
||||||
}
|
}
|
||||||
if bottomPadding == nil {
|
if self.bottomPadding == nil {
|
||||||
bottomPadding = 24
|
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
|
// 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) {
|
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)
|
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)
|
action = try typeContainer.decodeModelIfPresent(codingKey: .action)
|
||||||
hideArrow = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideArrow)
|
hideArrow = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideArrow)
|
||||||
line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line)
|
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)
|
try super.init(from: decoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,12 +8,19 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
public enum ListItemStyle: String, Codable {
|
||||||
|
case standard
|
||||||
|
case shortDivider
|
||||||
|
case tallDivider
|
||||||
|
case sectionFooter
|
||||||
|
case none
|
||||||
|
}
|
||||||
|
|
||||||
public protocol ListItemModelProtocol: ContainerModelProtocol {
|
public protocol ListItemModelProtocol: ContainerModelProtocol {
|
||||||
var line: LineModel? { get set }
|
var line: LineModel? { get set }
|
||||||
var action: ActionModelProtocol? { get set }
|
var action: ActionModelProtocol? { get set }
|
||||||
var hideArrow: Bool? { get set }
|
var hideArrow: Bool? { get set }
|
||||||
var style: String? { get set }
|
var style: ListItemStyle? { get set }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not a strict requirement.
|
// Not a strict requirement.
|
||||||
@ -24,7 +31,7 @@ public extension ListItemModelProtocol {
|
|||||||
set { }
|
set { }
|
||||||
}
|
}
|
||||||
|
|
||||||
var style: String? {
|
var style: ListItemStyle? {
|
||||||
get { return nil }
|
get { return nil }
|
||||||
set { }
|
set { }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,60 +31,33 @@ import UIKit
|
|||||||
private var initialSetupPerformed = false
|
private var initialSetupPerformed = false
|
||||||
|
|
||||||
// MARK: - Styling
|
// MARK: - Styling
|
||||||
open func style(with styleString: String?) {
|
open func styleLine(with style: ListItemStyle?) {
|
||||||
guard let styleString = styleString else {
|
switch style {
|
||||||
return
|
case .standard?:
|
||||||
}
|
topSeparatorView?.setStyle(.none)
|
||||||
switch styleString {
|
bottomSeparatorView?.setStyle(.standard)
|
||||||
case "standard":
|
case .shortDivider?:
|
||||||
styleStandard()
|
topSeparatorView?.setStyle(.none)
|
||||||
case "shortDivider":
|
bottomSeparatorView?.setStyle(.thin)
|
||||||
styleShortDivider()
|
case .tallDivider?:
|
||||||
case "tallDivider":
|
topSeparatorView?.setStyle(.none)
|
||||||
styleTallDivider()
|
bottomSeparatorView?.setStyle(.thin)
|
||||||
case "sectionFooter":
|
case .sectionFooter?:
|
||||||
styleFooter()
|
topSeparatorView?.setStyle(.none)
|
||||||
case "none":
|
bottomSeparatorView?.setStyle(.none)
|
||||||
styleNone()
|
case ListItemStyle.none?:
|
||||||
|
topSeparatorView?.setStyle(.none)
|
||||||
|
bottomSeparatorView?.setStyle(.none)
|
||||||
default: break
|
default: break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Default state.
|
||||||
open func styleStandard() {
|
open func styleStandard() {
|
||||||
listItemModel?.topPadding = 24
|
MFStyler.setMarginsFor(self, size: MVMCoreUIUtility.getWidth(), defaultHorizontal: true, top: Padding.Component.VerticalMarginSpacing, bottom: Padding.Component.VerticalMarginSpacing)
|
||||||
listItemModel?.bottomPadding = 24
|
styleLine(with: .standard)
|
||||||
topSeparatorView?.setStyle(.none)
|
|
||||||
bottomSeparatorView?.setStyle(.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.
|
/// Adds the molecule to the view.
|
||||||
open func addMolecule(_ molecule: MoleculeViewProtocol) {
|
open func addMolecule(_ molecule: MoleculeViewProtocol) {
|
||||||
contentView.addSubview(molecule)
|
contentView.addSubview(molecule)
|
||||||
@ -156,7 +129,7 @@ import UIKit
|
|||||||
guard let model = model as? ListItemModelProtocol else { return }
|
guard let model = model as? ListItemModelProtocol else { return }
|
||||||
|
|
||||||
self.listItemModel = model
|
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.
|
// Add the caret if there is an action and it's not declared hidden.
|
||||||
if !customAccessoryView {
|
if !customAccessoryView {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user