From 047d9b7014a8b9e2b5e2684e7925c8df1047e952 Mon Sep 17 00:00:00 2001 From: vimal Date: Wed, 3 Jan 2024 15:23:29 +0530 Subject: [PATCH 1/2] enhancement on the header update based on the molecules --- .../Atomic/Templates/MoleculeListTemplate.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift index 1af1a85a..fe30288a 100644 --- a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift @@ -202,7 +202,21 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol } open func newData(for molecule: MoleculeModelProtocol) { - //TODO: expand for header, navigation, etc + + if let headerMolecule = molecule as? MoleculeHeaderModel { + //If complete header replaced then it makes sense to add this + /*createViewForTableHeader() + let width = view.bounds.width + if let topView = topView as? MVMCoreViewProtocol { + topView.updateView(width) + showHeader(width) + }*/ + //Just update is happening only on the existing molecules. ex. changing the title, action etc.. + (topView as? MoleculeViewProtocol)?.set(with: headerMolecule, delegateObject() as? MVMCoreUIDelegateObject, nil) + return + } + + //TODO: expand for navigation, etc guard let moleculesInfo = moleculesInfo else { return } let indicies = moleculesInfo.indices.filter({ index -> Bool in From db7e59191a8eecddf85decfa08f0ed42c3aa64eb Mon Sep 17 00:00:00 2001 From: vimal Date: Wed, 3 Jan 2024 23:25:48 +0530 Subject: [PATCH 2/2] fix for button model review comment updated --- .../Atoms/Buttons/ImageButtonModel.swift | 10 ++++++- .../Templates/MoleculeListTemplate.swift | 27 ++++++++++++------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/ImageButtonModel.swift b/MVMCoreUI/Atomic/Atoms/Buttons/ImageButtonModel.swift index a61ec150..5a53e637 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/ImageButtonModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/ImageButtonModel.swift @@ -8,7 +8,7 @@ import Foundation -open class ImageButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWatcherFieldProtocol { +open class ImageButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWatcherFieldProtocol, ParentMoleculeModelProtocol { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- @@ -29,6 +29,14 @@ open class ImageButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGro public var updateUI: ActionBlock? + public var children: [MoleculeModelProtocol] { + [image].compactMap({$0}) + } + + public func replaceChildMolecule(with molecule: MoleculeModelProtocol) throws -> Bool { + return try replaceChildMolecule(at: &image, with: molecule) + } + public init(image: ImageViewModel?, action: ActionModelProtocol) { self.image = image self.action = action diff --git a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift index fe30288a..cc76ef34 100644 --- a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift @@ -203,16 +203,13 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol open func newData(for molecule: MoleculeModelProtocol) { - if let headerMolecule = molecule as? MoleculeHeaderModel { - //If complete header replaced then it makes sense to add this - /*createViewForTableHeader() - let width = view.bounds.width - if let topView = topView as? MVMCoreViewProtocol { - topView.updateView(width) - showHeader(width) - }*/ - //Just update is happening only on the existing molecules. ex. changing the title, action etc.. - (topView as? MoleculeViewProtocol)?.set(with: headerMolecule, delegateObject() as? MVMCoreUIDelegateObject, nil) + //Update the header + if updateHeaderFooter(modelView: topView, molecule: molecule) { + return + } + + //Update the footer + if updateHeaderFooter(modelView: bottomView, molecule: molecule) { return } @@ -235,6 +232,16 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol tableView.selectRow(at: selectedIndex, animated: false, scrollPosition: .none) } } + + ///Helper functions to update the header/footer view + private func updateHeaderFooter(modelView: UIView?, molecule: MoleculeModelProtocol) -> Bool { + if let updateView = modelView, + let moleculeView = MVMCoreUIUtility.findViews(by: MoleculeViewProtocol.self, views: [updateView]).first(where: { $0.model?.moleculeName == molecule.moleculeName && $0.model?.id == molecule.id }) { + updateMoleculeView(moleculeView, from: molecule) + return true + } + return false + } //-------------------------------------------------- // MARK: - Convenience