container protocol updates and container model
This commit is contained in:
parent
f7406c0bf9
commit
d3a73939f0
@ -120,6 +120,7 @@ import Foundation
|
|||||||
|
|
||||||
|
|
||||||
// Other Container Molecules
|
// Other Container Molecules
|
||||||
|
MoleculeObjectMapping.shared()?.register(viewClass: MoleculeContainer.self, viewModelClass: MoleculeContainerModel.self)
|
||||||
MoleculeObjectMapping.shared()?.register(viewClass: MoleculeHeaderView.self, viewModelClass: MoleculeHeaderModel.self)
|
MoleculeObjectMapping.shared()?.register(viewClass: MoleculeHeaderView.self, viewModelClass: MoleculeHeaderModel.self)
|
||||||
MoleculeObjectMapping.shared()?.register(viewClass: FooterView.self, viewModelClass: FooterModel.self)
|
MoleculeObjectMapping.shared()?.register(viewClass: FooterView.self, viewModelClass: FooterModel.self)
|
||||||
MoleculeObjectMapping.shared()?.register(viewClass: Scroller.self, viewModelClass: ScrollerModel.self)
|
MoleculeObjectMapping.shared()?.register(viewClass: Scroller.self, viewModelClass: ScrollerModel.self)
|
||||||
|
|||||||
@ -25,8 +25,8 @@ public class HeadersH2NoButtonsBodyTextModel: HeaderModel, MoleculeModelProtocol
|
|||||||
|
|
||||||
public override func setDefaults() {
|
public override func setDefaults() {
|
||||||
super.setDefaults()
|
super.setDefaults()
|
||||||
topMarginPadding = PaddingDefaultVerticalSpacing3
|
topPadding = PaddingDefaultVerticalSpacing3
|
||||||
bottomMarginPadding = PaddingDefaultVerticalSpacing3
|
bottomPadding = PaddingDefaultVerticalSpacing3
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -9,47 +9,24 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
|
||||||
@objcMembers public class FooterModel: MoleculeContainerModel, MoleculeModelProtocol {
|
@objcMembers public class FooterModel: MoleculeContainerModel {
|
||||||
public static var identifier: String = "footer"
|
public override class var identifier: String {
|
||||||
public var backgroundColor: Color?
|
return "footer"
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
|
||||||
case moleculeName
|
|
||||||
case backgroundColor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Defaults to set
|
/// Defaults to set
|
||||||
func setDefaults() {
|
public override func setDefaults() {
|
||||||
if useHorizontalMargins == nil {
|
if useHorizontalMargins == nil {
|
||||||
useHorizontalMargins = true
|
useHorizontalMargins = true
|
||||||
}
|
}
|
||||||
if useVerticalMargins == nil {
|
if useVerticalMargins == nil {
|
||||||
useVerticalMargins = true
|
useVerticalMargins = true
|
||||||
}
|
}
|
||||||
if topMarginPadding == nil {
|
if topPadding == nil {
|
||||||
topMarginPadding = PaddingDefaultVerticalSpacing
|
topPadding = PaddingDefaultVerticalSpacing
|
||||||
}
|
}
|
||||||
if bottomMarginPadding == nil {
|
if bottomPadding == nil {
|
||||||
bottomMarginPadding = PaddingDefaultVerticalSpacing
|
bottomPadding = PaddingDefaultVerticalSpacing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override init(with moleculeModel: MoleculeModelProtocol) {
|
|
||||||
super.init(with: moleculeModel)
|
|
||||||
setDefaults()
|
|
||||||
}
|
|
||||||
|
|
||||||
required public init(from decoder: Decoder) throws {
|
|
||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
|
||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
|
||||||
try super.init(from: decoder)
|
|
||||||
setDefaults()
|
|
||||||
}
|
|
||||||
|
|
||||||
public override func encode(to encoder: Encoder) throws {
|
|
||||||
try super.encode(to: encoder)
|
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,18 +18,18 @@ import Foundation
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Defaults to set
|
/// Defaults to set
|
||||||
public func setDefaults() {
|
public override func setDefaults() {
|
||||||
if useHorizontalMargins == nil {
|
if useHorizontalMargins == nil {
|
||||||
useHorizontalMargins = true
|
useHorizontalMargins = true
|
||||||
}
|
}
|
||||||
if useVerticalMargins == nil {
|
if useVerticalMargins == nil {
|
||||||
useVerticalMargins = true
|
useVerticalMargins = true
|
||||||
}
|
}
|
||||||
if topMarginPadding == nil {
|
if topPadding == nil {
|
||||||
topMarginPadding = PaddingDefaultVerticalSpacing
|
topPadding = PaddingDefaultVerticalSpacing
|
||||||
}
|
}
|
||||||
if bottomMarginPadding == nil {
|
if bottomPadding == nil {
|
||||||
bottomMarginPadding = PaddingDefaultVerticalSpacing
|
bottomPadding = PaddingDefaultVerticalSpacing
|
||||||
}
|
}
|
||||||
if line == nil {
|
if line == nil {
|
||||||
line = LineModel(type: .heavy)
|
line = LineModel(type: .heavy)
|
||||||
@ -38,7 +38,6 @@ import Foundation
|
|||||||
|
|
||||||
public override init() {
|
public override init() {
|
||||||
super.init()
|
super.init()
|
||||||
setDefaults()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
@ -46,7 +45,6 @@ import Foundation
|
|||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line)
|
line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line)
|
||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
setDefaults()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
|
|||||||
@ -38,7 +38,7 @@ import Foundation
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
/// Defaults to set
|
/// Defaults to set
|
||||||
open func setDefaults() {
|
open override func setDefaults() {
|
||||||
if useHorizontalMargins == nil {
|
if useHorizontalMargins == nil {
|
||||||
useHorizontalMargins = true
|
useHorizontalMargins = true
|
||||||
}
|
}
|
||||||
@ -54,9 +54,12 @@ import Foundation
|
|||||||
// MARK: - Initializer
|
// MARK: - Initializer
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
public override init() {
|
public override init() {
|
||||||
super.init()
|
super.init()
|
||||||
setDefaults()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -71,7 +74,6 @@ import Foundation
|
|||||||
line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line)
|
line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line)
|
||||||
style = try typeContainer.decodeIfPresent(String.self, forKey: .style)
|
style = try typeContainer.decodeIfPresent(String.self, forKey: .style)
|
||||||
try super.init(from: decoder)
|
try super.init(from: decoder)
|
||||||
setDefaults()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func encode(to encoder: Encoder) throws {
|
open override func encode(to encoder: Encoder) throws {
|
||||||
|
|||||||
@ -9,49 +9,36 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
/// A model for a collection item that is a container for any molecule.
|
/// A model for a collection item that is a container for any molecule.
|
||||||
@objcMembers public class MoleculeCollectionItemModel: MoleculeContainerModel, CollectionItemModelProtocol, MoleculeModelProtocol {
|
@objcMembers public class MoleculeCollectionItemModel: MoleculeContainerModel, CollectionItemModelProtocol {
|
||||||
open class var identifier: String {
|
open override class var identifier: String {
|
||||||
return "collectionItem"
|
return "collectionItem"
|
||||||
}
|
}
|
||||||
public var backgroundColor: Color?
|
|
||||||
|
|
||||||
/// Defaults to set
|
/// Defaults to set
|
||||||
public func setDefaults() {
|
public override func setDefaults() {
|
||||||
if useHorizontalMargins == nil {
|
if useHorizontalMargins == nil {
|
||||||
useHorizontalMargins = true
|
useHorizontalMargins = true
|
||||||
}
|
}
|
||||||
if useVerticalMargins == nil {
|
if useVerticalMargins == nil {
|
||||||
useVerticalMargins = true
|
useVerticalMargins = true
|
||||||
}
|
}
|
||||||
if topMarginPadding == nil {
|
if topPadding == nil {
|
||||||
topMarginPadding = PaddingDefault
|
topPadding = PaddingDefault
|
||||||
}
|
}
|
||||||
if bottomMarginPadding == nil {
|
if bottomPadding == nil {
|
||||||
bottomMarginPadding = PaddingDefault
|
bottomPadding = PaddingDefault
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
|
||||||
case moleculeName
|
|
||||||
case backgroundColor
|
|
||||||
}
|
|
||||||
|
|
||||||
public override init(with moleculeModel: MoleculeModelProtocol) {
|
public override init(with moleculeModel: MoleculeModelProtocol) {
|
||||||
super.init(with: moleculeModel)
|
super.init(with: moleculeModel)
|
||||||
setDefaults()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
|
||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
|
||||||
try super.init(from: decoder)
|
try super.init(from: decoder)
|
||||||
setDefaults()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
try super.encode(to: encoder)
|
try super.encode(to: encoder)
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,6 +54,6 @@ open class MoleculeCollectionViewCell: CollectionViewCell {
|
|||||||
let height = classType.estimatedHeight(with: model.molecule, delegateObject)
|
let height = classType.estimatedHeight(with: model.molecule, delegateObject)
|
||||||
else { return 100 }
|
else { return 100 }
|
||||||
|
|
||||||
return height + (model.topMarginPadding ?? 0) + (model.bottomMarginPadding ?? 0)
|
return height + (model.topPadding ?? 0) + (model.bottomPadding ?? 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,16 +8,15 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
@objcMembers public class MoleculeStackItemModel: MoleculeContainerModel, MoleculeModelProtocol, StackItemModelProtocol {
|
@objcMembers public class MoleculeStackItemModel: MoleculeContainerModel, StackItemModelProtocol {
|
||||||
public static var identifier: String = "stackItem"
|
public override class var identifier: String {
|
||||||
public var backgroundColor: Color?
|
return "stackItem"
|
||||||
|
}
|
||||||
public var spacing: CGFloat?
|
public var spacing: CGFloat?
|
||||||
public var percent: Int?
|
public var percent: Int?
|
||||||
public var gone: Bool = false
|
public var gone: Bool = false
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case moleculeName
|
|
||||||
case backgroundColor
|
|
||||||
case spacing
|
case spacing
|
||||||
case percent
|
case percent
|
||||||
case gone
|
case gone
|
||||||
@ -34,17 +33,14 @@ import Foundation
|
|||||||
if let gone = try typeContainer.decodeIfPresent(Bool.self, forKey: .gone) {
|
if let gone = try typeContainer.decodeIfPresent(Bool.self, forKey: .gone) {
|
||||||
self.gone = gone
|
self.gone = gone
|
||||||
}
|
}
|
||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
|
||||||
try super.init(from: decoder)
|
try super.init(from: decoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
try super.encode(to: encoder)
|
try super.encode(to: encoder)
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
|
||||||
try container.encodeIfPresent(spacing, forKey: .spacing)
|
try container.encodeIfPresent(spacing, forKey: .spacing)
|
||||||
try container.encodeIfPresent(percent, forKey: .percent)
|
try container.encodeIfPresent(percent, forKey: .percent)
|
||||||
try container.encode(gone, forKey: .gone)
|
try container.encode(gone, forKey: .gone)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,16 +24,17 @@ import Foundation
|
|||||||
// MARK: - Initializer
|
// MARK: - Initializer
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public convenience init(spacing: CGFloat? = nil, percent: Int? = nil, horizontalAlignment: UIStackView.Alignment? = nil, verticalAlignment: UIStackView.Alignment? = nil, gone: Bool? = nil) {
|
public init(spacing: CGFloat? = nil, percent: Int? = nil, horizontalAlignment: UIStackView.Alignment? = nil, verticalAlignment: UIStackView.Alignment? = nil, gone: Bool? = nil) {
|
||||||
self.init()
|
|
||||||
|
|
||||||
self.horizontalAlignment = horizontalAlignment
|
|
||||||
self.verticalAlignment = verticalAlignment
|
|
||||||
self.spacing = spacing
|
self.spacing = spacing
|
||||||
self.percent = percent
|
self.percent = percent
|
||||||
|
|
||||||
if let gone = gone {
|
if let gone = gone {
|
||||||
self.gone = gone
|
self.gone = gone
|
||||||
}
|
}
|
||||||
|
super.init(horizontalAlignment: horizontalAlignment, verticalAlignment: verticalAlignment)
|
||||||
|
}
|
||||||
|
|
||||||
|
required public init(from decoder: Decoder) throws {
|
||||||
|
fatalError("init(from:) has not been implemented")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,8 +24,8 @@ public class TabsListItemModel: ListItemModel, MoleculeModelProtocol {
|
|||||||
hideArrow = true
|
hideArrow = true
|
||||||
action = nil
|
action = nil
|
||||||
style = nil
|
style = nil
|
||||||
topMarginPadding = 8
|
topPadding = 8
|
||||||
bottomMarginPadding = 0
|
bottomPadding = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(with tabs: TabsModel, molecules: [[ListItemModelProtocol & MoleculeModelProtocol]]) {
|
public init(with tabs: TabsModel, molecules: [[ListItemModelProtocol & MoleculeModelProtocol]]) {
|
||||||
|
|||||||
@ -8,8 +8,9 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public class ScrollerModel: MoleculeContainerModel, MoleculeModelProtocol {
|
public class ScrollerModel: MoleculeContainerModel {
|
||||||
public static var identifier: String = "scroller"
|
public override class var identifier: String {
|
||||||
|
return "scroller"
|
||||||
|
}
|
||||||
public var moleculeName: String = ScrollerModel.identifier
|
public var moleculeName: String = ScrollerModel.identifier
|
||||||
public var backgroundColor: Color?
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,22 +20,21 @@ public class BGImageHeadlineBodyButtonModel: ContainerModel, MoleculeModelProtoc
|
|||||||
self.headlineBody = headlineBody
|
self.headlineBody = headlineBody
|
||||||
self.image = image
|
self.image = image
|
||||||
super.init()
|
super.init()
|
||||||
setDefaults()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Defaults to set
|
/// Defaults to set
|
||||||
func setDefaults() {
|
public override func setDefaults() {
|
||||||
if useHorizontalMargins == nil {
|
if useHorizontalMargins == nil {
|
||||||
useHorizontalMargins = true
|
useHorizontalMargins = true
|
||||||
}
|
}
|
||||||
if useVerticalMargins == nil {
|
if useVerticalMargins == nil {
|
||||||
useVerticalMargins = true
|
useVerticalMargins = true
|
||||||
}
|
}
|
||||||
if topMarginPadding == nil {
|
if topPadding == nil {
|
||||||
topMarginPadding = PaddingDefault
|
topPadding = PaddingDefault
|
||||||
}
|
}
|
||||||
if bottomMarginPadding == nil {
|
if bottomPadding == nil {
|
||||||
bottomMarginPadding = PaddingDefault
|
bottomPadding = PaddingDefault
|
||||||
}
|
}
|
||||||
if image.height == nil {
|
if image.height == nil {
|
||||||
image.height = BGImageHeadlineBodyButton.heightConstant
|
image.height = BGImageHeadlineBodyButton.heightConstant
|
||||||
@ -59,7 +58,6 @@ public class BGImageHeadlineBodyButtonModel: ContainerModel, MoleculeModelProtoc
|
|||||||
image = try typeContainer.decode(ImageViewModel.self, forKey: .image)
|
image = try typeContainer.decode(ImageViewModel.self, forKey: .image)
|
||||||
button = try typeContainer.decodeIfPresent(ButtonModel.self, forKey: .button)
|
button = try typeContainer.decodeIfPresent(ButtonModel.self, forKey: .button)
|
||||||
try super.init(from: decoder)
|
try super.init(from: decoder)
|
||||||
setDefaults()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
|
|||||||
@ -19,22 +19,21 @@ public class HeadlineBodyCaretLinkImageModel: ContainerModel, MoleculeModelProto
|
|||||||
self.headlineBody = headlineBody
|
self.headlineBody = headlineBody
|
||||||
self.image = image
|
self.image = image
|
||||||
super.init()
|
super.init()
|
||||||
setDefaults()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Defaults to set
|
/// Defaults to set
|
||||||
func setDefaults() {
|
public override func setDefaults() {
|
||||||
if useHorizontalMargins == nil {
|
if useHorizontalMargins == nil {
|
||||||
useHorizontalMargins = true
|
useHorizontalMargins = true
|
||||||
}
|
}
|
||||||
if useVerticalMargins == nil {
|
if useVerticalMargins == nil {
|
||||||
useVerticalMargins = true
|
useVerticalMargins = true
|
||||||
}
|
}
|
||||||
if topMarginPadding == nil {
|
if topPadding == nil {
|
||||||
topMarginPadding = PaddingDefault
|
topPadding = PaddingDefault
|
||||||
}
|
}
|
||||||
if bottomMarginPadding == nil {
|
if bottomPadding == nil {
|
||||||
bottomMarginPadding = PaddingDefault
|
bottomPadding = PaddingDefault
|
||||||
}
|
}
|
||||||
if image.height == nil {
|
if image.height == nil {
|
||||||
image.height = HeadLineBodyCaretLinkImage.heightConstant
|
image.height = HeadLineBodyCaretLinkImage.heightConstant
|
||||||
@ -56,7 +55,6 @@ public class HeadlineBodyCaretLinkImageModel: ContainerModel, MoleculeModelProto
|
|||||||
image = try typeContainer.decode(ImageViewModel.self, forKey: .image)
|
image = try typeContainer.decode(ImageViewModel.self, forKey: .image)
|
||||||
caretLink = try typeContainer.decodeIfPresent(CaretLinkModel.self, forKey: .caretLink)
|
caretLink = try typeContainer.decodeIfPresent(CaretLinkModel.self, forKey: .caretLink)
|
||||||
try super.init(from: decoder)
|
try super.init(from: decoder)
|
||||||
setDefaults()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
|
|||||||
@ -11,10 +11,12 @@ import Foundation
|
|||||||
|
|
||||||
public protocol ContainerModelProtocol {
|
public protocol ContainerModelProtocol {
|
||||||
var horizontalAlignment: UIStackView.Alignment? { get set }
|
var horizontalAlignment: UIStackView.Alignment? { get set }
|
||||||
var verticalAlignment: UIStackView.Alignment? { get set }
|
|
||||||
var useHorizontalMargins: Bool? { get set }
|
var useHorizontalMargins: Bool? { get set }
|
||||||
|
var leftPadding: CGFloat? { get set }
|
||||||
|
var rightPadding: CGFloat? { get set }
|
||||||
|
|
||||||
|
var verticalAlignment: UIStackView.Alignment? { get set }
|
||||||
var useVerticalMargins: Bool? { get set }
|
var useVerticalMargins: Bool? { get set }
|
||||||
var topMarginPadding: CGFloat? { get set }
|
var topPadding: CGFloat? { get set }
|
||||||
var bottomMarginPadding: CGFloat? { get set }
|
var bottomPadding: CGFloat? { get set }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,36 +51,36 @@ import UIKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
open func styleStandard() {
|
open func styleStandard() {
|
||||||
listItemModel?.topMarginPadding = 24
|
listItemModel?.topPadding = 24
|
||||||
listItemModel?.bottomMarginPadding = 24
|
listItemModel?.bottomPadding = 24
|
||||||
topSeparatorView?.setStyle(.none)
|
topSeparatorView?.setStyle(.none)
|
||||||
bottomSeparatorView?.setStyle(.standard)
|
bottomSeparatorView?.setStyle(.standard)
|
||||||
}
|
}
|
||||||
|
|
||||||
open func styleTallDivider() {
|
open func styleTallDivider() {
|
||||||
listItemModel?.topMarginPadding = 48
|
listItemModel?.topPadding = 48
|
||||||
listItemModel?.bottomMarginPadding = 16
|
listItemModel?.bottomPadding = 16
|
||||||
topSeparatorView?.setStyle(.none)
|
topSeparatorView?.setStyle(.none)
|
||||||
bottomSeparatorView?.setStyle(.thin)
|
bottomSeparatorView?.setStyle(.thin)
|
||||||
}
|
}
|
||||||
|
|
||||||
open func styleShortDivider() {
|
open func styleShortDivider() {
|
||||||
listItemModel?.topMarginPadding = 32
|
listItemModel?.topPadding = 32
|
||||||
listItemModel?.bottomMarginPadding = 16
|
listItemModel?.bottomPadding = 16
|
||||||
topSeparatorView?.setStyle(.none)
|
topSeparatorView?.setStyle(.none)
|
||||||
bottomSeparatorView?.setStyle(.thin)
|
bottomSeparatorView?.setStyle(.thin)
|
||||||
}
|
}
|
||||||
|
|
||||||
open func styleFooter() {
|
open func styleFooter() {
|
||||||
listItemModel?.topMarginPadding = 24
|
listItemModel?.topPadding = 24
|
||||||
listItemModel?.bottomMarginPadding = 0
|
listItemModel?.bottomPadding = 0
|
||||||
topSeparatorView?.setStyle(.none)
|
topSeparatorView?.setStyle(.none)
|
||||||
bottomSeparatorView?.setStyle(.none)
|
bottomSeparatorView?.setStyle(.none)
|
||||||
}
|
}
|
||||||
|
|
||||||
open func styleNone() {
|
open func styleNone() {
|
||||||
listItemModel?.topMarginPadding = 0
|
listItemModel?.topPadding = 0
|
||||||
listItemModel?.bottomMarginPadding = 0
|
listItemModel?.bottomPadding = 0
|
||||||
topSeparatorView?.setStyle(.none)
|
topSeparatorView?.setStyle(.none)
|
||||||
bottomSeparatorView?.setStyle(.none)
|
bottomSeparatorView?.setStyle(.none)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -169,8 +169,15 @@ open class ContainerHelper: NSObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Updates the view margins according to model and size. If useHorizontalMargins is true, we will try to use the left and right padding, else we will default to the normal gutters. If useVerticalMargins is true, we will try to use the top and bottom padding. All else, we use zero.
|
||||||
open func updateViewMargins(_ view: UIView, model: ContainerModelProtocol?, size: CGFloat) {
|
open func updateViewMargins(_ view: UIView, model: ContainerModelProtocol?, size: CGFloat) {
|
||||||
MFStyler.setMarginsFor(view, size: size, defaultHorizontal: model?.useHorizontalMargins ?? false, top: (model?.useVerticalMargins ?? false) ? (model?.topMarginPadding ?? 0) : 0, bottom: (model?.useVerticalMargins ?? false) ? (model?.bottomMarginPadding ?? 0) : 0)
|
let left = (model?.useHorizontalMargins ?? false) ? (model?.leftPadding ?? Padding.Component.horizontalPaddingForSize(size)) : 0.0
|
||||||
|
let right = (model?.useHorizontalMargins ?? false) ? (model?.rightPadding ?? Padding.Component.horizontalPaddingForSize(size)) : 0.0
|
||||||
|
let top = (model?.useVerticalMargins ?? false) ? (model?.topPadding ?? 0.0) : 0.0
|
||||||
|
let bottom = (model?.useVerticalMargins ?? false) ? (model?.bottomPadding ?? 0.0) : 0.0
|
||||||
|
MVMCoreDispatchUtility.performBlock(onMainThread: {
|
||||||
|
MVMCoreUIUtility.setMarginsFor(view, leading: left, top: top, trailing: right, bottom: bottom)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
open func set(with model: ContainerModelProtocol, for contained: MVMCoreUIViewConstrainingProtocol?) {
|
open func set(with model: ContainerModelProtocol, for contained: MVMCoreUIViewConstrainingProtocol?) {
|
||||||
|
|||||||
@ -9,41 +9,61 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
open class ContainerModel: ContainerModelProtocol, Codable {
|
open class ContainerModel: ContainerModelProtocol, Codable {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public var horizontalAlignment: UIStackView.Alignment?
|
public var horizontalAlignment: UIStackView.Alignment?
|
||||||
public var verticalAlignment: UIStackView.Alignment?
|
|
||||||
public var useHorizontalMargins: Bool?
|
public var useHorizontalMargins: Bool?
|
||||||
|
public var leftPadding: CGFloat?
|
||||||
|
public var rightPadding: CGFloat?
|
||||||
|
|
||||||
|
public var verticalAlignment: UIStackView.Alignment?
|
||||||
public var useVerticalMargins: Bool?
|
public var useVerticalMargins: Bool?
|
||||||
public var topMarginPadding: CGFloat?
|
public var topPadding: CGFloat?
|
||||||
public var bottomMarginPadding: CGFloat?
|
public var bottomPadding: CGFloat?
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Keys
|
// MARK: - Keys
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case verticalAlignment
|
|
||||||
case horizontalAlignment
|
case horizontalAlignment
|
||||||
case useHorizontalMargins
|
case useHorizontalMargins
|
||||||
|
case leftPadding
|
||||||
|
case rightPadding
|
||||||
|
case verticalAlignment
|
||||||
case useVerticalMargins
|
case useVerticalMargins
|
||||||
case topMarginPadding
|
case topPadding
|
||||||
case bottomMarginPadding
|
case bottomPadding
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Subclassable
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
/// Sets the default values. Should be called on init.
|
||||||
|
public func setDefaults() {}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public init() {}
|
public init() {
|
||||||
|
setDefaults()
|
||||||
|
}
|
||||||
|
|
||||||
public convenience init(horizontalAlignment: UIStackView.Alignment? = nil, verticalAlignment: UIStackView.Alignment? = nil) {
|
public 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) {
|
||||||
self.init()
|
|
||||||
self.horizontalAlignment = horizontalAlignment
|
self.horizontalAlignment = horizontalAlignment
|
||||||
self.verticalAlignment = verticalAlignment
|
self.verticalAlignment = verticalAlignment
|
||||||
|
self.useHorizontalMargins = useHorizontalMargins
|
||||||
|
self.leftPadding = leftPadding
|
||||||
|
self.rightPadding = rightPadding
|
||||||
|
self.useVerticalMargins = useVerticalMargins
|
||||||
|
self.topPadding = topPadding
|
||||||
|
self.bottomPadding = bottomPadding
|
||||||
|
setDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -59,9 +79,12 @@ open class ContainerModel: ContainerModelProtocol, Codable {
|
|||||||
horizontalAlignment = ContainerHelper.getAlignment(for: horizontalAlignmentString)
|
horizontalAlignment = ContainerHelper.getAlignment(for: horizontalAlignmentString)
|
||||||
}
|
}
|
||||||
useHorizontalMargins = try typeContainer.decodeIfPresent(Bool.self, forKey: .useHorizontalMargins)
|
useHorizontalMargins = try typeContainer.decodeIfPresent(Bool.self, forKey: .useHorizontalMargins)
|
||||||
|
leftPadding = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .leftPadding)
|
||||||
|
rightPadding = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .rightPadding)
|
||||||
useVerticalMargins = try typeContainer.decodeIfPresent(Bool.self, forKey: .useVerticalMargins)
|
useVerticalMargins = try typeContainer.decodeIfPresent(Bool.self, forKey: .useVerticalMargins)
|
||||||
topMarginPadding = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .topMarginPadding)
|
topPadding = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .topPadding)
|
||||||
bottomMarginPadding = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .bottomMarginPadding)
|
bottomPadding = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .bottomPadding)
|
||||||
|
setDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
open func encode(to encoder: Encoder) throws {
|
open func encode(to encoder: Encoder) throws {
|
||||||
@ -69,9 +92,10 @@ open class ContainerModel: ContainerModelProtocol, Codable {
|
|||||||
try container.encodeIfPresent(ContainerHelper.getAlignmentString(for: verticalAlignment), forKey: .verticalAlignment)
|
try container.encodeIfPresent(ContainerHelper.getAlignmentString(for: verticalAlignment), forKey: .verticalAlignment)
|
||||||
try container.encodeIfPresent(ContainerHelper.getAlignmentString(for: horizontalAlignment), forKey: .horizontalAlignment)
|
try container.encodeIfPresent(ContainerHelper.getAlignmentString(for: horizontalAlignment), forKey: .horizontalAlignment)
|
||||||
try container.encodeIfPresent(useHorizontalMargins, forKey: .useHorizontalMargins)
|
try container.encodeIfPresent(useHorizontalMargins, forKey: .useHorizontalMargins)
|
||||||
|
try container.encodeIfPresent(leftPadding, forKey: .leftPadding)
|
||||||
|
try container.encodeIfPresent(rightPadding, forKey: .rightPadding)
|
||||||
try container.encodeIfPresent(useVerticalMargins, forKey: .useVerticalMargins)
|
try container.encodeIfPresent(useVerticalMargins, forKey: .useVerticalMargins)
|
||||||
// TODO: can add this back once we have type erasures.
|
try container.encodeIfPresent(topPadding, forKey: .topPadding)
|
||||||
//try container.encodeIfPresent(topMarginPadding, forKey: .topMarginPadding)
|
try container.encodeIfPresent(bottomPadding, forKey: .bottomPadding)
|
||||||
//try container.encodeIfPresent(bottomMarginPadding, forKey: .bottomMarginPadding)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,9 +41,9 @@ open class MoleculeContainer: Container {
|
|||||||
guard let containerModel = model as? MoleculeContainerModelProtocol else { return 0 }
|
guard let containerModel = model as? MoleculeContainerModelProtocol else { return 0 }
|
||||||
guard let moleculeClass = MoleculeObjectMapping.shared()?.getMoleculeClass(containerModel.molecule),
|
guard let moleculeClass = MoleculeObjectMapping.shared()?.getMoleculeClass(containerModel.molecule),
|
||||||
let moleculeHeight = moleculeClass.estimatedHeight(with: containerModel.molecule, delegateObject) else {
|
let moleculeHeight = moleculeClass.estimatedHeight(with: containerModel.molecule, delegateObject) else {
|
||||||
return (containerModel.topMarginPadding ?? 0) + (containerModel.bottomMarginPadding ?? 0)
|
return (containerModel.topPadding ?? 0) + (containerModel.bottomPadding ?? 0)
|
||||||
}
|
}
|
||||||
return moleculeHeight + (containerModel.topMarginPadding ?? 0) + (containerModel.bottomMarginPadding ?? 0)
|
return moleculeHeight + (containerModel.topPadding ?? 0) + (containerModel.bottomPadding ?? 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
|
public override class func requiredModules(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
|
||||||
|
|||||||
@ -8,11 +8,17 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public class MoleculeContainerModel: ContainerModel, MoleculeContainerModelProtocol {
|
public class MoleculeContainerModel: ContainerModel, MoleculeContainerModelProtocol, MoleculeModelProtocol {
|
||||||
|
public class var identifier: String {
|
||||||
|
return "container"
|
||||||
|
}
|
||||||
|
public var backgroundColor: Color?
|
||||||
public var molecule: MoleculeModelProtocol
|
public var molecule: MoleculeModelProtocol
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
case moleculeName
|
||||||
case molecule
|
case molecule
|
||||||
|
case backgroundColor
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(with moleculeModel: MoleculeModelProtocol) {
|
public init(with moleculeModel: MoleculeModelProtocol) {
|
||||||
@ -23,12 +29,15 @@ public class MoleculeContainerModel: ContainerModel, MoleculeContainerModelProto
|
|||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
molecule = try typeContainer.decodeModel(codingKey: .molecule)
|
molecule = try typeContainer.decodeModel(codingKey: .molecule)
|
||||||
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
try super.init(from: decoder)
|
try super.init(from: decoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
try super.encode(to: encoder)
|
try super.encode(to: encoder)
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try container.encode(moleculeName, forKey: .moleculeName)
|
||||||
try container.encodeModel(molecule, forKey: .molecule)
|
try container.encodeModel(molecule, forKey: .molecule)
|
||||||
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user