diff --git a/MVMCoreUI/Atoms/Buttons/CaretButton.swift b/MVMCoreUI/Atoms/Buttons/CaretButton.swift index 46c6d3f4..4ca750c6 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretButton.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretButton.swift @@ -139,4 +139,8 @@ open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUI open func alignment() -> UIStackView.Alignment { return UIStackView.Alignment.leading; } + + public static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + return 10 + } } diff --git a/MVMCoreUI/Atoms/Buttons/MFTextButton.m b/MVMCoreUI/Atoms/Buttons/MFTextButton.m index 336db92a..e1a6c504 100644 --- a/MVMCoreUI/Atoms/Buttons/MFTextButton.m +++ b/MVMCoreUI/Atoms/Buttons/MFTextButton.m @@ -146,6 +146,10 @@ } } ++ (CGFloat)estimatedHeightForRow:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject { + return 31; +} + #pragma mark - MVMCoreUIViewConstrainingProtocol - (BOOL)needsToBeConstrained { diff --git a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift index 795dea86..703ffd65 100644 --- a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift +++ b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift @@ -184,6 +184,10 @@ import UIKit addSizeConstraintsForAspectRatio = true } + public override static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + return json?.optionalCGFloatForKey("height") ?? 0 + } + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) if let accessibilityString = json?.optionalStringForKey("accessibilityText") { diff --git a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m index 9db9285b..2cde1bc3 100644 --- a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m +++ b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m @@ -78,6 +78,9 @@ static const CGFloat CheckBoxHeightWidth = 18.0; additionalData: additionalData]; } ++ (CGFloat)estimatedHeightForRow:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject { + return CheckBoxHeightWidth; +} #pragma mark - convenient class methods diff --git a/MVMCoreUI/Atoms/Views/MVMCoreUISwitch.h b/MVMCoreUI/Atoms/Views/MVMCoreUISwitch.h index 8c42f5e5..5591f595 100644 --- a/MVMCoreUI/Atoms/Views/MVMCoreUISwitch.h +++ b/MVMCoreUI/Atoms/Views/MVMCoreUISwitch.h @@ -31,4 +31,6 @@ typedef void(^ValueChangeBlock)(void); // Sets the state without triggering the value changed block. - (void)setState:(BOOL)stateWithoutBlock withoutBlockAnimated:(BOOL)animated; ++ (CGFloat)getSwitchHeight; + @end diff --git a/MVMCoreUI/Atoms/Views/SeparatorView.m b/MVMCoreUI/Atoms/Views/SeparatorView.m index a92c252b..2d01e6d2 100644 --- a/MVMCoreUI/Atoms/Views/SeparatorView.m +++ b/MVMCoreUI/Atoms/Views/SeparatorView.m @@ -70,10 +70,6 @@ #pragma mark - set up -- (void)reset { - [self setAsLight]; -} - - (void)updateView:(CGFloat)size { [super updateView:size]; self.height.constant = [self.heightSizeObject getValueBasedOnSize:size]; @@ -163,6 +159,10 @@ } #pragma mark - Molecule + +- (void)reset { + [self setAsLight]; +} - (BOOL)needsToBeConstrained { return YES; @@ -172,4 +172,19 @@ return NO; } ++ (CGFloat)estimatedHeightForRow:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject { + NSString *type = [json string:KeyType]; + if ([type isEqualToString:@"none"]) { + return 0; + } else { + if ([type isEqualToString:@"medium"]) { + return 2; + } else if ([type isEqualToString:@"heavy"]) { + return 4; + } else { + return 1; + } + } +} + @end diff --git a/MVMCoreUI/Molecules/ModuleMolecule.swift b/MVMCoreUI/Molecules/ModuleMolecule.swift index f160acda..3478c9ab 100644 --- a/MVMCoreUI/Molecules/ModuleMolecule.swift +++ b/MVMCoreUI/Molecules/ModuleMolecule.swift @@ -53,7 +53,7 @@ open class ModuleMolecule: ViewConstrainingView { // Critical error return 0 } - return MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: module)?.estimatedHeight?(forRow: module, delegateObject: delegateObject) ?? 80 + return MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: module)?.estimatedHeight?(forRow: module, delegateObject: delegateObject) ?? 0 } public override static func name(forReuse molecule: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { diff --git a/MVMCoreUI/Molecules/MoleculeStackView.swift b/MVMCoreUI/Molecules/MoleculeStackView.swift index 869dda5d..3183800f 100644 --- a/MVMCoreUI/Molecules/MoleculeStackView.swift +++ b/MVMCoreUI/Molecules/MoleculeStackView.swift @@ -218,8 +218,25 @@ public class MoleculeStackView: ViewConstrainingView { } public override static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { - // if horizontal, max, if vertical, append. - return 100 + guard let items = json?.optionalArrayForKey(KeyMolecules) else { + return 0 + } + let horizontal = json?.optionalStringForKey("axis") == "horizontal" + var estimatedHeight: CGFloat = 0 + for case let item as [AnyHashable: AnyHashable] in items { + if let molecule = item.optionalDictionaryForKey(KeyMolecule) { + let height = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: molecule)?.estimatedHeight?(forRow: molecule, delegateObject: delegateObject) + if !horizontal { + // Vertical stack aggregates the items + let spacing = item.optionalCGFloatForKey("spacing") ?? (estimatedHeight != 0 ? (json?.optionalCGFloatForKey("spacing") ?? 16) : 0) + estimatedHeight += ((height ?? 0) + spacing) + } else if let height = height { + // Horizontal stack takes the tallest item. + estimatedHeight = max(estimatedHeight, height) + } + } + } + return estimatedHeight } public override static func requiredModules(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer?) -> [String]? { diff --git a/MVMCoreUI/Molecules/MoleculeTableViewCell.swift b/MVMCoreUI/Molecules/MoleculeTableViewCell.swift index f8fc00fa..fc681c12 100644 --- a/MVMCoreUI/Molecules/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/MoleculeTableViewCell.swift @@ -131,7 +131,7 @@ import UIKit guard let moleculeJSON = json?.optionalDictionaryForKey(KeyMolecule), let height = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(withJSON: moleculeJSON)?.estimatedHeight?(forRow: moleculeJSON, delegateObject: delegateObject) else { return 80 } - return height + return max(80, height) } public static func name(forReuse molecule: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { diff --git a/MVMCoreUI/Molecules/StandardFooterView.swift b/MVMCoreUI/Molecules/StandardFooterView.swift index b99ad5d0..21c70a7f 100644 --- a/MVMCoreUI/Molecules/StandardFooterView.swift +++ b/MVMCoreUI/Molecules/StandardFooterView.swift @@ -103,4 +103,8 @@ public class StandardFooterView: ViewConstrainingView { twoButtonView.reset() textButton.reset() } + + public override static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + return 42 + } } diff --git a/MVMCoreUI/Molecules/StandardHeaderView.swift b/MVMCoreUI/Molecules/StandardHeaderView.swift index b9639f07..2440656f 100644 --- a/MVMCoreUI/Molecules/StandardHeaderView.swift +++ b/MVMCoreUI/Molecules/StandardHeaderView.swift @@ -111,14 +111,6 @@ public class StandardHeaderView: ViewConstrainingView { separatorView?.rightPin?.constant = constant } - open override func reset() { - backgroundColor = .clear - headlineLabel.styleH2(true) - messageLabel.styleB2(true) - separatorView?.setAsHeavy() - separatorView?.show() - } - // MARK: - MVMCoreUIMoleculeViewProtocol open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) @@ -143,4 +135,16 @@ public class StandardHeaderView: ViewConstrainingView { bottomPin?.constant = PaddingDefaultVerticalSpacing } } + + open override func reset() { + backgroundColor = .clear + headlineLabel.styleH2(true) + messageLabel.styleB2(true) + separatorView?.setAsHeavy() + separatorView?.show() + } + + public override static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + return 121 + } } diff --git a/MVMCoreUI/Molecules/Switch.swift b/MVMCoreUI/Molecules/Switch.swift index a8bb00ba..5b23b1d5 100644 --- a/MVMCoreUI/Molecules/Switch.swift +++ b/MVMCoreUI/Molecules/Switch.swift @@ -83,5 +83,9 @@ import UIKit public override func alignment() -> UIStackView.Alignment { return UIStackView.Alignment.leading } + + public override static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + return MVMCoreUISwitch.getHeight() + } }