create model for progress bar, using ModelMoleculeViewProtocol
This commit is contained in:
parent
ec9ac811d5
commit
5fd74b695f
@ -46,6 +46,8 @@
|
||||
0A7BAFA1232BE61800FB8E22 /* Checkbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */; };
|
||||
943784F5236B77BB006A1E82 /* GraphView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 943784F3236B77BB006A1E82 /* GraphView.swift */; };
|
||||
943784F6236B77BB006A1E82 /* GraphViewAnimationHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 943784F4236B77BB006A1E82 /* GraphViewAnimationHandler.swift */; };
|
||||
9445890C2385BCE300DE9FD4 /* ProgressBarModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9445890B2385BCE300DE9FD4 /* ProgressBarModel.swift */; };
|
||||
9445890E2385C3F800DE9FD4 /* MultiProgressModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9445890D2385C3F800DE9FD4 /* MultiProgressModel.swift */; };
|
||||
9455B19C234F8A0400A574DB /* MVMAnimationFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9455B19B234F8A0400A574DB /* MVMAnimationFramework.framework */; };
|
||||
946EE1BA237B66D80036751F /* ModelHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1B9237B66D80036751F /* ModelHelper.swift */; };
|
||||
948DB67E2326DCD90011F916 /* MultiProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 948DB67D2326DCD90011F916 /* MultiProgress.swift */; };
|
||||
@ -260,6 +262,8 @@
|
||||
0A7BAFA2232BE63400FB8E22 /* CheckboxWithLabelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxWithLabelView.swift; sourceTree = "<group>"; };
|
||||
943784F3236B77BB006A1E82 /* GraphView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphView.swift; sourceTree = "<group>"; };
|
||||
943784F4236B77BB006A1E82 /* GraphViewAnimationHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphViewAnimationHandler.swift; sourceTree = "<group>"; };
|
||||
9445890B2385BCE300DE9FD4 /* ProgressBarModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressBarModel.swift; sourceTree = "<group>"; };
|
||||
9445890D2385C3F800DE9FD4 /* MultiProgressModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiProgressModel.swift; sourceTree = "<group>"; };
|
||||
9455B19B234F8A0400A574DB /* MVMAnimationFramework.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MVMAnimationFramework.framework; path = ../SharedFrameworks/MVMAnimationFramework.framework; sourceTree = "<group>"; };
|
||||
946EE1B9237B66D80036751F /* ModelHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelHelper.swift; sourceTree = "<group>"; };
|
||||
948DB67D2326DCD90011F916 /* MultiProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiProgress.swift; sourceTree = "<group>"; };
|
||||
@ -590,6 +594,7 @@
|
||||
D29DF0CE21E404D4003B2FB9 /* MVMCoreUI */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D29DF10D21E67A70003B2FB9 /* Atoms */,
|
||||
01509D96232803B200EF99AA /* Models */,
|
||||
D2B18B7D236090D500A9AEDC /* BaseClasses */,
|
||||
01C74D87224298E2009C25A3 /* FormUIHelpers */,
|
||||
@ -602,7 +607,6 @@
|
||||
D22D1F582204D2590077CEC0 /* LegacyControllers */,
|
||||
D29DF10F21E67A7D003B2FB9 /* BaseControllers */,
|
||||
D29DF11E21E6851E003B2FB9 /* TopAlert */,
|
||||
D29DF10D21E67A70003B2FB9 /* Atoms */,
|
||||
D29DF10E21E67A77003B2FB9 /* Molecules */,
|
||||
D22479902316A9CB003FCCF9 /* Organisms */,
|
||||
D29DF0DF21E418B2003B2FB9 /* Templates */,
|
||||
@ -789,10 +793,12 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
01509D922327ECFB00EF99AA /* ProgressBar.swift */,
|
||||
9445890B2385BCE300DE9FD4 /* ProgressBarModel.swift */,
|
||||
D260D7AF22D65BDD007E7233 /* MVMCoreUIPageControl.h */,
|
||||
D260D7B022D65BDD007E7233 /* MVMCoreUIPageControl.m */,
|
||||
D260D7B522D68509007E7233 /* MVMCoreUIPagingProtocol.h */,
|
||||
948DB67D2326DCD90011F916 /* MultiProgress.swift */,
|
||||
9445890D2385C3F800DE9FD4 /* MultiProgressModel.swift */,
|
||||
DBC4391622442196001AB423 /* CaretView.swift */,
|
||||
DBC4391722442197001AB423 /* DashLine.swift */,
|
||||
DB06250A2293456500B72DD3 /* LeftRightLabelView.swift */,
|
||||
@ -1143,6 +1149,7 @@
|
||||
DBC4392122491730001AB423 /* LabelWithInternalButton.swift in Sources */,
|
||||
D224798C231450C8003FCCF9 /* HeadlineBodySwitch.swift in Sources */,
|
||||
017BEB442362192F0024EF95 /* MVMCoreUIMoleculeMappingObject+ModelExtension.swift in Sources */,
|
||||
9445890C2385BCE300DE9FD4 /* ProgressBarModel.swift in Sources */,
|
||||
D29DF17C21E69E1F003B2FB9 /* MFTextButton.m in Sources */,
|
||||
D29DF2C521E7BF57003B2FB9 /* MFTabBarSwipeAnimator.m in Sources */,
|
||||
D29DF2B421E7B76D003B2FB9 /* MFLoadingSpinner.m in Sources */,
|
||||
@ -1197,6 +1204,7 @@
|
||||
01DF55E021F8FAA800CC099B /* MFTextFieldListView.swift in Sources */,
|
||||
D2A5146B2214905000345BFB /* ThreeLayerViewController.swift in Sources */,
|
||||
D29DF2C921E7BFC6003B2FB9 /* MFSizeObject.m in Sources */,
|
||||
9445890E2385C3F800DE9FD4 /* MultiProgressModel.swift in Sources */,
|
||||
D2A6390522CBCE160052ED1F /* MoleculeCollectionViewCell.swift in Sources */,
|
||||
D2A6390122CBB1820052ED1F /* Carousel.swift in Sources */,
|
||||
D29DF2C721E7BF57003B2FB9 /* MFTabBarInteractor.m in Sources */,
|
||||
|
||||
@ -8,35 +8,10 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
@objcMembers open class ProgressBarObject {
|
||||
///from 0.0 to 1.0. input progress should be [0 100]
|
||||
var progress: CGFloat = 0.0
|
||||
///default color is cerulean
|
||||
var color: UIColor = UIColor.mfCerulean()
|
||||
@objcMembers open class MultiProgress: ViewConstrainingView, ModelMoleculeViewProtocol {
|
||||
|
||||
init(_ module: [AnyHashable: Any]?) {
|
||||
progress = (module?.optionalCGFloatForKey("progress") ?? 0.0)/100
|
||||
if let colorString = module?.optionalStringForKey("progressColor") {
|
||||
color = UIColor.mfGet(forHex: colorString)
|
||||
}
|
||||
}
|
||||
|
||||
static func getProgressBarObjectList(_ list: [[AnyHashable: Any]]?) -> [ProgressBarObject]? {
|
||||
guard list?.count ?? 0 > 0 else {
|
||||
return nil
|
||||
}
|
||||
var progressList = [ProgressBarObject]()
|
||||
for module in list! {
|
||||
let progressObject = ProgressBarObject(module)
|
||||
progressList.append(progressObject)
|
||||
}
|
||||
return progressList
|
||||
}
|
||||
}
|
||||
|
||||
@objcMembers open class MultiProgress: MFView {
|
||||
///passing value to progressList creates corresponding progress bars
|
||||
var progressList: Array<ProgressBarObject>? {
|
||||
var progressList: Array<SingleProgressBarModel>? {
|
||||
didSet {
|
||||
for subview in subviews {
|
||||
subview.removeFromSuperview()
|
||||
@ -46,14 +21,18 @@ import UIKit
|
||||
}
|
||||
var previous: UIView?
|
||||
for progressObject in progressList! {
|
||||
guard progressObject.progress > 0.0 else {
|
||||
guard progressObject.progress ?? 0.0 > 0.0 else {
|
||||
continue
|
||||
}
|
||||
let view = MFView(frame: .zero)
|
||||
view.translatesAutoresizingMaskIntoConstraints = false
|
||||
addSubview(view)
|
||||
view.backgroundColor = progressObject.color
|
||||
view.widthAnchor.constraint(equalTo: widthAnchor, multiplier: progressObject.progress).isActive = true
|
||||
var color = UIColor.mfCerulean()
|
||||
if let colorString = progressObject.color {
|
||||
color = UIColor.mfGet(forHex: colorString)
|
||||
}
|
||||
view.backgroundColor = color
|
||||
view.widthAnchor.constraint(equalTo: widthAnchor, multiplier: progressObject.progress ?? 0).isActive = true
|
||||
view.leadingAnchor.constraint(equalTo: previous?.trailingAnchor ?? leadingAnchor).isActive = true
|
||||
previous = view
|
||||
NSLayoutConstraint.constraintPinSubview(view, pinTop: true, pinBottom: true, pinLeft: false, pinRight: false)
|
||||
@ -70,6 +49,7 @@ import UIKit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var thicknessConstraint: NSLayoutConstraint?
|
||||
let defaultHeight: CGFloat = 8
|
||||
|
||||
@ -84,6 +64,16 @@ import UIKit
|
||||
}
|
||||
}
|
||||
|
||||
public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) {
|
||||
guard let multiProgressModel = model as? MultiProgressBarModel else {
|
||||
return
|
||||
}
|
||||
roundedRect = multiProgressModel.roundedRect ?? false
|
||||
thicknessConstraint?.constant = multiProgressModel.thickness ?? defaultHeight
|
||||
progressList = multiProgressModel.progressList
|
||||
|
||||
}
|
||||
|
||||
open override func reset() {
|
||||
super.reset()
|
||||
backgroundColor = .mfLightSilver()
|
||||
@ -94,6 +84,5 @@ import UIKit
|
||||
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
||||
thicknessConstraint?.constant = json?.optionalCGFloatForKey("thickness") ?? defaultHeight
|
||||
roundedRect = json?.optionalBoolForKey("roundedRect") ?? false
|
||||
progressList = ProgressBarObject.getProgressBarObjectList(json?.optionalArrayForKey("progressList") as? [[AnyHashable: Any]])
|
||||
}
|
||||
}
|
||||
|
||||
47
MVMCoreUI/Atoms/Views/MultiProgressModel.swift
Normal file
47
MVMCoreUI/Atoms/Views/MultiProgressModel.swift
Normal file
@ -0,0 +1,47 @@
|
||||
//
|
||||
// MultiProgressModel.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Ryan on 11/20/19.
|
||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
@objcMembers public class SingleProgressBarModel: Codable {
|
||||
var progress: CGFloat?
|
||||
var color: String?
|
||||
}
|
||||
|
||||
@objcMembers public class MultiProgressBarModel: MoleculeProtocol {
|
||||
public static var identifier: String = "multiProgressBar"
|
||||
public var moleculeName: String
|
||||
public var progressList: [SingleProgressBarModel]?
|
||||
public var thickness: CGFloat?
|
||||
public var roundedRect: Bool?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case moleculeName
|
||||
case progressList
|
||||
case thickness
|
||||
case roundedRect
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName)
|
||||
self.progressList = try typeContainer.decodeIfPresent([SingleProgressBarModel].self, forKey: .progressList)
|
||||
self.thickness = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .thickness)
|
||||
self.roundedRect = try typeContainer.decodeIfPresent(Bool.self, forKey: .roundedRect)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(progressList, forKey: .progressList)
|
||||
try container.encodeIfPresent(thickness, forKey: .thickness)
|
||||
try container.encodeIfPresent(roundedRect, forKey: .roundedRect)
|
||||
}
|
||||
}
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
@objcMembers open class ProgressBar: UIProgressView, MVMCoreUIMoleculeViewProtocol, MVMCoreViewProtocol {
|
||||
@objcMembers open class ProgressBar: UIProgressView, MVMCoreViewProtocol, ModelMoleculeViewProtocol, MVMCoreUIMoleculeViewProtocol {
|
||||
var isRounded = false
|
||||
var thickness: CGFloat = 8.0 {
|
||||
willSet(newValue) {
|
||||
@ -40,12 +40,31 @@ import Foundation
|
||||
public func setupView() {
|
||||
clipsToBounds = true
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
reset()
|
||||
isRounded = false
|
||||
thickness = 8
|
||||
progress = 0
|
||||
progressTintColor = UIColor.mfCerulean()
|
||||
trackTintColor = UIColor.mfLightSilver()
|
||||
}
|
||||
|
||||
public func updateView(_ size: CGFloat) {
|
||||
}
|
||||
|
||||
public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String: AnyHashable]?) {
|
||||
guard let progressBarModel = model as? ProgressBarModel else {
|
||||
return
|
||||
}
|
||||
isRounded = progressBarModel.isRounded ?? false
|
||||
thickness = progressBarModel.thickness ?? 8
|
||||
progress = (progressBarModel.percentage ?? 0)/100.0
|
||||
if let progressColor = progressBarModel.progressColor {
|
||||
progressTintColor = UIColor.mfGet(forHex: progressColor)
|
||||
}
|
||||
if let backgroundColor = progressBarModel.backgroundColor {
|
||||
trackTintColor = UIColor.mfGet(forHex: backgroundColor)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||
public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) {
|
||||
if let isRounded = json?.optionalBoolForKey("roundedRect") {
|
||||
|
||||
52
MVMCoreUI/Atoms/Views/ProgressBarModel.swift
Normal file
52
MVMCoreUI/Atoms/Views/ProgressBarModel.swift
Normal file
@ -0,0 +1,52 @@
|
||||
//
|
||||
// ProgressBarModel.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Ryan on 11/20/19.
|
||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
@objcMembers public class ProgressBarModel: MoleculeProtocol {
|
||||
public static var identifier: String = "progressbar"
|
||||
public var moleculeName: String
|
||||
|
||||
public var isRounded: Bool?
|
||||
public var thickness: CGFloat?
|
||||
///from 0 to 100
|
||||
public var percentage: Float?
|
||||
public var progressColor: String?
|
||||
public var backgroundColor: String?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case moleculeName
|
||||
case isRounded = "roundRect"
|
||||
case thickness
|
||||
case percentage = "percent"
|
||||
case progressColor
|
||||
case backgroundColor
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
self.moleculeName = try typeContainer.decode(String.self, forKey: .moleculeName)
|
||||
self.isRounded = try typeContainer.decodeIfPresent(Bool.self, forKey: .isRounded)
|
||||
self.thickness = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .thickness)
|
||||
self.percentage = try typeContainer.decodeIfPresent(Float.self, forKey: .percentage)
|
||||
self.progressColor = try typeContainer.decodeIfPresent(String.self, forKey: .progressColor)
|
||||
self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor)
|
||||
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(moleculeName, forKey: .moleculeName)
|
||||
try container.encodeIfPresent(isRounded, forKey: .isRounded)
|
||||
try container.encodeIfPresent(thickness, forKey: .thickness)
|
||||
try container.encodeIfPresent(percentage, forKey: .percentage)
|
||||
try container.encodeIfPresent(progressColor, forKey: .progressColor)
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
}
|
||||
}
|
||||
@ -18,5 +18,7 @@ import Foundation
|
||||
ModelRegistry.register(ListItemModel.self)
|
||||
ModelRegistry.register(TextFieldModel.self)
|
||||
ModelRegistry.register(LineModel.self)
|
||||
ModelRegistry.register(ProgressBarModel.self)
|
||||
ModelRegistry.register(MultiProgressBarModel.self)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user