commenting
This commit is contained in:
parent
7ba0e8ad67
commit
d9d417cc3d
@ -8,25 +8,18 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
|
||||
@objcMembers open class MultiProgress: View {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
|
||||
private let stack = Stack<StackModel>()
|
||||
|
||||
var multiProgressModel: MultiProgressBarModel? {
|
||||
get { return model as? MultiProgressBarModel }
|
||||
}
|
||||
|
||||
public required init(model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
|
||||
super.init(frame: .zero)
|
||||
set(with: model, delegateObject, additionalData)
|
||||
}
|
||||
|
||||
public required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
}
|
||||
|
||||
public override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
}
|
||||
|
||||
var roundedCorners: Bool = false {
|
||||
didSet {
|
||||
if roundedCorners {
|
||||
@ -40,16 +33,37 @@ import UIKit
|
||||
var thicknessConstraint: NSLayoutConstraint?
|
||||
let defaultHeight: CGFloat = 8
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
//--------------------------------------------------
|
||||
|
||||
public required init(model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
super.init(frame: .zero)
|
||||
set(with: model, delegateObject, additionalData)
|
||||
}
|
||||
|
||||
public required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
}
|
||||
|
||||
public override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Lifecycles
|
||||
//--------------------------------------------------
|
||||
|
||||
override open func setupView() {
|
||||
super.setupView()
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
backgroundColor = .mfLightSilver()
|
||||
|
||||
backgroundColor = .mvmCoolGray3
|
||||
clipsToBounds = true
|
||||
|
||||
addSubview(stack)
|
||||
NSLayoutConstraint.constraintPinSubview(toSuperview: stack)
|
||||
stack.backgroundColor = backgroundColor
|
||||
stack.contentView.backgroundColor = .white
|
||||
stack.contentView.backgroundColor = .mvmWhite
|
||||
stack.model = StackModel(molecules: [], axis: .horizontal, spacing: 2)
|
||||
stack.stackModel?.horizontalAlignment = .leading
|
||||
|
||||
@ -59,14 +73,26 @@ import UIKit
|
||||
}
|
||||
}
|
||||
|
||||
open override func reset() {
|
||||
super.reset()
|
||||
backgroundColor = .mvmCoolGray3
|
||||
stack.reset()
|
||||
set(with: [], nil, nil)
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - MoleculeViewProtocol
|
||||
//--------------------------------------------------
|
||||
|
||||
/// Creates the bars
|
||||
open func set(with progressList: Array<SingleProgressBarModel>, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
stack.removeAllItemViews()
|
||||
|
||||
guard let stackModel = stack.stackModel else { return }
|
||||
|
||||
var views: [StackItem] = []
|
||||
var models: [StackItemModel] = []
|
||||
for progressObject in progressList {
|
||||
guard progressObject.percent > 0.0 else { continue }
|
||||
for progressObject in progressList where progressObject.percent > 0.0 {
|
||||
let model = StackItemModel(percent: Int(progressObject.percent), horizontalAlignment: .fill, verticalAlignment: .fill)
|
||||
model.backgroundColor = progressObject.color
|
||||
models.append(model)
|
||||
@ -77,23 +103,18 @@ import UIKit
|
||||
stack.set(with: stackModel, delegateObject, additionalData)
|
||||
}
|
||||
|
||||
//MARK: - MoleculeViewProtocol
|
||||
|
||||
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
super.set(with: model, delegateObject, additionalData)
|
||||
|
||||
guard let multiProgressModel = multiProgressModel else { return }
|
||||
|
||||
roundedCorners = multiProgressModel.roundedCorners ?? false
|
||||
thicknessConstraint?.constant = multiProgressModel.thickness ?? defaultHeight
|
||||
stack.model?.backgroundColor = model.backgroundColor
|
||||
set(with: multiProgressModel.progressList, delegateObject, additionalData)
|
||||
}
|
||||
|
||||
open override func reset() {
|
||||
super.reset()
|
||||
backgroundColor = .mfLightSilver()
|
||||
stack.reset()
|
||||
set(with: [], nil, nil)
|
||||
}
|
||||
|
||||
public override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||
return (model as? MultiProgressBarModel)?.thickness ?? 8
|
||||
}
|
||||
|
||||
@ -36,6 +36,8 @@ import UIKit
|
||||
progressBar.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
|
||||
progressBar.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
|
||||
view.bottomAnchor.constraint(equalTo: progressBar.bottomAnchor).isActive = true
|
||||
isAccessibilityElement = true
|
||||
updateAccessibilityLabel()
|
||||
}
|
||||
|
||||
public override func updateView(_ size: CGFloat) {
|
||||
@ -66,9 +68,35 @@ import UIKit
|
||||
progressBar.set(with: model.progressBar, delegateObject, additionalData)
|
||||
leftLabel.set(with: model.leftLabel, delegateObject, additionalData)
|
||||
rightLabel.set(with: model.rightLabel, delegateObject, additionalData)
|
||||
updateAccessibilityLabel()
|
||||
}
|
||||
|
||||
open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||
return 90
|
||||
}
|
||||
|
||||
//------------------------------------------------------
|
||||
// MARK: - Accessibility
|
||||
//------------------------------------------------------
|
||||
|
||||
func updateAccessibilityLabel() {
|
||||
|
||||
var message = ""
|
||||
|
||||
if let leftLabelText = leftLabel.text, !leftLabelText.isEmpty {
|
||||
message += leftLabelText + ", "
|
||||
}
|
||||
|
||||
if let rightLabelText = rightLabel.text, !rightLabelText.isEmpty {
|
||||
message += rightLabelText + ", "
|
||||
}
|
||||
|
||||
if let progressList = progressBar.multiProgressModel?.progressList {
|
||||
for progress in progressList {
|
||||
message += "\(progress.percent)%, "
|
||||
}
|
||||
}
|
||||
|
||||
accessibilityLabel = message
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user