From dace6a6374c4bbfa33bcff56673cefaf71cf2d2f Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 23 Jul 2019 09:55:43 -0400 Subject: [PATCH 1/3] update table cell --- MVMCoreUI/Atoms/Views/MFLoadImageView.swift | 4 ++++ MVMCoreUI/OtherHandlers/MoleculeDelegateProtocol.h | 4 ++++ MVMCoreUI/Templates/MoleculeListTemplate.swift | 10 ++++++++++ 3 files changed, 18 insertions(+) diff --git a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift index 703ffd65..996dea95 100644 --- a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift +++ b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift @@ -22,6 +22,8 @@ import UIKit var imageWidth: CGFloat? var imageHeight: CGFloat? + var delegateObject: MVMCoreUIDelegateObject? + // For keeping track of current state. private var edges: UIRectEdge? private var spinnerHeight: CGFloat? @@ -190,6 +192,7 @@ import UIKit open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + self.delegateObject = delegateObject if let accessibilityString = json?.optionalStringForKey("accessibilityText") { imageView.accessibilityLabel = accessibilityString imageView.accessibilityTraits = .staticText @@ -223,6 +226,7 @@ import UIKit self?.loadingSpinnerHeightConstraint?.constant = 0 self?.loadingSpinner.pause() self?.addConstraints(width: width, height: height, size: image?.size) + self?.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated?(self!) completionHandler(image,data,isFallbackImage) })} diff --git a/MVMCoreUI/OtherHandlers/MoleculeDelegateProtocol.h b/MVMCoreUI/OtherHandlers/MoleculeDelegateProtocol.h index 0d027386..fa91e0fc 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeDelegateProtocol.h +++ b/MVMCoreUI/OtherHandlers/MoleculeDelegateProtocol.h @@ -12,4 +12,8 @@ /// returns a module for the corresponding module name. - (nullable NSDictionary *)getModuleWithName:(nullable NSString *)name; +@optional +/// Notifies the delegate that the molecule layout update. Should be called when the layout may change due to an async method. +- (void)moleculeLayoutUpdated:(nonnull UIView *)molecule; + @end diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index f3a4f310..ec2f2ff7 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -106,6 +106,16 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { return loadObject?.requestParameters?.modules } + // MARK: - MoleculeDelegateProtocol + open override func moleculeLayoutUpdated(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) { + if let tableView = tableView { + let point = molecule.convert(molecule.bounds.origin, to: tableView) + if let indexPath = tableView.indexPathForRow(at: point) { + tableView.reloadRows(at: [indexPath], with: .none) + } + } + } + // MARK: - Convenience /// Returns the (identifier, class) of the molecule for the given map. func getMoleculeInfo(with molecule: [AnyHashable: Any]?) -> (identifier: String, class: AnyClass, molecule: [AnyHashable: Any])? { From 482c6c4fababeb1bb7980face7995612a3e7e9e0 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 23 Jul 2019 09:56:49 -0400 Subject: [PATCH 2/3] auto looks better --- MVMCoreUI/Templates/MoleculeListTemplate.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index ec2f2ff7..693a8c4d 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -111,7 +111,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { if let tableView = tableView { let point = molecule.convert(molecule.bounds.origin, to: tableView) if let indexPath = tableView.indexPathForRow(at: point) { - tableView.reloadRows(at: [indexPath], with: .none) + tableView.reloadRows(at: [indexPath], with: .automatic) } } } From 6537523373fac2b8ea095eae577b2e2cf00c3454 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 23 Jul 2019 11:57:03 -0400 Subject: [PATCH 3/3] different way to update --- MVMCoreUI/Templates/MoleculeListTemplate.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index 693a8c4d..abec1b01 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -110,8 +110,9 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { open override func moleculeLayoutUpdated(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) { if let tableView = tableView { let point = molecule.convert(molecule.bounds.origin, to: tableView) - if let indexPath = tableView.indexPathForRow(at: point) { - tableView.reloadRows(at: [indexPath], with: .automatic) + if let indexPath = tableView.indexPathForRow(at: point), tableView.indexPathsForVisibleRows?.contains(indexPath) ?? false { + tableView.beginUpdates() + tableView.endUpdates() } } }