diff --git a/MVMCoreUI/Atoms/Views/Toggle.swift b/MVMCoreUI/Atoms/Views/Toggle.swift index 899c1edb..73a8ec2f 100644 --- a/MVMCoreUI/Atoms/Views/Toggle.swift +++ b/MVMCoreUI/Atoms/Views/Toggle.swift @@ -333,6 +333,7 @@ public typealias ActionBlockConfirmation = () -> (Bool) } } + // MARK:- ModelMoleculeViewProtocol public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { guard let toggleModel = model as? ToggleModel else { return @@ -341,6 +342,10 @@ public typealias ActionBlockConfirmation = () -> (Bool) let toggleModelJSON = toggleModel.toJSON() setWithJSON(toggleModelJSON, delegateObject: delegateObject, additionalData: additionalData) } + + public override class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + return Self.getContainerHeight() + } } // MARK: - Accessibility diff --git a/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift b/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift index 09432dce..597f1059 100644 --- a/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift +++ b/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/HeadlineBodySwitch.swift @@ -34,9 +34,7 @@ import UIKit NSLayoutConstraint.pinSubviewsCenter(leftView: headlineBody, rightView: toggle) } - - //MARK: - MVMCoreMoleculeViewProtocol - + // MARK:- ModelMoleculeViewProtocol open override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData) guard let headlineBodyToggleModel = model as? HeadlineBodyToggleModel else { @@ -46,31 +44,17 @@ import UIKit } public class override func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { - return 30 + guard let model = molecule as? HeadlineBodyToggleModel, + let toggleHeight = Toggle.estimatedHeight(forRow: model.toggle, delegateObject: delegateObject), + let headlineBody = HeadlineBody.estimatedHeight(forRow: model.headlineBody, delegateObject: delegateObject) else { return nil } + return max(toggleHeight, headlineBody) } - // MARK: - MVMCoreUIMoleculeViewProtocol - open override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - headlineBody.setWithJSON(json?.optionalDictionaryForKey("headlineBody"), delegateObject: delegateObject, additionalData: additionalData) - toggle.setWithJSON(json?.optionalDictionaryForKey("toggle"), delegateObject: delegateObject, additionalData: additionalData) - } - - open class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { - return 30 - } - - open override func setAsMolecule() { - headlineBody.setAsMolecule() - (toggle as MVMCoreUIMoleculeViewProtocol).setAsMolecule?() - headlineBody.styleListItem() - } - open override func reset() { super.reset() headlineBody.reset() - (toggle as MVMCoreUIMoleculeViewProtocol).reset?() + toggle.reset() headlineBody.styleListItem() } } diff --git a/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/LabelSwitch.swift b/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/LabelSwitch.swift index 0e87e7c7..dcb8dd58 100644 --- a/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/LabelSwitch.swift +++ b/MVMCoreUI/Molecules/LeftRightViews/SwitchMolecules/LabelSwitch.swift @@ -8,7 +8,7 @@ import UIKit -@objcMembers public class LabelSwitch: ViewConstrainingView, ModelMoleculeViewProtocol { +@objcMembers public class LabelSwitch: View { let label = Label.commonLabelB1(true) let mvmSwitch = Toggle() @@ -24,24 +24,22 @@ import UIKit guard mvmSwitch.superview == nil else { return } - let view = MVMCoreUICommonViewsUtility.commonView() - addSubview(view) - pinView(toSuperView: view) - view.addSubview(label) - view.addSubview(mvmSwitch) + addSubview(label) + addSubview(mvmSwitch) label.setContentHuggingPriority(UILayoutPriority.required, for: NSLayoutConstraint.Axis.vertical) NSLayoutConstraint.pinSubviewsCenter(leftView: label, rightView: mvmSwitch) } - // MARK: - MVMCoreUIMoleculeViewProtocol - public override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { - super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - label.setWithJSON(json?.optionalDictionaryForKey("label"), delegateObject: delegateObject, additionalData: additionalData) - mvmSwitch.setWithJSON(json?.optionalDictionaryForKey("toggle"), delegateObject: delegateObject, additionalData: additionalData) + // MARK:- ModelMoleculeViewProtocol + public override class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + guard let model = molecule as? LabelToggleModel, + let toggleHeight = Toggle.estimatedHeight(forRow: model.toggle, delegateObject: delegateObject), + let labelHeight = Label.estimatedHeight(forRow: model.label, delegateObject: delegateObject) else { return nil } + return max(toggleHeight, labelHeight) } - - public func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + + public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { guard let labelToggleModel = model as? LabelToggleModel else { return } @@ -49,17 +47,7 @@ import UIKit mvmSwitch.setWithModel(labelToggleModel.toggle, delegateObject, additionalData) } - public override class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { - return MVMCoreUISwitch.estimatedHeight(forRow: json, delegateObject: delegateObject) - } - - public override func setAsMolecule() { - super.setAsMolecule() - label.setAsMolecule() - (mvmSwitch as MVMCoreUIMoleculeViewProtocol).setAsMolecule?() - label.styleB1(true) - } - + // MARK: - MVMCoreUIMoleculeViewProtocol public override func reset() { super.reset() label.reset() diff --git a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift index 8cdb5633..3a270ad5 100644 --- a/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift +++ b/MVMCoreUI/Molecules/VerticalCombinationViews/HeadlineBody.swift @@ -119,6 +119,11 @@ open class HeadlineBody: View { } } + // MARK:- ModelMoleculeViewProtocol + public override class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { + return 58 + } + public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.setWithModel(model, delegateObject, additionalData)