91 lines
3.0 KiB
Swift
91 lines
3.0 KiB
Swift
//
|
|
// TestLabelToggle.swift
|
|
// JSONCreator
|
|
//
|
|
// Created by Matt Bruce on 8/2/22.
|
|
// Copyright © 2022 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import MVMCore
|
|
import MVMCoreUI
|
|
|
|
@objcMembers open class TestLabelToggle: View {
|
|
//--------------------------------------------------
|
|
// MARK: - Properties
|
|
//--------------------------------------------------
|
|
public let toggle = TestToggle()
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - MVMCoreViewProtocol
|
|
//--------------------------------------------------
|
|
|
|
open override func updateView(_ size: CGFloat) {
|
|
super.updateView(size)
|
|
toggle.updateView(size)
|
|
}
|
|
|
|
open override func setupView() {
|
|
super.setupView()
|
|
addSubview(toggle)
|
|
toggle.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
|
toggle.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
|
|
toggle.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
|
|
}
|
|
|
|
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
|
guard let labelToggleModel = model as? TestLabelToggleModel else { return }
|
|
|
|
toggle.set(with: labelToggleModel.toggle, delegateObject, additionalData)
|
|
|
|
let text = labelToggleModel.label.text
|
|
toggle.showText = true
|
|
toggle.onText = text
|
|
toggle.offText = text
|
|
toggle.textSize = .small
|
|
toggle.textWeight = .bold
|
|
}
|
|
|
|
// MARK: - MoleculeViewProtocol
|
|
open override func reset() {
|
|
super.reset()
|
|
toggle.reset()
|
|
}
|
|
}
|
|
|
|
public class TestLabelToggleModel: MoleculeModelProtocol {
|
|
public static var identifier: String = "testLabelToggle"
|
|
public var moleculeName: String = TestLabelToggleModel.identifier
|
|
public var backgroundColor: Color?
|
|
public var label: LabelModel
|
|
public var toggle: TestToggleModel
|
|
|
|
public init(_ label: LabelModel, _ toggle: TestToggleModel) {
|
|
self.label = label
|
|
self.toggle = toggle
|
|
}
|
|
|
|
private enum CodingKeys: String, CodingKey {
|
|
case moleculeName
|
|
case backgroundColor
|
|
case label
|
|
case toggle
|
|
}
|
|
|
|
required public init(from decoder: Decoder) throws {
|
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey:.backgroundColor)
|
|
label = try typeContainer.decode(LabelModel.self, forKey:.label)
|
|
toggle = try typeContainer.decode(TestToggleModel.self, forKey:.toggle)
|
|
}
|
|
|
|
public func encode(to encoder: Encoder) throws {
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
try container.encode(moleculeName, forKey: .moleculeName)
|
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
|
try container.encode(label, forKey: .label)
|
|
try container.encode(toggle, forKey: .toggle)
|
|
}
|
|
}
|
|
|