commenting
This commit is contained in:
parent
7ba0e8ad67
commit
d9d417cc3d
@ -8,13 +8,36 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
|
|
||||||
@objcMembers open class MultiProgress: View {
|
@objcMembers open class MultiProgress: View {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
private let stack = Stack<StackModel>()
|
private let stack = Stack<StackModel>()
|
||||||
|
|
||||||
var multiProgressModel: MultiProgressBarModel? {
|
var multiProgressModel: MultiProgressBarModel? {
|
||||||
get { return model as? 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)
|
super.init(frame: .zero)
|
||||||
set(with: model, delegateObject, additionalData)
|
set(with: model, delegateObject, additionalData)
|
||||||
}
|
}
|
||||||
@ -27,29 +50,20 @@ import UIKit
|
|||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
var roundedCorners: Bool = false {
|
//--------------------------------------------------
|
||||||
didSet {
|
// MARK: - Lifecycles
|
||||||
if roundedCorners {
|
//--------------------------------------------------
|
||||||
layer.cornerRadius = (thicknessConstraint?.constant ?? defaultHeight)/2
|
|
||||||
} else {
|
|
||||||
layer.cornerRadius = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var thicknessConstraint: NSLayoutConstraint?
|
|
||||||
let defaultHeight: CGFloat = 8
|
|
||||||
|
|
||||||
override open func setupView() {
|
override open func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
backgroundColor = .mfLightSilver()
|
backgroundColor = .mvmCoolGray3
|
||||||
clipsToBounds = true
|
clipsToBounds = true
|
||||||
|
|
||||||
addSubview(stack)
|
addSubview(stack)
|
||||||
NSLayoutConstraint.constraintPinSubview(toSuperview: stack)
|
NSLayoutConstraint.constraintPinSubview(toSuperview: stack)
|
||||||
stack.backgroundColor = backgroundColor
|
stack.backgroundColor = backgroundColor
|
||||||
stack.contentView.backgroundColor = .white
|
stack.contentView.backgroundColor = .mvmWhite
|
||||||
stack.model = StackModel(molecules: [], axis: .horizontal, spacing: 2)
|
stack.model = StackModel(molecules: [], axis: .horizontal, spacing: 2)
|
||||||
stack.stackModel?.horizontalAlignment = .leading
|
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
|
/// Creates the bars
|
||||||
open func set(with progressList: Array<SingleProgressBarModel>, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
open func set(with progressList: Array<SingleProgressBarModel>, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
stack.removeAllItemViews()
|
stack.removeAllItemViews()
|
||||||
|
|
||||||
guard let stackModel = stack.stackModel else { return }
|
guard let stackModel = stack.stackModel else { return }
|
||||||
|
|
||||||
var views: [StackItem] = []
|
var views: [StackItem] = []
|
||||||
var models: [StackItemModel] = []
|
var models: [StackItemModel] = []
|
||||||
for progressObject in progressList {
|
for progressObject in progressList where progressObject.percent > 0.0 {
|
||||||
guard progressObject.percent > 0.0 else { continue }
|
|
||||||
let model = StackItemModel(percent: Int(progressObject.percent), horizontalAlignment: .fill, verticalAlignment: .fill)
|
let model = StackItemModel(percent: Int(progressObject.percent), horizontalAlignment: .fill, verticalAlignment: .fill)
|
||||||
model.backgroundColor = progressObject.color
|
model.backgroundColor = progressObject.color
|
||||||
models.append(model)
|
models.append(model)
|
||||||
@ -77,23 +103,18 @@ import UIKit
|
|||||||
stack.set(with: stackModel, delegateObject, additionalData)
|
stack.set(with: stackModel, delegateObject, additionalData)
|
||||||
}
|
}
|
||||||
|
|
||||||
//MARK: - MoleculeViewProtocol
|
|
||||||
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
super.set(with: model, delegateObject, additionalData)
|
super.set(with: model, delegateObject, additionalData)
|
||||||
|
|
||||||
guard let multiProgressModel = multiProgressModel else { return }
|
guard let multiProgressModel = multiProgressModel else { return }
|
||||||
|
|
||||||
roundedCorners = multiProgressModel.roundedCorners ?? false
|
roundedCorners = multiProgressModel.roundedCorners ?? false
|
||||||
thicknessConstraint?.constant = multiProgressModel.thickness ?? defaultHeight
|
thicknessConstraint?.constant = multiProgressModel.thickness ?? defaultHeight
|
||||||
stack.model?.backgroundColor = model.backgroundColor
|
stack.model?.backgroundColor = model.backgroundColor
|
||||||
set(with: multiProgressModel.progressList, delegateObject, additionalData)
|
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? {
|
public override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||||
return (model as? MultiProgressBarModel)?.thickness ?? 8
|
return (model as? MultiProgressBarModel)?.thickness ?? 8
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,6 +36,8 @@ import UIKit
|
|||||||
progressBar.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
|
progressBar.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
|
||||||
progressBar.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
|
progressBar.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
|
||||||
view.bottomAnchor.constraint(equalTo: progressBar.bottomAnchor).isActive = true
|
view.bottomAnchor.constraint(equalTo: progressBar.bottomAnchor).isActive = true
|
||||||
|
isAccessibilityElement = true
|
||||||
|
updateAccessibilityLabel()
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func updateView(_ size: CGFloat) {
|
public override func updateView(_ size: CGFloat) {
|
||||||
@ -66,9 +68,35 @@ import UIKit
|
|||||||
progressBar.set(with: model.progressBar, delegateObject, additionalData)
|
progressBar.set(with: model.progressBar, delegateObject, additionalData)
|
||||||
leftLabel.set(with: model.leftLabel, delegateObject, additionalData)
|
leftLabel.set(with: model.leftLabel, delegateObject, additionalData)
|
||||||
rightLabel.set(with: model.rightLabel, delegateObject, additionalData)
|
rightLabel.set(with: model.rightLabel, delegateObject, additionalData)
|
||||||
|
updateAccessibilityLabel()
|
||||||
}
|
}
|
||||||
|
|
||||||
open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||||
return 90
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -94,7 +94,7 @@ open class DoughnutChart: View {
|
|||||||
titleLabel.textAlignment = .center
|
titleLabel.textAlignment = .center
|
||||||
subTitleLabel.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.numberOfLines = 1
|
||||||
titleLabel.adjustsFontSizeToFitWidth = true
|
titleLabel.adjustsFontSizeToFitWidth = true
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ open class DoughnutChart: View {
|
|||||||
NSLayoutConstraint.constraintPinSubview(titleLabel, pinTop: true, pinBottom: false, pinLeft: true, pinRight: true)
|
NSLayoutConstraint.constraintPinSubview(titleLabel, pinTop: true, pinBottom: false, pinLeft: true, pinRight: true)
|
||||||
NSLayoutConstraint.constraintPinSubview(subTitleLabel, pinTop: false, pinBottom: true, pinLeft: true, pinRight: true)
|
NSLayoutConstraint.constraintPinSubview(subTitleLabel, pinTop: false, pinBottom: true, pinLeft: true, pinRight: true)
|
||||||
_ = NSLayoutConstraint(pinFirstView: titleLabel, toSecondView: subTitleLabel, withConstant: 0, directionVertical: 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)
|
doughnutLayer.transform = CATransform3DMakeRotation(1 * .pi, 0, 0, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user