temp fix for arch issue
This commit is contained in:
parent
8fb8694b82
commit
83d5721e68
@ -15,4 +15,12 @@
|
||||
public override class var identifier: String {
|
||||
return ""
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
try super.init(from: decoder)
|
||||
}
|
||||
|
||||
public override func encode(to encoder: Encoder) throws {
|
||||
try super.encode(to: encoder)
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,6 +38,6 @@
|
||||
public override func encode(to encoder: Encoder) throws {
|
||||
try super.encode(to: encoder)
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encodeIfPresent(dateFormat, forKey: .dateFormat)
|
||||
try container.encode(dateFormat, forKey: .dateFormat)
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@
|
||||
public override func encode(to encoder: Encoder) throws {
|
||||
try super.encode(to: encoder)
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encodeIfPresent(digits, forKey: .digits)
|
||||
try container.encodeIfPresent(secureEntry, forKey: .secureEntry)
|
||||
try container.encode(digits, forKey: .digits)
|
||||
try container.encode(secureEntry, forKey: .secureEntry)
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,10 +68,10 @@ import Foundation
|
||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||
try container.encodeIfPresent(title, forKey: .title)
|
||||
try container.encodeIfPresent(feedback, forKey: .feedback)
|
||||
try container.encodeIfPresent(errorMessage, forKey: .errorMessage)
|
||||
try container.encodeIfPresent(isEnabled, forKey: .isEnabled)
|
||||
try container.encodeIfPresent(isLocked, forKey: .isLocked)
|
||||
try container.encodeIfPresent(isSelected, forKey: .isSelected)
|
||||
try container.encode(errorMessage, forKey: .errorMessage)
|
||||
try container.encode(isEnabled, forKey: .isEnabled)
|
||||
try container.encode(isLocked, forKey: .isLocked)
|
||||
try container.encode(isSelected, forKey: .isSelected)
|
||||
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
|
||||
try container.encodeIfPresent(isValid, forKey: .isValid)
|
||||
}
|
||||
|
||||
@ -96,9 +96,11 @@ open class ItemDropdownEntryField: BaseDropdownEntryField {
|
||||
|
||||
guard let model = model as? ItemDropdownEntryFieldModel else { return }
|
||||
|
||||
if let options = model.options {
|
||||
pickerData = options
|
||||
setPickerDelegates(delegate: self)
|
||||
pickerData = model.options
|
||||
setPickerDelegates(delegate: self)
|
||||
|
||||
if let pickerView = pickerView {
|
||||
self.pickerView(pickerView, didSelectRow: 0, inComponent: 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,5 +15,29 @@
|
||||
return "dropDown"
|
||||
}
|
||||
|
||||
public var options: [String]?
|
||||
public var options: [String] = []
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Keys
|
||||
//--------------------------------------------------
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case options
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
//--------------------------------------------------
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
try super.init(from: decoder)
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
options = try typeContainer.decodeIfPresent([String].self, forKey: .options) ?? []
|
||||
}
|
||||
|
||||
public override func encode(to encoder: Encoder) throws {
|
||||
try super.encode(to: encoder)
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(options, forKey: .options)
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,6 +33,14 @@ extension MFViewController: MoleculeDelegateProtocol {
|
||||
@objc public func moleculeLayoutUpdated(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) {
|
||||
|
||||
}
|
||||
|
||||
@objc public func addMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@objc public func removeMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
public extension MFViewController {
|
||||
|
||||
@ -19,47 +19,49 @@ import UIKit
|
||||
var previousIndex = NSNotFound
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - MFViewProtocol
|
||||
// MARK: - Lifecycle
|
||||
//--------------------------------------------------
|
||||
|
||||
override public func setupView() {
|
||||
super.setupView()
|
||||
|
||||
guard dropDown.superview == nil else { return }
|
||||
|
||||
contentView.addSubview(dropDown)
|
||||
NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: dropDown, useMargins: true).values))
|
||||
|
||||
addMolecule(dropDown)
|
||||
dropDown.observeDropdownChange = { [weak self] oldValue, newValue in
|
||||
|
||||
guard newValue != oldValue,
|
||||
let self = self,
|
||||
let options = self.dropDown.json?.optionalArrayForKey("options") as? [NSString],
|
||||
let index = options.firstIndex(of: newValue as NSString),
|
||||
let molecules = self.dropDownListItemModel?.molecules else { return }
|
||||
let index = self.dropDown.pickerData.firstIndex(of: newValue),
|
||||
let molecules = self.dropDownListItemModel?.molecules
|
||||
else { return }
|
||||
|
||||
if self.previousIndex != NSNotFound {
|
||||
self.delegateObject?.moleculeDelegate?.removeMolecules(molecules[self.previousIndex], sender: self, animation: .fade)
|
||||
var json2d = [[[AnyHashable: Any]]]()
|
||||
|
||||
for moleculeList in molecules {
|
||||
var json1d = [[AnyHashable: Any]]()
|
||||
for molecule in moleculeList {
|
||||
json1d.append((molecule as? ListItemModel)!.toJSON()!)
|
||||
}
|
||||
json2d.append(json1d)
|
||||
}
|
||||
|
||||
self.delegateObject?.moleculeDelegate?.addMolecules(molecules[index], sender: self, animation: .fade)
|
||||
if self.previousIndex != NSNotFound {
|
||||
self.delegateObject?.moleculeDelegate?.removeMolecules(json2d[self.previousIndex], sender: self, animation: .fade)
|
||||
}
|
||||
|
||||
self.delegateObject?.moleculeDelegate?.addMolecules(json2d[index], sender: self, animation: .fade)
|
||||
self.previousIndex = index
|
||||
}
|
||||
}
|
||||
|
||||
public override func updateView(_ size: CGFloat) {
|
||||
super.updateView(size)
|
||||
dropDown.updateView(size)
|
||||
}
|
||||
|
||||
public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
dropDownListItemModel = model as? DropDownListItemModel
|
||||
self.delegateObject = delegateObject
|
||||
super.setWithModel(model, delegateObject, additionalData)
|
||||
|
||||
dropDown.setWithModel(dropDownListItemModel?.dropDown, delegateObject, additionalData)
|
||||
dropDown.observingTextFieldDelegate = delegateObject?.uiTextFieldDelegate as? ObservingTextFieldDelegate
|
||||
dropDown.uiTextFieldDelegate = delegateObject?.uiTextFieldDelegate
|
||||
dropDown.setWithModel(dropDownListItemModel, delegateObject, additionalData)
|
||||
}
|
||||
|
||||
public override func reset() {
|
||||
|
||||
@ -9,6 +9,9 @@
|
||||
import Foundation
|
||||
|
||||
@objcMembers public class DropDownListItemModel: ContainerModel, ListItemModelProtocol {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
|
||||
public static var identifier: String = "dropDownListItem"
|
||||
public var molecules: [[ListItemModelProtocol]]
|
||||
@ -16,12 +19,37 @@ import Foundation
|
||||
public var backgroundColor: Color?
|
||||
public var line: LineModel? = LineModel(type: .none)
|
||||
public var hideArrow: Bool? = true
|
||||
|
||||
/// Defaults to set
|
||||
func setDefaults() {
|
||||
if useHorizontalMargins == nil {
|
||||
useHorizontalMargins = true
|
||||
}
|
||||
if useVerticalMargins == nil {
|
||||
useVerticalMargins = true
|
||||
}
|
||||
if topMarginPadding == nil {
|
||||
topMarginPadding = 24
|
||||
}
|
||||
if bottomMarginPadding == nil {
|
||||
bottomMarginPadding = 0
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializer
|
||||
//--------------------------------------------------
|
||||
|
||||
public init(molecules: [[ListItemModelProtocol]], dropDown: ItemDropdownEntryFieldModel) {
|
||||
self.molecules = molecules
|
||||
self.dropDown = dropDown
|
||||
super.init()
|
||||
setDefaults()
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Keys
|
||||
//--------------------------------------------------
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case molecules
|
||||
@ -29,10 +57,14 @@ import Foundation
|
||||
case line
|
||||
case backgroundColor
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Codec
|
||||
//--------------------------------------------------
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
molecules = try typeContainer.decodeMolecules2D(codingKey: .molecules) as! [[ListItemModelProtocol]]
|
||||
molecules = try typeContainer.decodeMolecules2D(codingKey: .molecules) as? [[ListItemModelProtocol]] ?? [[]]
|
||||
dropDown = try typeContainer.decode(ItemDropdownEntryFieldModel.self, forKey: .dropDown)
|
||||
|
||||
if let lineModel = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) {
|
||||
@ -41,6 +73,7 @@ import Foundation
|
||||
|
||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||
try super.init(from: decoder)
|
||||
setDefaults()
|
||||
}
|
||||
|
||||
public override func encode(to encoder: Encoder) throws {
|
||||
|
||||
@ -31,15 +31,19 @@ extension MoleculeDelegateProtocol {
|
||||
public func moleculeLayoutUpdated(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) {
|
||||
// Do Nothing
|
||||
}
|
||||
|
||||
public func addMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
||||
// Do nothpublic ing
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
public func removeMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
public func addMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
||||
// Do nothpublic ing
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
public func removeMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@ -146,6 +146,64 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
||||
}
|
||||
}
|
||||
|
||||
public override func addMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
||||
|
||||
var tmpMolecules = [ListItemModelProtocol]()
|
||||
|
||||
molecules.forEach { molecule in
|
||||
|
||||
let data = try? JSONSerialization.data(withJSONObject: molecule)
|
||||
let decoder = JSONDecoder()
|
||||
let listItemModel = try? decoder.decode(ListItemModel.self, from: data!)
|
||||
|
||||
tmpMolecules.append(listItemModel!)
|
||||
}
|
||||
|
||||
DispatchQueue.main.async {
|
||||
guard let indexPath = self.tableView?.indexPath(for: sender) else { return }
|
||||
var indexPaths: [IndexPath] = []
|
||||
for molecule in molecules {
|
||||
if let info = self.getMoleculeInfo(with: tmpMolecules as! ListItemModelProtocol) {
|
||||
self.tableView?.register(info.class, forCellReuseIdentifier: info.identifier)
|
||||
let index = indexPath.row + 1 + indexPaths.count
|
||||
self.moleculesInfo?.insert(info, at: index)
|
||||
indexPaths.append(IndexPath(row: index, section: 0))
|
||||
}
|
||||
}
|
||||
self.tableView?.insertRows(at: indexPaths, with: animation)
|
||||
self.updateViewConstraints()
|
||||
self.view.layoutIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
public override func removeMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
||||
|
||||
var tmpMolecules = [ListItemModelProtocol]()
|
||||
|
||||
molecules.forEach { molecule in
|
||||
|
||||
let data = try? JSONSerialization.data(withJSONObject: molecule)
|
||||
let decoder = JSONDecoder()
|
||||
let listItemModel = try? decoder.decode(ListItemModel.self, from: data!)
|
||||
|
||||
tmpMolecules.append(listItemModel!)
|
||||
}
|
||||
|
||||
var indexPaths: [IndexPath] = []
|
||||
//TODO: cehck for molecule protocola eqality
|
||||
for molecule in tmpMolecules {
|
||||
if let removeIndex = moleculesInfo?.firstIndex(where: { (moleculeInfo) -> Bool in
|
||||
return molecule.toJSONString() == moleculeInfo.molecule.toJSONString()
|
||||
}) {
|
||||
moleculesInfo?.remove(at: removeIndex)
|
||||
indexPaths.append(IndexPath(row: removeIndex + indexPaths.count, section: 0))
|
||||
}
|
||||
}
|
||||
self.tableView?.deleteRows(at: indexPaths, with: animation)
|
||||
self.updateViewConstraints()
|
||||
self.view.layoutIfNeeded()
|
||||
}
|
||||
|
||||
public func addMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
||||
// This dispatch is needed to fix a race condition that can occur if this function is called during the table setup.
|
||||
DispatchQueue.main.async {
|
||||
@ -164,6 +222,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
||||
self.view.layoutIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
public func removeMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
||||
var indexPaths: [IndexPath] = []
|
||||
//TODO: cehck for molecule protocola eqality
|
||||
|
||||
Loading…
Reference in New Issue
Block a user