commenting

This commit is contained in:
Kevin G Christiano 2020-06-04 14:41:25 -04:00
parent 7ba0e8ad67
commit d9d417cc3d
3 changed files with 77 additions and 28 deletions

View File

@ -8,13 +8,36 @@
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]?) {
var roundedCorners: Bool = false {
didSet {
if roundedCorners {
layer.cornerRadius = (thicknessConstraint?.constant ?? defaultHeight) / 2
} else {
layer.cornerRadius = 0
}
}
}
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)
}
@ -27,29 +50,20 @@ import UIKit
super.init(frame: frame)
}
var roundedCorners: Bool = false {
didSet {
if roundedCorners {
layer.cornerRadius = (thicknessConstraint?.constant ?? defaultHeight)/2
} else {
layer.cornerRadius = 0
}
}
}
var thicknessConstraint: NSLayoutConstraint?
let defaultHeight: CGFloat = 8
//--------------------------------------------------
// 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
}

View File

@ -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
}
}

View File

@ -94,7 +94,7 @@ open class DoughnutChart: View {
titleLabel.textAlignment = .center
subTitleLabel.textAlignment = .center
//Make label font size to adjust width if label content is high
// Make label font size to adjust width if label content is high
titleLabel.numberOfLines = 1
titleLabel.adjustsFontSizeToFitWidth = true
@ -117,7 +117,7 @@ open class DoughnutChart: View {
NSLayoutConstraint.constraintPinSubview(titleLabel, pinTop: true, pinBottom: false, pinLeft: true, pinRight: true)
NSLayoutConstraint.constraintPinSubview(subTitleLabel, pinTop: false, pinBottom: true, pinLeft: true, pinRight: true)
_ = NSLayoutConstraint(pinFirstView: titleLabel, toSecondView: subTitleLabel, withConstant: 0, directionVertical: true)
//Rotate view for initial draw
// Rotate view for initial draw
doughnutLayer.transform = CATransform3DMakeRotation(1 * .pi, 0, 0, 1)
}