Using stack as per review comments
This commit is contained in:
parent
22285dda62
commit
3f1e37c878
@ -12,14 +12,13 @@ import Foundation
|
|||||||
let wheel = GraphView(frame: .zero)
|
let wheel = GraphView(frame: .zero)
|
||||||
let leftLabel = Label(frame: .zero)
|
let leftLabel = Label(frame: .zero)
|
||||||
let rightLabel = Label(frame: .zero)
|
let rightLabel = Label(frame: .zero)
|
||||||
|
let stack = Stack<StackModel>(frame: .zero)
|
||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
// MARK: - View Cycle
|
// MARK: - View Cycle
|
||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
open override func updateView(_ size: CGFloat) {
|
open override func updateView(_ size: CGFloat) {
|
||||||
super.updateView(size)
|
super.updateView(size)
|
||||||
wheel.updateView(size)
|
stack.updateView(size)
|
||||||
leftLabel.updateView(size)
|
|
||||||
rightLabel.updateView(size)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
@ -27,39 +26,10 @@ import Foundation
|
|||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
open override func setupView() {
|
open override func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
guard leftLabel.superview == nil else {
|
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||||
return
|
stack.stackItems = [StackItem(andContain: leftLabel),StackItem(andContain: wheel),StackItem(andContain: rightLabel)]
|
||||||
}
|
contentView.addSubview(stack)
|
||||||
contentView.addSubview(wheel)
|
containerHelper.constrainView(stack)
|
||||||
contentView.addSubview(leftLabel)
|
|
||||||
contentView.addSubview(rightLabel)
|
|
||||||
NSLayoutConstraint.constraintPinSubview(toSuperview: contentView)
|
|
||||||
contentView.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
|
|
||||||
//-------------------------------------------------
|
|
||||||
// MARK: - Constraining
|
|
||||||
//-------------------------------------------------
|
|
||||||
self.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
NSLayoutConstraint.activate([
|
|
||||||
leftLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
|
|
||||||
leftLabel.topAnchor.constraint(equalTo: contentView.topAnchor),
|
|
||||||
leftLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
|
||||||
leftLabel.widthAnchor.constraint(equalTo: contentView.widthAnchor, multiplier: 0.3)
|
|
||||||
])
|
|
||||||
NSLayoutConstraint.activate([
|
|
||||||
wheel.topAnchor.constraint(equalTo: contentView.topAnchor),
|
|
||||||
wheel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
|
||||||
])
|
|
||||||
|
|
||||||
let rightLabelTrailing = rightLabel.trailingAnchor.constraint(greaterThanOrEqualTo: contentView.trailingAnchor)
|
|
||||||
rightLabelTrailing.priority = UILayoutPriority(900)
|
|
||||||
NSLayoutConstraint.activate([
|
|
||||||
rightLabelTrailing,
|
|
||||||
rightLabel.leadingAnchor.constraint(equalTo: wheel.trailingAnchor),
|
|
||||||
rightLabel.widthAnchor.constraint(equalTo: contentView.widthAnchor, multiplier: 0.32),
|
|
||||||
rightLabel.topAnchor.constraint(equalTo: contentView.topAnchor),
|
|
||||||
rightLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
|
|
||||||
])
|
|
||||||
}
|
}
|
||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||||
@ -70,6 +40,19 @@ import Foundation
|
|||||||
leftLabel.setWithModel(model.leftLabel, delegateObject, additionalData)
|
leftLabel.setWithModel(model.leftLabel, delegateObject, additionalData)
|
||||||
rightLabel.setWithModel(model.rightLabel, delegateObject, additionalData)
|
rightLabel.setWithModel(model.rightLabel, delegateObject, additionalData)
|
||||||
wheel.setWithModel(model.wheel, delegateObject, additionalData)
|
wheel.setWithModel(model.wheel, delegateObject, additionalData)
|
||||||
|
|
||||||
|
// Create a stack model to use for the internal stack and set the alignment of models
|
||||||
|
let leftHeadlineBodyAlignment = StackItemModel(percent: 55)
|
||||||
|
leftHeadlineBodyAlignment.horizontalAlignment = .leading
|
||||||
|
|
||||||
|
let centerHeadLineBodyAlignment = StackItemModel(percent: 20)
|
||||||
|
centerHeadLineBodyAlignment.horizontalAlignment = .trailing
|
||||||
|
let rightHeadLineBodyAlignment = StackItemModel(percent: 25)
|
||||||
|
rightHeadLineBodyAlignment.horizontalAlignment = .trailing
|
||||||
|
let stackModel = StackModel(molecules: [leftHeadlineBodyAlignment,centerHeadLineBodyAlignment,rightHeadLineBodyAlignment])
|
||||||
|
stackModel.axis = .horizontal
|
||||||
|
stack.model = stackModel
|
||||||
|
stack.restack()
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
@ -77,9 +60,7 @@ import Foundation
|
|||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
open override func reset() {
|
open override func reset() {
|
||||||
super.reset()
|
super.reset()
|
||||||
leftLabel.reset()
|
stack.reset()
|
||||||
rightLabel.reset()
|
|
||||||
wheel.reset()
|
|
||||||
}
|
}
|
||||||
public override class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
public override class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||||
return 43
|
return 43
|
||||||
|
|||||||
@ -7,8 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
public class ListRVWheelModel:MoleculeModelProtocol {
|
public class ListRVWheelModel:ListItemModel,MoleculeModelProtocol {
|
||||||
public var backgroundColor: Color?
|
|
||||||
public static var identifier: String = "listRVWheel"
|
public static var identifier: String = "listRVWheel"
|
||||||
public var leftLabel: LabelModel?
|
public var leftLabel: LabelModel?
|
||||||
public var rightLabel: LabelModel?
|
public var rightLabel: LabelModel?
|
||||||
@ -17,20 +16,26 @@ public class ListRVWheelModel:MoleculeModelProtocol {
|
|||||||
self.leftLabel = leftLabel
|
self.leftLabel = leftLabel
|
||||||
self.rightLabel = rightLabel
|
self.rightLabel = rightLabel
|
||||||
self.wheel = wheel
|
self.wheel = wheel
|
||||||
|
super.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum CodingKeys: String,CodingKey {
|
private enum CodingKeys: String,CodingKey {
|
||||||
case moleculeName
|
case moleculeName
|
||||||
case leftLabel
|
case leftLabel
|
||||||
case rightLabel
|
case rightLabel
|
||||||
case wheel
|
case wheel
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
leftLabel = try typeContainer.decode(LabelModel.self, forKey: .leftLabel)
|
leftLabel = try typeContainer.decode(LabelModel.self, forKey: .leftLabel)
|
||||||
rightLabel = try typeContainer.decode(LabelModel.self, forKey: .rightLabel)
|
rightLabel = try typeContainer.decode(LabelModel.self, forKey: .rightLabel)
|
||||||
wheel = try typeContainer.decode(CircleProgressModel.self, forKey: .wheel)
|
wheel = try typeContainer.decode(CircleProgressModel.self, forKey: .wheel)
|
||||||
|
try super.init(from: decoder)
|
||||||
}
|
}
|
||||||
public func encode(to encoder: Encoder) throws {
|
|
||||||
|
public override func encode(to encoder: Encoder) throws {
|
||||||
|
try super.encode(to: encoder)
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encode(ListRVWheelModel.identifier, forKey: .moleculeName)
|
try container.encode(ListRVWheelModel.identifier, forKey: .moleculeName)
|
||||||
try container.encode(leftLabel, forKey: .leftLabel)
|
try container.encode(leftLabel, forKey: .leftLabel)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user