diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/Tags/Tags.swift b/MVMCoreUI/Atomic/Atoms/FormFields/Tags/Tags.swift index be518465..4b1fa4f9 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/Tags/Tags.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/Tags/Tags.swift @@ -26,7 +26,7 @@ open class Tags: View, MFButtonProtocol { DispatchQueue.main.async { self.collectionView.collectionViewLayout.invalidateLayout() self.collectionViewHeight.constant = self.collectionView.contentSize.height - self.delegateObject?.moleculeListDelegate?.moleculeLayoutUpdated(self) + self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self) } } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatches.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatches.swift index 8587bb2f..5a5b6836 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatches.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatches.swift @@ -96,7 +96,7 @@ open class RadioSwatches: View { height != oldHeight { // Notify delegate of height change, called async to avoid various race conditions caused while happening while laying out initially. DispatchQueue.main.async { - self.delegateObject?.moleculeListDelegate?.moleculeLayoutUpdated(self) + self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self) } } collectionViewHeight?.constant = CGFloat(height) diff --git a/MVMCoreUI/Atomic/Atoms/Views/LoadImageView.swift b/MVMCoreUI/Atomic/Atoms/Views/LoadImageView.swift index fa3d290c..8d8ef49e 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/LoadImageView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/LoadImageView.swift @@ -331,7 +331,7 @@ self.addConstraints(width: width, height: height, size: image?.size) self.loadingSpinnerHeightConstraint?.constant = 0 if layoutWillChange { - self.delegateObject?.moleculeListDelegate?.moleculeLayoutUpdated(self) + self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self) } completionBlock(image,data,isFallbackImage) })} diff --git a/MVMCoreUI/Atomic/Atoms/Views/WebView.swift b/MVMCoreUI/Atomic/Atoms/Views/WebView.swift index d75c59ab..e6708055 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/WebView.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/WebView.swift @@ -148,7 +148,7 @@ extension WebView : WKUIDelegate { //if failed to get height from javascript, using scrollview.contensize's height self.webViewHeight?.constant = webView.scrollView.contentSize.height } - self.delegateObject?.moleculeListDelegate?.moleculeLayoutUpdated(self) + self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self) }) }) } diff --git a/MVMCoreUI/Atomic/Protocols/MoleculeDelegateProtocol.swift b/MVMCoreUI/Atomic/Protocols/MoleculeDelegateProtocol.swift index 25bddd08..1d0a3f61 100644 --- a/MVMCoreUI/Atomic/Protocols/MoleculeDelegateProtocol.swift +++ b/MVMCoreUI/Atomic/Protocols/MoleculeDelegateProtocol.swift @@ -15,4 +15,12 @@ public protocol MoleculeDelegateProtocol: AnyObject { func getModuleWithName(_ name: String?) -> [AnyHashable: Any]? func getModuleWithName(_ moleculeName: String) -> MoleculeModelProtocol? + + /// Notifies the delegate that the molecule layout update. Should be called when the layout may change due to an async method. Mainly used for list or collections. + func moleculeLayoutUpdated(_ molecule: MoleculeViewProtocol) //optional +} + +extension MoleculeDelegateProtocol { + + public func moleculeLayoutUpdated(_ molecule: MoleculeViewProtocol) { } } diff --git a/MVMCoreUI/Atomic/Protocols/MoleculeListProtocol.swift b/MVMCoreUI/Atomic/Protocols/MoleculeListProtocol.swift index 091fa00b..dfeb7b11 100644 --- a/MVMCoreUI/Atomic/Protocols/MoleculeListProtocol.swift +++ b/MVMCoreUI/Atomic/Protocols/MoleculeListProtocol.swift @@ -16,9 +16,6 @@ public protocol MoleculeListProtocol { /// Asks the delegate to remove molecules. func removeMolecules(at indexPaths: [IndexPath], animation: UITableView.RowAnimation?) - - /// Notifies the delegate that the molecule layout update. Should be called when the layout may change due to an async method. Mainly used for list or collections. - func moleculeLayoutUpdated(_ molecule: MoleculeViewProtocol) } extension MoleculeListProtocol { diff --git a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift index 2447aedb..843d807e 100644 --- a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift @@ -182,6 +182,15 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol // MARK: - MoleculeDelegateProtocol //-------------------------------------------------- + open override func moleculeLayoutUpdated(_ molecule: MoleculeViewProtocol) { + guard let tableView = tableView else { return } + + let point = molecule.convert(molecule.bounds.origin, to: tableView) + if let indexPath = tableView.indexPathForRow(at: point), tableView.indexPathsForVisibleRows?.contains(indexPath) ?? false { + performTableViewUpdates() + } + } + open func newData(for molecule: MoleculeModelProtocol) { //TODO: expand for header, navigation, etc let json = molecule.toJSON() @@ -326,13 +335,4 @@ extension MoleculeListTemplate: MoleculeListProtocol { return IndexPath(row: index, section: 0) } - - open func moleculeLayoutUpdated(_ molecule: MoleculeViewProtocol) { - guard let tableView = tableView else { return } - - let point = molecule.convert(molecule.bounds.origin, to: tableView) - if let indexPath = tableView.indexPathForRow(at: point), tableView.indexPathsForVisibleRows?.contains(indexPath) ?? false { - performTableViewUpdates() - } - } } diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index 59a06018..91f98d19 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -504,7 +504,10 @@ import UIKit return nil } - + + // Needed otherwise when subclassed, the extension gets called. + open func moleculeLayoutUpdated(_ molecule: MoleculeViewProtocol) { } + //-------------------------------------------------- // MARK: - MVMCoreUIDetailViewProtocol //-------------------------------------------------- diff --git a/MVMCoreUI/Containers/Views/EntryFieldContainer.swift b/MVMCoreUI/Containers/Views/EntryFieldContainer.swift index 52be603f..9ccd1d25 100644 --- a/MVMCoreUI/Containers/Views/EntryFieldContainer.swift +++ b/MVMCoreUI/Containers/Views/EntryFieldContainer.swift @@ -270,7 +270,7 @@ import UIKit bottomBar?.frame = CGRect(x: 0, y: bounds.height - size, width: bounds.width, height: size) if updateMoleculeLayout || heightChanged { - delegateObject?.moleculeListDelegate?.moleculeLayoutUpdated(self) + delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self) } setNeedsDisplay()