Code Changes after reimplementing the molecule class.
This commit is contained in:
parent
fed9b8ff92
commit
c30a001239
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
@objcMembers public class StackItemModel: StackItemModelProtocol, MoleculeModelProtocol {
|
@objcMembers public class StackItemModel: ContainerModel, StackItemModelProtocol, MoleculeModelProtocol {
|
||||||
public static var identifier: String = "simpleStackItem"
|
public static var identifier: String = "simpleStackItem"
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var spacing: CGFloat?
|
public var spacing: CGFloat?
|
||||||
|
|||||||
@ -14,30 +14,15 @@ import UIKit
|
|||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
// MARK: - Outlets
|
// MARK: - Outlets
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
|
|
||||||
let leftImage = MFLoadImageView()
|
let leftImage = MFLoadImageView()
|
||||||
let leftLabel = Label.commonLabelB2(true)
|
let leftLabel = Label.commonLabelB2(true)
|
||||||
let rightLabel = Label.commonLabelB2(true)
|
let rightLabel = Label.commonLabelB2(true)
|
||||||
let containerView = Container()
|
let stack = Stack<StackModel>(frame: .zero)
|
||||||
|
|
||||||
//------------------------------------------------------
|
|
||||||
// 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()
|
|
||||||
|
|
||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
// MARK: - View Lifecycle
|
// MARK: - View Lifecycle
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
|
|
||||||
open override func updateView(_ size: CGFloat) {
|
open override func updateView(_ size: CGFloat) {
|
||||||
super.updateView(size)
|
super.updateView(size)
|
||||||
containerView.updateView(size)
|
|
||||||
leftImage.updateView(size)
|
leftImage.updateView(size)
|
||||||
leftLabel.updateView(size)
|
leftLabel.updateView(size)
|
||||||
rightLabel.updateView(size)
|
rightLabel.updateView(size)
|
||||||
@ -48,48 +33,23 @@ import UIKit
|
|||||||
guard leftImage.superview == nil else {
|
guard leftImage.superview == nil else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
containerView.translatesAutoresizingMaskIntoConstraints = false
|
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||||
contentView.heightAnchor.constraint(equalToConstant: cellHeight).isActive = true
|
stack.stackItems = [StackItem(andContain: leftImage),StackItem(andContain: leftLabel),StackItem(andContain: rightLabel)]
|
||||||
contentView.addSubview(containerView)
|
contentView.addSubview(stack)
|
||||||
|
containerHelper.constrainView(stack)
|
||||||
//containerView constraints
|
leftLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 901), for: .horizontal)
|
||||||
containerView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
|
rightLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 902), for: .horizontal)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
// MARK: - Molecule
|
// MARK: - Molecule
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
override open func reset() {
|
override open func reset() {
|
||||||
super.reset()
|
super.reset()
|
||||||
leftImage.reset()
|
leftImage.reset()
|
||||||
leftLabel.reset()
|
leftLabel.reset()
|
||||||
rightLabel.reset()
|
rightLabel.reset()
|
||||||
|
stack.reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
|
public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
|
||||||
@ -98,5 +58,17 @@ import UIKit
|
|||||||
leftImage.setWithModel(model.image, delegateObject, additionalData)
|
leftImage.setWithModel(model.image, delegateObject, additionalData)
|
||||||
leftLabel.setWithModel(model.leftLabel, delegateObject, additionalData)
|
leftLabel.setWithModel(model.leftLabel, delegateObject, additionalData)
|
||||||
rightLabel.setWithModel(model.rightLabel, 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 class ListLeftVariableIconWithRightCaretModel: ContainerModel, ListItemModelProtocol {
|
||||||
|
|
||||||
public var line: LineModel?
|
public var line: LineModel?
|
||||||
|
public var style: String? = "standard"
|
||||||
public var hideArrow: Bool? = false
|
public var hideArrow: Bool? = false
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var action: ActionModelProtocol?
|
public var action: ActionModelProtocol?
|
||||||
@ -26,11 +27,8 @@ public class ListLeftVariableIconWithRightCaretModel: ContainerModel, ListItemMo
|
|||||||
if useVerticalMargins == nil {
|
if useVerticalMargins == nil {
|
||||||
useVerticalMargins = true
|
useVerticalMargins = true
|
||||||
}
|
}
|
||||||
if topMarginPadding == nil {
|
if image.height == nil {
|
||||||
topMarginPadding = 24
|
image.height = 30.0
|
||||||
}
|
|
||||||
if bottomMarginPadding == nil {
|
|
||||||
bottomMarginPadding = 0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user