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..abec1b01 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -106,6 +106,17 @@ 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.indexPathsForVisibleRows?.contains(indexPath) ?? false { + tableView.beginUpdates() + tableView.endUpdates() + } + } + } + // 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])? {