diff --git a/MVMCoreUI/Atomic/Templates/CollectionTemplate.swift b/MVMCoreUI/Atomic/Templates/CollectionTemplate.swift index e4e50d89..896aa5bf 100644 --- a/MVMCoreUI/Atomic/Templates/CollectionTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/CollectionTemplate.swift @@ -80,11 +80,15 @@ } + open override func handleNewData() { + setup() + registerCells() + super.handleNewData() + } + open override func updateUI() { topViewOutsideOfScrollArea = templateModel?.anchorHeader ?? false bottomViewOutsideOfScrollArea = templateModel?.anchorFooter ?? false - setup() - registerCells() super.updateUI() } diff --git a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift index 0605e4e6..406f72a9 100644 --- a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift @@ -81,11 +81,15 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol return molecule } + open override func handleNewData() { + setup() + registerWithTable() + super.handleNewData() // Currently stuck as MoleculeListProtocol being called from AddRemoveMoleculesBehaviorModel. + } + open override func updateUI() { topViewOutsideOfScrollArea = templateModel?.anchorHeader ?? false bottomViewOutsideOfScrollArea = templateModel?.anchorFooter ?? false - setup() - registerWithTable() super.updateUI() } diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index 1b4e5728..37051176 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -232,16 +232,6 @@ import MVMCore return true } - @MainActor - open func updateUI() { - if let backgroundColor = model?.backgroundColor { - view.backgroundColor = backgroundColor.uiColor - } - - needsUpdateUI = true - view.setNeedsLayout() - } - /// Creates a legacy navigation model. open func createDefaultLegacyNavigationModel() -> NavigationItemModel { let navigationModel = NavigationItemModel() @@ -249,7 +239,7 @@ import MVMCore return navigationModel } - /// Processes any new data. Called after the page is loaded the first time and on response updates for this page, + /// Processes any new data. Called after the page is loaded the first time and on response updates for this page, Triggers a render refresh. @MainActor open func handleNewData() { if model?.navigationBar == nil { @@ -269,7 +259,24 @@ import MVMCore // Notify the manager of new data manager?.newDataReceived?(in: self) - updateUI() + Task { @MainActor in + updateUI() + } + } + + /// Applies the latest model to the UI. + @MainActor + open func updateUI() { + executeBehaviors { (behavior: PageMoleculeTransformationBehavior) in + behavior.willRender(rootMolecules: getRootMolecules(), delegateObjectIVar) + } + + if let backgroundColor = model?.backgroundColor { + view.backgroundColor = backgroundColor.uiColor + } + + needsUpdateUI = true + view.setNeedsLayout() } public func generateMoleculeView(from model: MoleculeModelProtocol) -> MoleculeViewProtocol? {