Defaults, percent fix
This commit is contained in:
parent
7790a20ad3
commit
979718d4b8
@ -16,11 +16,33 @@ import Foundation
|
||||
enum FooterCodingKeys: String, CodingKey {
|
||||
case backgroundColor
|
||||
}
|
||||
|
||||
/// Defaults to set
|
||||
func setDefaults() {
|
||||
if useHorizontalMargins == nil {
|
||||
useHorizontalMargins = true
|
||||
}
|
||||
if useVerticalMargins == nil {
|
||||
useVerticalMargins = true
|
||||
}
|
||||
if topMarginPadding == nil {
|
||||
topMarginPadding = PaddingDefaultVerticalSpacing
|
||||
}
|
||||
if bottomMarginPadding == nil {
|
||||
bottomMarginPadding = PaddingDefaultVerticalSpacing
|
||||
}
|
||||
}
|
||||
|
||||
public override init(with moleculeModel: MoleculeProtocol) {
|
||||
super.init(with: moleculeModel)
|
||||
setDefaults()
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: FooterCodingKeys.self)
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
try super.init(from: decoder)
|
||||
setDefaults()
|
||||
}
|
||||
|
||||
public override func encode(to encoder: Encoder) throws {
|
||||
|
||||
@ -18,19 +18,34 @@ import Foundation
|
||||
case line
|
||||
case backgroundColor
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
try super.init(from: decoder)
|
||||
let typeContainer = try decoder.container(keyedBy: HeaderCodingKeys.self)
|
||||
line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line)
|
||||
|
||||
// Default Values
|
||||
|
||||
/// Defaults to set
|
||||
func setDefaults() {
|
||||
if useHorizontalMargins == nil {
|
||||
useHorizontalMargins = true
|
||||
}
|
||||
if useVerticalMargins == nil {
|
||||
useVerticalMargins = true
|
||||
}
|
||||
if topMarginPadding == nil {
|
||||
topMarginPadding = PaddingDefaultVerticalSpacing
|
||||
}
|
||||
if bottomMarginPadding == nil {
|
||||
bottomMarginPadding = PaddingDefaultVerticalSpacing
|
||||
}
|
||||
line?.type = .heavy
|
||||
}
|
||||
|
||||
public override init(with moleculeModel: MoleculeProtocol) {
|
||||
super.init(with: moleculeModel)
|
||||
setDefaults()
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
try super.init(from: decoder)
|
||||
let typeContainer = try decoder.container(keyedBy: HeaderCodingKeys.self)
|
||||
line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line)
|
||||
setDefaults()
|
||||
}
|
||||
|
||||
public override func encode(to encoder: Encoder) throws {
|
||||
|
||||
@ -24,6 +24,28 @@ import MVMCore
|
||||
case line
|
||||
case style
|
||||
}
|
||||
|
||||
/// Defaults to set
|
||||
func setDefaults() {
|
||||
style = "standard"
|
||||
if useHorizontalMargins == nil {
|
||||
useHorizontalMargins = true
|
||||
}
|
||||
if useVerticalMargins == nil {
|
||||
useVerticalMargins = true
|
||||
}
|
||||
if topMarginPadding == nil {
|
||||
topMarginPadding = 24
|
||||
}
|
||||
if bottomMarginPadding == nil {
|
||||
bottomMarginPadding = 24
|
||||
}
|
||||
}
|
||||
|
||||
public override init(with moleculeModel: MoleculeProtocol) {
|
||||
super.init(with: moleculeModel)
|
||||
setDefaults()
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: ListItemCodingKeys.self)
|
||||
@ -34,15 +56,8 @@ import MVMCore
|
||||
if let style = try typeContainer.decodeIfPresent(String.self, forKey: .style) {
|
||||
self.style = style
|
||||
}
|
||||
|
||||
try super.init(from: decoder)
|
||||
|
||||
if useHorizontalMargins == nil {
|
||||
useHorizontalMargins = true
|
||||
}
|
||||
if useVerticalMargins == nil {
|
||||
useVerticalMargins = true
|
||||
}
|
||||
setDefaults()
|
||||
}
|
||||
|
||||
public override func encode(to encoder: Encoder) throws {
|
||||
|
||||
@ -12,12 +12,12 @@ import Foundation
|
||||
public static var identifier: String = "stackItem"
|
||||
public var backgroundColor: Color?
|
||||
public var spacing: CGFloat?
|
||||
public var percentage: Int? = 0
|
||||
public var percent: Int?
|
||||
public var gone: Bool = false
|
||||
|
||||
enum MoleculeStackItemCodingKeys: String, CodingKey {
|
||||
case spacing
|
||||
case percentage
|
||||
case percent
|
||||
case gone
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ import Foundation
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: MoleculeStackItemCodingKeys.self)
|
||||
spacing = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .spacing)
|
||||
percentage = try typeContainer.decodeIfPresent(Int.self, forKey: .percentage)
|
||||
percent = try typeContainer.decodeIfPresent(Int.self, forKey: .percent)
|
||||
if let gone = try typeContainer.decodeIfPresent(Bool.self, forKey: .gone) {
|
||||
self.gone = gone
|
||||
}
|
||||
@ -39,7 +39,7 @@ import Foundation
|
||||
try super.encode(to: encoder)
|
||||
var container = encoder.container(keyedBy: MoleculeStackItemCodingKeys.self)
|
||||
try container.encodeIfPresent(spacing, forKey: .spacing)
|
||||
try container.encodeIfPresent(percentage, forKey: .percentage)
|
||||
try container.encodeIfPresent(percent, forKey: .percent)
|
||||
try container.encode(gone, forKey: .gone)
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,8 +222,8 @@ open class MoleculeStackView: Container {
|
||||
stackItem.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
let spacing = model.spacing ?? stackModel.spacing
|
||||
let verticalAlignment = model.verticalAlignment ?? (stackItem.view as? MVMCoreUIViewConstrainingProtocol)?.verticalAlignment?() ?? (model.percentage == nil && stackModel.axis == .vertical ? .fill : (stackModel.axis == .vertical ? .leading : .center))
|
||||
let horizontalAlignment = model.horizontalAlignment ?? (stackItem.view as? MVMCoreUIViewConstrainingProtocol)?.horizontalAlignment?() ?? (stackModel.axis == .vertical || model.percentage == nil ? .fill : .leading)
|
||||
let verticalAlignment = model.verticalAlignment ?? (stackItem.view as? MVMCoreUIViewConstrainingProtocol)?.verticalAlignment?() ?? (model.percent == nil && stackModel.axis == .vertical ? .fill : (stackModel.axis == .vertical ? .leading : .center))
|
||||
let horizontalAlignment = model.horizontalAlignment ?? (stackItem.view as? MVMCoreUIViewConstrainingProtocol)?.horizontalAlignment?() ?? (stackModel.axis == .vertical || model.percent == nil ? .fill : .leading)
|
||||
stackItem.containerHelper.alignHorizontal(horizontalAlignment)
|
||||
stackItem.containerHelper.alignVertical(verticalAlignment)
|
||||
|
||||
@ -238,7 +238,7 @@ open class MoleculeStackView: Container {
|
||||
}
|
||||
pinView(stackItem, toView: contentView, attribute: .leading, relation: .equal, priority: .required, constant: 0)
|
||||
pinView(contentView, toView: stackItem, attribute: .trailing, relation: .equal, priority: .required, constant: 0)
|
||||
if let percent = model.percentage {
|
||||
if let percent = model.percent {
|
||||
stackItem.heightAnchor.constraint(equalTo: contentView.heightAnchor, multiplier: CGFloat(percent)/100.0).isActive = true
|
||||
}
|
||||
if lastItem {
|
||||
@ -255,7 +255,7 @@ open class MoleculeStackView: Container {
|
||||
}
|
||||
pinView(stackItem, toView: contentView, attribute: .top, relation: .equal, priority: .required, constant: 0)
|
||||
pinView(contentView, toView: stackItem, attribute: .bottom, relation: .equal, priority: .required, constant: 0)
|
||||
if let percent = model.percentage {
|
||||
if let percent = model.percent {
|
||||
stackItem.widthAnchor.constraint(equalTo: contentView.widthAnchor, multiplier: CGFloat(percent)/100.0).isActive = true
|
||||
}
|
||||
if lastItem {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user