From 4bd5006e5eb9f7e40308f4f4f9a9ce3a1480995b Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 11 Jun 2019 13:44:53 -0400 Subject: [PATCH] name reuse for molecules arrow change for molecule cell --- .../Molecules/MVMCoreUIMoleculeViewProtocol.h | 3 +++ MVMCoreUI/Molecules/MoleculeStackView.swift | 13 ++++++++++++ .../Molecules/MoleculeTableViewCell.swift | 20 +++++++++++++------ .../Templates/MoleculeListCellProtocol.h | 2 -- .../Templates/MoleculeListTemplate.swift | 2 +- 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h b/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h index 962b0c0c..9140245e 100644 --- a/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h +++ b/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h @@ -27,6 +27,9 @@ /// For the molecule list to load more efficiently. + (CGFloat)estimatedHeightForRow:(nullable NSDictionary *)json; +/// Allows the molecule to set its name for reuse. Default could be moleculeName. ++ (nullable NSString *)nameForReuse:(nullable NSDictionary *)molecule delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject; + @end diff --git a/MVMCoreUI/Molecules/MoleculeStackView.swift b/MVMCoreUI/Molecules/MoleculeStackView.swift index 0f539827..9bf0f5ab 100644 --- a/MVMCoreUI/Molecules/MoleculeStackView.swift +++ b/MVMCoreUI/Molecules/MoleculeStackView.swift @@ -200,6 +200,19 @@ public class MoleculeStackView: ViewConstrainingView { } } + public override static func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { + var name = "" + guard let molecules = molecule?.optionalArrayForKey(KeyMolecules) else { + return name + } + for case let item as [AnyHashable: AnyHashable] in molecules { + if let moleculeName = item.stringOptionalWithChainOfKeysOrIndexes([KeyMolecule, KeyMoleculeName]) { + name.append(moleculeName) + } + } + return name + } + // MARK: - Convenience Functions func clear() { MVMCoreUIStackableViewController.remove(contentView.subviews) diff --git a/MVMCoreUI/Molecules/MoleculeTableViewCell.swift b/MVMCoreUI/Molecules/MoleculeTableViewCell.swift index 298fa6b5..86f5a4dc 100644 --- a/MVMCoreUI/Molecules/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/MoleculeTableViewCell.swift @@ -119,6 +119,18 @@ import UIKit return estimatedHeightFor(moleculeJSON) } + public static func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { + if let molecule = molecule?.optionalDictionaryForKey(KeyMolecule), + let moleculeName = molecule.optionalStringForKey(KeyMoleculeName), + let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping[moleculeName] as? AnyClass, + let castClass = moleculeClass as? MVMCoreUIMoleculeViewProtocol.Type, + let nameFunc = castClass.name { + return nameFunc(molecule, delegateObject) + } else { + return molecule?.optionalDictionaryForKey(KeyMolecule)?.optionalStringForKey(KeyMoleculeName) + } + } + // MARK: - Arrow /// Adds the standard mvm style caret to the accessory view public func addCaretViewAccessory() { @@ -129,16 +141,12 @@ import UIKit let height: CGFloat = 10 caretView = CaretView(lineThickness: CaretView.thin) caretView?.frame = CGRect(x: 0, y: 0, width: width, height: height) - caretViewWidthSizeObject = MFSizeObject(scalingStandardSize: width) - caretViewHeightSizeObject = MFSizeObject(scalingStandardSize: height) + caretViewWidthSizeObject = MFSizeObject(standardSize: width, standardiPadPortraitSize: 9) + caretViewHeightSizeObject = MFSizeObject(standardSize: height, standardiPadPortraitSize: 16) accessoryView = caretView } // MARK: - MoleculeListCellProtocol - public static func moleculeName(_ molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { - return molecule?.optionalDictionaryForKey(KeyMolecule)?.optionalStringForKey(KeyMoleculeName) - } - /// For when the separator between cells shows using json and frequency. Default is type: standard, frequency: allExceptTop. public func setSeparatorWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?, indexPath: IndexPath) { addSeparatorsIfNeeded() diff --git a/MVMCoreUI/Templates/MoleculeListCellProtocol.h b/MVMCoreUI/Templates/MoleculeListCellProtocol.h index 08ca2a37..7603c820 100644 --- a/MVMCoreUI/Templates/MoleculeListCellProtocol.h +++ b/MVMCoreUI/Templates/MoleculeListCellProtocol.h @@ -10,8 +10,6 @@ @protocol MoleculeListCellProtocol @optional -/// Can override the molecule name for the given molecule. Otherwise we assume value for key moleculeName. -+ (nullable NSString *)moleculeName:(nullable NSDictionary *)molecule delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject; /// Can set the separator according to what the moleculeList commands. - (void)setSeparatorWithJSON:(nullable NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData indexPath:(nonnull NSIndexPath *)indexPath; diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index 490f2e1a..ea3f94b4 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -117,7 +117,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { guard let map = molecule.molecule, let moleculeName = map.optionalStringForKey(KeyMoleculeName), let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping[moleculeName] as? AnyClass else { return nil } - if let moleculeClass = moleculeClass as? MoleculeListCellProtocol.Type, let moleculeNameFunc = moleculeClass.moleculeName { + if let moleculeClass = moleculeClass as? MVMCoreUIMoleculeViewProtocol.Type, let moleculeNameFunc = moleculeClass.name { return (moleculeNameFunc(map, delegateObject() as? MVMCoreUIDelegateObject), moleculeClass) } else { return (moleculeName, moleculeClass)