fix for button model

review comment updated
This commit is contained in:
vimal 2024-01-03 23:25:48 +05:30
parent b6623b34c6
commit db7e59191a
2 changed files with 26 additions and 11 deletions

View File

@ -8,7 +8,7 @@
import Foundation import Foundation
open class ImageButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWatcherFieldProtocol { open class ImageButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWatcherFieldProtocol, ParentMoleculeModelProtocol {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Properties // MARK: - Properties
//-------------------------------------------------- //--------------------------------------------------
@ -29,6 +29,14 @@ open class ImageButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGro
public var updateUI: ActionBlock? 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) { public init(image: ImageViewModel?, action: ActionModelProtocol) {
self.image = image self.image = image
self.action = action self.action = action

View File

@ -203,16 +203,13 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
open func newData(for molecule: MoleculeModelProtocol) { open func newData(for molecule: MoleculeModelProtocol) {
if let headerMolecule = molecule as? MoleculeHeaderModel { //Update the header
//If complete header replaced then it makes sense to add this if updateHeaderFooter(modelView: topView, molecule: molecule) {
/*createViewForTableHeader() return
let width = view.bounds.width }
if let topView = topView as? MVMCoreViewProtocol {
topView.updateView(width) //Update the footer
showHeader(width) if updateHeaderFooter(modelView: bottomView, molecule: molecule) {
}*/
//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 return
} }
@ -236,6 +233,16 @@ 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
}
return false
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Convenience // MARK: - Convenience
//-------------------------------------------------- //--------------------------------------------------