progress, multi progress, caret
This commit is contained in:
parent
54d0ea3e5c
commit
f40335ce19
@ -102,27 +102,10 @@ open class CaretView: View {
|
||||
@objc open override func setAsMolecule() {
|
||||
defaultState()
|
||||
}
|
||||
|
||||
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
||||
// Configure class properties with JSON values
|
||||
guard let dictionary = json else { return }
|
||||
|
||||
if let strokeColorHex = dictionary["strokeColor"] as? String {
|
||||
strokeColor = UIColor.mfGet(forHex: strokeColorHex)
|
||||
}
|
||||
|
||||
if let isHiddenValue = dictionary[KeyIsHidden] as? Bool {
|
||||
isHidden = isHiddenValue
|
||||
}
|
||||
|
||||
if let isOpaqueValue = dictionary[KeyIsOpaque] as? Bool {
|
||||
isOpaque = isOpaqueValue
|
||||
}
|
||||
|
||||
if let lineWidthValue = dictionary["lineWidth"] as? CGFloat {
|
||||
lineWidth = lineWidthValue
|
||||
}
|
||||
|
||||
public override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) {
|
||||
guard let json = json, let model = try? Self.decodeJSONToModel(json: json, type: CaretViewModel.self) else { return }
|
||||
setWithModel(model, delegateObject, additionalData as? [String : AnyHashable])
|
||||
}
|
||||
|
||||
//MARK: - MVMCoreMoleculeViewProtocol
|
||||
@ -131,17 +114,9 @@ open class CaretView: View {
|
||||
guard let caretModel = model as? CaretViewModel else {
|
||||
return
|
||||
}
|
||||
if let strokeColorHex = caretModel.strokeColor {
|
||||
strokeColor = UIColor.mfGet(forHex: strokeColorHex)
|
||||
}
|
||||
|
||||
if let isHiddenValue = caretModel.isHidden {
|
||||
isHidden = isHiddenValue
|
||||
}
|
||||
|
||||
if let isOpaqueValue = caretModel.isOpaque {
|
||||
isOpaque = isOpaqueValue
|
||||
}
|
||||
strokeColor = caretModel.strokeColor.uiColor
|
||||
isHidden = caretModel.isHidden ?? false
|
||||
isOpaque = caretModel.isOpaque ?? false
|
||||
|
||||
if let lineWidthValue = caretModel.lineWidth {
|
||||
lineWidth = lineWidthValue
|
||||
|
||||
@ -12,8 +12,36 @@ import Foundation
|
||||
|
||||
public static var identifier: String = "caretView"
|
||||
public var backgroundColor: Color?
|
||||
public var strokeColor: String?
|
||||
public var strokeColor: Color = Color(uiColor: .black)
|
||||
public var isHidden: Bool?
|
||||
public var isOpaque: Bool?
|
||||
public var lineWidth: CGFloat?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case backgroundColor
|
||||
case strokeColor
|
||||
case isHidden
|
||||
case isOpaque
|
||||
case lineWidth
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
if let strokeColor = try typeContainer.decodeIfPresent(Color.self, forKey: .strokeColor) {
|
||||
self.strokeColor = strokeColor
|
||||
}
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
isHidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .isHidden)
|
||||
isOpaque = try typeContainer.decodeIfPresent(Bool.self, forKey: .isOpaque)
|
||||
lineWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .lineWidth)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(strokeColor, forKey: .strokeColor)
|
||||
try container.encodeIfPresent(isHidden, forKey: .isHidden)
|
||||
try container.encodeIfPresent(isOpaque, forKey: .isOpaque)
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
try container.encodeIfPresent(lineWidth, forKey: .lineWidth)
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,7 +9,10 @@
|
||||
import UIKit
|
||||
|
||||
@objcMembers open class MultiProgress: View {
|
||||
|
||||
var multiProgressModel: MultiProgressBarModel? {
|
||||
get { return model as? MultiProgressBarModel }
|
||||
}
|
||||
|
||||
///passing value to progressList creates corresponding progress bars
|
||||
var progressList: Array<SingleProgressBarModel>? {
|
||||
didSet {
|
||||
@ -63,7 +66,7 @@ import UIKit
|
||||
//MARK: - MVMCoreMoleculeViewProtocol
|
||||
public override func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) {
|
||||
super.setWithModel(model, delegateObject, additionalData)
|
||||
guard let multiProgressModel = model as? MultiProgressBarModel else {
|
||||
guard let multiProgressModel = multiProgressModel else {
|
||||
return
|
||||
}
|
||||
roundedRect = multiProgressModel.roundedRect ?? false
|
||||
@ -78,9 +81,8 @@ import UIKit
|
||||
progressList = nil
|
||||
}
|
||||
|
||||
override open func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
||||
thicknessConstraint?.constant = json?.optionalCGFloatForKey("thickness") ?? defaultHeight
|
||||
roundedRect = json?.optionalBoolForKey("roundedRect") ?? false
|
||||
public override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) {
|
||||
guard let json = json, let model = try? Self.decodeJSONToModel(json: json, type: MultiProgressBarModel.self) else { return }
|
||||
setWithModel(model, delegateObject, additionalData as? [String : AnyHashable])
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,6 +32,10 @@ import Foundation
|
||||
case backgroundColor
|
||||
}
|
||||
|
||||
public init(_ progressList: [SingleProgressBarModel]) {
|
||||
self.progressList = progressList
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
progressList = try typeContainer.decode([SingleProgressBarModel].self, forKey: .progressList)
|
||||
|
||||
@ -9,11 +9,12 @@
|
||||
import Foundation
|
||||
|
||||
@objcMembers open class ProgressBar: UIProgressView, MVMCoreViewProtocol, ModelMoleculeViewProtocol, MVMCoreUIMoleculeViewProtocol {
|
||||
var isRounded = false
|
||||
var progressBarModel: ProgressBarModel?
|
||||
|
||||
var thickness: CGFloat = 8.0 {
|
||||
willSet(newValue) {
|
||||
heightAnchor.constraint(equalToConstant: newValue).isActive = true
|
||||
if isRounded {
|
||||
if progressBarModel?.isRounded ?? false {
|
||||
layer.cornerRadius = newValue/2.0
|
||||
} else {
|
||||
progressViewStyle = .bar
|
||||
@ -40,7 +41,6 @@ import Foundation
|
||||
public func setupView() {
|
||||
clipsToBounds = true
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
isRounded = false
|
||||
thickness = 8
|
||||
progress = 0
|
||||
progressTintColor = UIColor.mfCerulean()
|
||||
@ -55,7 +55,6 @@ import Foundation
|
||||
guard let progressBarModel = model as? ProgressBarModel else {
|
||||
return
|
||||
}
|
||||
isRounded = progressBarModel.isRounded ?? false
|
||||
thickness = progressBarModel.thickness ?? 8
|
||||
progress = Float((progressBarModel.percent)/100.0)
|
||||
progressTintColor = progressBarModel.progressColor.uiColor
|
||||
@ -66,26 +65,11 @@ import Foundation
|
||||
|
||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||
public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) {
|
||||
if let isRounded = json?.optionalBoolForKey("roundedRect") {
|
||||
self.isRounded = isRounded
|
||||
}
|
||||
if let thickness = json?.optionalCGFloatForKey("thickness") {
|
||||
self.thickness = thickness
|
||||
}
|
||||
// as? Float returns nil, apple defect.
|
||||
if let percentage = json?["percent"] as? CGFloat {
|
||||
progress = Float(percentage/100.0)
|
||||
}
|
||||
if let progressColor = json?.optionalStringForKey("progressColor") {
|
||||
progressTintColor = UIColor.mfGet(forHex: progressColor)
|
||||
}
|
||||
if let backgroundColor = json?.optionalStringForKey("backgroundColor") {
|
||||
trackTintColor = UIColor.mfGet(forHex: backgroundColor)
|
||||
}
|
||||
guard let json = json, let model = try? Self.decodeJSONToModel(json: json, type: ProgressBarModel.self) else { return }
|
||||
setWithModel(model, delegateObject, additionalData as? [String : AnyHashable])
|
||||
}
|
||||
|
||||
public func reset() {
|
||||
isRounded = false
|
||||
thickness = 8
|
||||
progress = 0
|
||||
progressTintColor = UIColor.mfCerulean()
|
||||
|
||||
@ -25,7 +25,7 @@ import Foundation
|
||||
case backgroundColor
|
||||
}
|
||||
|
||||
init(_ percent: CGFloat) {
|
||||
public init(_ percent: CGFloat) {
|
||||
self.percent = percent
|
||||
}
|
||||
|
||||
|
||||
@ -25,4 +25,11 @@ extension ModelMoleculeViewProtocol {
|
||||
public static func requiredModules(_ molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Temporary
|
||||
public static func decodeJSONToModel<T>(json: [AnyHashable: Any], type: T.Type) throws -> T where T : Decodable {
|
||||
let data = try JSONSerialization.data(withJSONObject: json)
|
||||
let decoder = JSONDecoder()
|
||||
return try decoder.decode(type, from: data)
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +143,6 @@ open class MoleculeStackView: Container {
|
||||
} else {
|
||||
setWithModel(model, delegateObject, additionalData as? [String : AnyHashable])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||
|
||||
@ -33,5 +33,6 @@ import Foundation
|
||||
//
|
||||
//ModelRegistry.register(ModuleMoleculeModel.self)
|
||||
ModelRegistry.register(LeftRightLabelModel.self)
|
||||
ModelRegistry.register(CaretViewModel.self)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user