From 03ea6c528c4eb0b538e50e6387e2b6bb86d30d8c Mon Sep 17 00:00:00 2001 From: vimal Date: Thu, 4 Jan 2024 11:07:34 +0530 Subject: [PATCH 1/2] minor cleanup --- .../Templates/MoleculeListTemplate.swift | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift index cc76ef34..a0f6743c 100644 --- a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift @@ -203,17 +203,10 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol open func newData(for molecule: MoleculeModelProtocol) { - //Update the header - if updateHeaderFooter(modelView: topView, molecule: molecule) { + if updateMoleculeViewByModelId(molecule: molecule) { return } - //Update the footer - if updateHeaderFooter(modelView: bottomView, molecule: molecule) { - return - } - - //TODO: expand for navigation, etc guard let moleculesInfo = moleculesInfo else { return } let indicies = moleculesInfo.indices.filter({ index -> Bool in @@ -234,11 +227,14 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol } ///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 + //TODO: expand for navigation, etc + private func updateMoleculeViewByModelId(molecule: MoleculeModelProtocol) -> Bool { + let headerFooterViews = [topView, bottomView].compactMap({$0 as? MoleculeViewProtocol}) + for headerFooterView in headerFooterViews { + if let moleculeView = MVMCoreUIUtility.findViews(by: MoleculeViewProtocol.self, views: [headerFooterView]).first(where: { $0.model?.moleculeName == molecule.moleculeName && $0.model?.id == molecule.id }) { + updateMoleculeView(moleculeView, from: molecule) + return true + } } return false } From 46a3af5e6b6723221b3cfb3c307e2b3a749dd686 Mon Sep 17 00:00:00 2001 From: vimal Date: Mon, 8 Jan 2024 09:30:09 +0530 Subject: [PATCH 2/2] review comment updated --- .../Templates/MoleculeListTemplate.swift | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift index a0f6743c..61669200 100644 --- a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift @@ -203,7 +203,9 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol open func newData(for molecule: MoleculeModelProtocol) { - if updateMoleculeViewByModelId(molecule: molecule) { + //Check header and footer if replace happens then return. + if updateMoleculeViewById(topView, with: molecule) || + updateMoleculeViewById(bottomView, with: molecule) { return } @@ -226,15 +228,12 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol } } - ///Helper functions to update the header/footer view - //TODO: expand for navigation, etc - private func updateMoleculeViewByModelId(molecule: MoleculeModelProtocol) -> Bool { - let headerFooterViews = [topView, bottomView].compactMap({$0 as? MoleculeViewProtocol}) - for headerFooterView in headerFooterViews { - if let moleculeView = MVMCoreUIUtility.findViews(by: MoleculeViewProtocol.self, views: [headerFooterView]).first(where: { $0.model?.moleculeName == molecule.moleculeName && $0.model?.id == molecule.id }) { - updateMoleculeView(moleculeView, from: molecule) - return true - } + ///Helper functions to update view with molecule + private func updateMoleculeViewById(_ view: UIView?, with molecule: MoleculeModelProtocol) -> Bool { + if let updateView = view, + 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 }