temp fix for arch issue

This commit is contained in:
Kevin G Christiano 2020-01-23 19:59:05 -05:00
parent 8fb8694b82
commit 83d5721e68
11 changed files with 171 additions and 31 deletions

View File

@ -15,4 +15,12 @@
public override class var identifier: String { public override class var identifier: String {
return "" 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)
}
} }

View File

@ -38,6 +38,6 @@
public override func encode(to encoder: Encoder) throws { public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder) try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(dateFormat, forKey: .dateFormat) try container.encode(dateFormat, forKey: .dateFormat)
} }
} }

View File

@ -42,7 +42,7 @@
public override func encode(to encoder: Encoder) throws { public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder) try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(digits, forKey: .digits) try container.encode(digits, forKey: .digits)
try container.encodeIfPresent(secureEntry, forKey: .secureEntry) try container.encode(secureEntry, forKey: .secureEntry)
} }
} }

View File

@ -68,10 +68,10 @@ import Foundation
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(title, forKey: .title) try container.encodeIfPresent(title, forKey: .title)
try container.encodeIfPresent(feedback, forKey: .feedback) try container.encodeIfPresent(feedback, forKey: .feedback)
try container.encodeIfPresent(errorMessage, forKey: .errorMessage) try container.encode(errorMessage, forKey: .errorMessage)
try container.encodeIfPresent(isEnabled, forKey: .isEnabled) try container.encode(isEnabled, forKey: .isEnabled)
try container.encodeIfPresent(isLocked, forKey: .isLocked) try container.encode(isLocked, forKey: .isLocked)
try container.encodeIfPresent(isSelected, forKey: .isSelected) try container.encode(isSelected, forKey: .isSelected)
try container.encodeIfPresent(fieldKey, forKey: .fieldKey) try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
try container.encodeIfPresent(isValid, forKey: .isValid) try container.encodeIfPresent(isValid, forKey: .isValid)
} }

View File

@ -96,9 +96,11 @@ open class ItemDropdownEntryField: BaseDropdownEntryField {
guard let model = model as? ItemDropdownEntryFieldModel else { return } guard let model = model as? ItemDropdownEntryFieldModel else { return }
if let options = model.options { pickerData = model.options
pickerData = options setPickerDelegates(delegate: self)
setPickerDelegates(delegate: self)
if let pickerView = pickerView {
self.pickerView(pickerView, didSelectRow: 0, inComponent: 0)
} }
} }
} }

View File

@ -15,5 +15,29 @@
return "dropDown" 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)
}
} }

View File

@ -33,6 +33,14 @@ extension MFViewController: MoleculeDelegateProtocol {
@objc public func moleculeLayoutUpdated(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) { @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 { public extension MFViewController {

View File

@ -19,47 +19,49 @@ import UIKit
var previousIndex = NSNotFound var previousIndex = NSNotFound
//-------------------------------------------------- //--------------------------------------------------
// MARK: - MFViewProtocol // MARK: - Lifecycle
//-------------------------------------------------- //--------------------------------------------------
override public func setupView() { override public func setupView() {
super.setupView() super.setupView()
guard dropDown.superview == nil else { return } guard dropDown.superview == nil else { return }
addMolecule(dropDown)
contentView.addSubview(dropDown)
NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: dropDown, useMargins: true).values))
dropDown.observeDropdownChange = { [weak self] oldValue, newValue in dropDown.observeDropdownChange = { [weak self] oldValue, newValue in
guard newValue != oldValue, guard newValue != oldValue,
let self = self, let self = self,
let options = self.dropDown.json?.optionalArrayForKey("options") as? [NSString], let index = self.dropDown.pickerData.firstIndex(of: newValue),
let index = options.firstIndex(of: newValue as NSString), let molecules = self.dropDownListItemModel?.molecules
let molecules = self.dropDownListItemModel?.molecules else { return } else { return }
if self.previousIndex != NSNotFound { var json2d = [[[AnyHashable: Any]]]()
self.delegateObject?.moleculeDelegate?.removeMolecules(molecules[self.previousIndex], sender: self, animation: .fade)
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 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]?) { public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
dropDownListItemModel = model as? DropDownListItemModel dropDownListItemModel = model as? DropDownListItemModel
self.delegateObject = delegateObject self.delegateObject = delegateObject
super.setWithModel(model, delegateObject, additionalData) super.setWithModel(model, delegateObject, additionalData)
dropDown.setWithModel(dropDownListItemModel?.dropDown, delegateObject, additionalData)
dropDown.observingTextFieldDelegate = delegateObject?.uiTextFieldDelegate as? ObservingTextFieldDelegate dropDown.observingTextFieldDelegate = delegateObject?.uiTextFieldDelegate as? ObservingTextFieldDelegate
dropDown.uiTextFieldDelegate = delegateObject?.uiTextFieldDelegate dropDown.uiTextFieldDelegate = delegateObject?.uiTextFieldDelegate
dropDown.setWithModel(dropDownListItemModel, delegateObject, additionalData)
} }
public override func reset() { public override func reset() {

View File

@ -9,6 +9,9 @@
import Foundation import Foundation
@objcMembers public class DropDownListItemModel: ContainerModel, ListItemModelProtocol { @objcMembers public class DropDownListItemModel: ContainerModel, ListItemModelProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "dropDownListItem" public static var identifier: String = "dropDownListItem"
public var molecules: [[ListItemModelProtocol]] public var molecules: [[ListItemModelProtocol]]
@ -16,12 +19,37 @@ import Foundation
public var backgroundColor: Color? public var backgroundColor: Color?
public var line: LineModel? = LineModel(type: .none) public var line: LineModel? = LineModel(type: .none)
public var hideArrow: Bool? = true 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) { public init(molecules: [[ListItemModelProtocol]], dropDown: ItemDropdownEntryFieldModel) {
self.molecules = molecules self.molecules = molecules
self.dropDown = dropDown self.dropDown = dropDown
super.init() super.init()
setDefaults()
} }
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case molecules case molecules
@ -29,10 +57,14 @@ import Foundation
case line case line
case backgroundColor case backgroundColor
} }
//--------------------------------------------------
// MARK: - Codec
//--------------------------------------------------
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) 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) dropDown = try typeContainer.decode(ItemDropdownEntryFieldModel.self, forKey: .dropDown)
if let lineModel = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) { if let lineModel = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) {
@ -41,6 +73,7 @@ import Foundation
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
try super.init(from: decoder) try super.init(from: decoder)
setDefaults()
} }
public override func encode(to encoder: Encoder) throws { public override func encode(to encoder: Encoder) throws {

View File

@ -31,15 +31,19 @@ extension MoleculeDelegateProtocol {
public func moleculeLayoutUpdated(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) { public func moleculeLayoutUpdated(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) {
// Do Nothing // Do Nothing
} }
public func addMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { 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) { public func removeMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) {
// Do nothing // Do nothing
} }
public func addMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) { 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) { public func removeMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) {
// Do nothing // Do nothing
} }

View File

@ -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) { 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. // This dispatch is needed to fix a race condition that can occur if this function is called during the table setup.
DispatchQueue.main.async { DispatchQueue.main.async {
@ -164,6 +222,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
self.view.layoutIfNeeded() self.view.layoutIfNeeded()
} }
} }
public func removeMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) { public func removeMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) {
var indexPaths: [IndexPath] = [] var indexPaths: [IndexPath] = []
//TODO: cehck for molecule protocola eqality //TODO: cehck for molecule protocola eqality