Code Changes after reimplementing the molecule class.
This commit is contained in:
parent
fed9b8ff92
commit
c30a001239
@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
@objcMembers public class StackItemModel: StackItemModelProtocol, MoleculeModelProtocol {
|
||||
@objcMembers public class StackItemModel: ContainerModel, StackItemModelProtocol, MoleculeModelProtocol {
|
||||
public static var identifier: String = "simpleStackItem"
|
||||
public var backgroundColor: Color?
|
||||
public var spacing: CGFloat?
|
||||
|
||||
@ -14,30 +14,15 @@ import UIKit
|
||||
//-----------------------------------------------------
|
||||
// MARK: - Outlets
|
||||
//-------------------------------------------------------
|
||||
|
||||
let leftImage = MFLoadImageView()
|
||||
let leftLabel = Label.commonLabelB2(true)
|
||||
let rightLabel = Label.commonLabelB2(true)
|
||||
let containerView = Container()
|
||||
|
||||
//------------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//------------------------------------------------------
|
||||
|
||||
let cellHeight: CGFloat = 79
|
||||
let leftPadding: CGFloat = 35
|
||||
let spaceBetweenImageAndLeftLabel: CGFloat = 16
|
||||
let imageSize: CGFloat = 30
|
||||
let spaceBetweenLabels: CGFloat = 40
|
||||
let horizontalPadding = MFStyler.defaultHorizontalPaddingForApplicationWidth()
|
||||
|
||||
let stack = Stack<StackModel>(frame: .zero)
|
||||
//-----------------------------------------------------
|
||||
// MARK: - View Lifecycle
|
||||
//-------------------------------------------------------
|
||||
|
||||
open override func updateView(_ size: CGFloat) {
|
||||
super.updateView(size)
|
||||
containerView.updateView(size)
|
||||
leftImage.updateView(size)
|
||||
leftLabel.updateView(size)
|
||||
rightLabel.updateView(size)
|
||||
@ -48,48 +33,23 @@ import UIKit
|
||||
guard leftImage.superview == nil else {
|
||||
return
|
||||
}
|
||||
containerView.translatesAutoresizingMaskIntoConstraints = false
|
||||
contentView.heightAnchor.constraint(equalToConstant: cellHeight).isActive = true
|
||||
contentView.addSubview(containerView)
|
||||
|
||||
//containerView constraints
|
||||
containerView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
|
||||
containerView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
|
||||
containerView.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
||||
containerView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
|
||||
|
||||
containerView.addSubview(leftImage)
|
||||
containerView.addSubview(leftLabel)
|
||||
containerView.addSubview(rightLabel)
|
||||
|
||||
//leftImage constraints
|
||||
leftImage.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: horizontalPadding).isActive = true
|
||||
leftImage.centerYAnchor.constraint(equalTo: leftLabel.centerYAnchor).isActive = true
|
||||
leftImage.widthAnchor.constraint(equalToConstant: imageSize).isActive = true
|
||||
leftImage.heightAnchor.constraint(equalToConstant: imageSize).isActive = true
|
||||
|
||||
|
||||
//leftLabel constraints
|
||||
leftLabel.leadingAnchor.constraint(equalTo: leftImage.trailingAnchor, constant: spaceBetweenImageAndLeftLabel).isActive = true
|
||||
leftLabel.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true
|
||||
leftLabel.bottomAnchor.constraint(equalTo: containerView.bottomAnchor).isActive = true
|
||||
|
||||
//rightLabel constraints
|
||||
rightLabel.leadingAnchor.constraint(greaterThanOrEqualTo: leftLabel.trailingAnchor, constant: spaceBetweenLabels).isActive = true
|
||||
rightLabel.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true
|
||||
rightLabel.bottomAnchor.constraint(equalTo: containerView.bottomAnchor).isActive = true
|
||||
rightLabel.trailingAnchor.constraint(equalTo: containerView.trailingAnchor,constant: -horizontalPadding - 20).isActive = true
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
stack.stackItems = [StackItem(andContain: leftImage),StackItem(andContain: leftLabel),StackItem(andContain: rightLabel)]
|
||||
contentView.addSubview(stack)
|
||||
containerHelper.constrainView(stack)
|
||||
leftLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 901), for: .horizontal)
|
||||
rightLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 902), for: .horizontal)
|
||||
|
||||
}
|
||||
|
||||
//----------------------------------------------------
|
||||
// MARK: - Molecule
|
||||
//------------------------------------------------------
|
||||
|
||||
override open func reset() {
|
||||
super.reset()
|
||||
leftImage.reset()
|
||||
leftLabel.reset()
|
||||
rightLabel.reset()
|
||||
stack.reset()
|
||||
}
|
||||
|
||||
public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
|
||||
@ -98,5 +58,17 @@ import UIKit
|
||||
leftImage.setWithModel(model.image, delegateObject, additionalData)
|
||||
leftLabel.setWithModel(model.leftLabel, delegateObject, additionalData)
|
||||
rightLabel.setWithModel(model.rightLabel, delegateObject, additionalData)
|
||||
|
||||
// Create a stack model to use for the internal stack and set the alignment of labels
|
||||
let leftImage = StackItemModel()
|
||||
leftImage.horizontalAlignment = .fill
|
||||
let leftLabel = StackItemModel()
|
||||
leftLabel.horizontalAlignment = .fill
|
||||
let rightLabel = StackItemModel()
|
||||
rightLabel.horizontalAlignment = .trailing
|
||||
let stackModel = StackModel(molecules: [leftImage,leftLabel,rightLabel])
|
||||
stackModel.axis = .horizontal
|
||||
stack.model = stackModel
|
||||
stack.restack()
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import Foundation
|
||||
public class ListLeftVariableIconWithRightCaretModel: ContainerModel, ListItemModelProtocol {
|
||||
|
||||
public var line: LineModel?
|
||||
public var style: String? = "standard"
|
||||
public var hideArrow: Bool? = false
|
||||
public var backgroundColor: Color?
|
||||
public var action: ActionModelProtocol?
|
||||
@ -26,11 +27,8 @@ public class ListLeftVariableIconWithRightCaretModel: ContainerModel, ListItemMo
|
||||
if useVerticalMargins == nil {
|
||||
useVerticalMargins = true
|
||||
}
|
||||
if topMarginPadding == nil {
|
||||
topMarginPadding = 24
|
||||
}
|
||||
if bottomMarginPadding == nil {
|
||||
bottomMarginPadding = 0
|
||||
if image.height == nil {
|
||||
image.height = 30.0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user