Move molecule layout update back

This commit is contained in:
Pfeil, Scott Robert 2021-07-26 19:11:17 -04:00
parent dc12612c6f
commit 4108cfb7c6
9 changed files with 26 additions and 18 deletions

View File

@ -26,7 +26,7 @@ open class Tags: View, MFButtonProtocol {
DispatchQueue.main.async { DispatchQueue.main.async {
self.collectionView.collectionViewLayout.invalidateLayout() self.collectionView.collectionViewLayout.invalidateLayout()
self.collectionViewHeight.constant = self.collectionView.contentSize.height self.collectionViewHeight.constant = self.collectionView.contentSize.height
self.delegateObject?.moleculeListDelegate?.moleculeLayoutUpdated(self) self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
} }
} }

View File

@ -96,7 +96,7 @@ open class RadioSwatches: View {
height != oldHeight { height != oldHeight {
// Notify delegate of height change, called async to avoid various race conditions caused while happening while laying out initially. // Notify delegate of height change, called async to avoid various race conditions caused while happening while laying out initially.
DispatchQueue.main.async { DispatchQueue.main.async {
self.delegateObject?.moleculeListDelegate?.moleculeLayoutUpdated(self) self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
} }
} }
collectionViewHeight?.constant = CGFloat(height) collectionViewHeight?.constant = CGFloat(height)

View File

@ -331,7 +331,7 @@
self.addConstraints(width: width, height: height, size: image?.size) self.addConstraints(width: width, height: height, size: image?.size)
self.loadingSpinnerHeightConstraint?.constant = 0 self.loadingSpinnerHeightConstraint?.constant = 0
if layoutWillChange { if layoutWillChange {
self.delegateObject?.moleculeListDelegate?.moleculeLayoutUpdated(self) self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
} }
completionBlock(image,data,isFallbackImage) completionBlock(image,data,isFallbackImage)
})} })}

View File

@ -148,7 +148,7 @@ extension WebView : WKUIDelegate {
//if failed to get height from javascript, using scrollview.contensize's height //if failed to get height from javascript, using scrollview.contensize's height
self.webViewHeight?.constant = webView.scrollView.contentSize.height self.webViewHeight?.constant = webView.scrollView.contentSize.height
} }
self.delegateObject?.moleculeListDelegate?.moleculeLayoutUpdated(self) self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
}) })
}) })
} }

View File

@ -15,4 +15,12 @@ public protocol MoleculeDelegateProtocol: AnyObject {
func getModuleWithName(_ name: String?) -> [AnyHashable: Any]? func getModuleWithName(_ name: String?) -> [AnyHashable: Any]?
func getModuleWithName(_ moleculeName: String) -> MoleculeModelProtocol? 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) { }
} }

View File

@ -16,9 +16,6 @@ public protocol MoleculeListProtocol {
/// Asks the delegate to remove molecules. /// Asks the delegate to remove molecules.
func removeMolecules(at indexPaths: [IndexPath], animation: UITableView.RowAnimation?) 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 { extension MoleculeListProtocol {

View File

@ -182,6 +182,15 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
// MARK: - MoleculeDelegateProtocol // 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) { open func newData(for molecule: MoleculeModelProtocol) {
//TODO: expand for header, navigation, etc //TODO: expand for header, navigation, etc
let json = molecule.toJSON() let json = molecule.toJSON()
@ -326,13 +335,4 @@ extension MoleculeListTemplate: MoleculeListProtocol {
return IndexPath(row: index, section: 0) 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()
}
}
} }

View File

@ -505,6 +505,9 @@ import UIKit
return nil return nil
} }
// Needed otherwise when subclassed, the extension gets called.
open func moleculeLayoutUpdated(_ molecule: MoleculeViewProtocol) { }
//-------------------------------------------------- //--------------------------------------------------
// MARK: - MVMCoreUIDetailViewProtocol // MARK: - MVMCoreUIDetailViewProtocol
//-------------------------------------------------- //--------------------------------------------------

View File

@ -270,7 +270,7 @@ import UIKit
bottomBar?.frame = CGRect(x: 0, y: bounds.height - size, width: bounds.width, height: size) bottomBar?.frame = CGRect(x: 0, y: bounds.height - size, width: bounds.width, height: size)
if updateMoleculeLayout || heightChanged { if updateMoleculeLayout || heightChanged {
delegateObject?.moleculeListDelegate?.moleculeLayoutUpdated(self) delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
} }
setNeedsDisplay() setNeedsDisplay()