diff --git a/MVMCoreUI/Atoms/Buttons/PrimaryButton.m b/MVMCoreUI/Atoms/Buttons/PrimaryButton.m index 74a1e41a..57470bf9 100644 --- a/MVMCoreUI/Atoms/Buttons/PrimaryButton.m +++ b/MVMCoreUI/Atoms/Buttons/PrimaryButton.m @@ -669,6 +669,13 @@ [FormValidator setupValidationWithMolecule:self delegate:delegateObject.formValidationProtocol]; self.primaryButtonType = PrimaryButtonTypeCustom; + NSString *style = [json string:@"style"]; + if ([style isEqualToString:@"primary"]) { + [self setAsStandardCustom]; + } else if ([style isEqualToString:@"secondary"]) { + [self setAsSecondaryCustom]; + } + NSString *color = [json string:@"fillColor"]; if (color) { self.fillColor = [UIColor mfGetColorForHex:color]; @@ -691,7 +698,14 @@ } self.validationRequired = [json boolForKey:@"validationRequired"]; - [self setAsSmallButton:[json boolForKey:@"small"]]; + NSString *size = [json string:@"size"]; + if ([size isEqualToString:@"small"]) { + [self setAsSmallButton:YES]; + } else if ([size isEqualToString:@"tiny"]) { + [self setAsTiny:YES]; + } else { + [self setAsSmallButton:NO]; + } [self setWithActionMap:json delegateObject:delegateObject additionalData:additionalData]; } diff --git a/MVMCoreUI/Atoms/Views/SeparatorView.h b/MVMCoreUI/Atoms/Views/SeparatorView.h index 78fe65e8..89a9197d 100644 --- a/MVMCoreUI/Atoms/Views/SeparatorView.h +++ b/MVMCoreUI/Atoms/Views/SeparatorView.h @@ -8,6 +8,7 @@ #import #import +#import @class MFSizeObject; typedef enum : NSUInteger { @@ -15,7 +16,7 @@ typedef enum : NSUInteger { SeparatorPositionBot } SeparatorPosition; -@interface SeparatorView : MFView +@interface SeparatorView : MFView @property (nullable, weak, nonatomic) NSLayoutConstraint *height; @property (nullable, weak, nonatomic) NSLayoutConstraint *leftPin; diff --git a/MVMCoreUI/Atoms/Views/SeparatorView.m b/MVMCoreUI/Atoms/Views/SeparatorView.m index 2734bc94..44e95d3c 100644 --- a/MVMCoreUI/Atoms/Views/SeparatorView.m +++ b/MVMCoreUI/Atoms/Views/SeparatorView.m @@ -165,5 +165,11 @@ [self setNeedsLayout]; [self layoutIfNeeded]; } + +#pragma mark - Molecule + +- (BOOL)needsToBeConstrained { + return YES; +} @end diff --git a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m index a7412b93..44445a3e 100644 --- a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m +++ b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m @@ -267,6 +267,9 @@ - (void)shouldSetHorizontalMargins:(BOOL)shouldSet { self.updateViewHorizontalDefaults = shouldSet; } + +- (void)shouldSetVerticalMargins:(BOOL)shouldSet { +} #pragma mark - MVMCoreViewProtocol @@ -307,7 +310,6 @@ [super setWithJSON:json delegateObject:delegateObject additionalData:additionalData]; if (self.molecule) { [self.molecule setWithJSON:json delegateObject:delegateObject additionalData:additionalData]; - self.backgroundColor = self.molecule.backgroundColor; } } diff --git a/MVMCoreUI/Molecules/MoleculeStackView.swift b/MVMCoreUI/Molecules/MoleculeStackView.swift index d2a70402..8c6e76bf 100644 --- a/MVMCoreUI/Molecules/MoleculeStackView.swift +++ b/MVMCoreUI/Molecules/MoleculeStackView.swift @@ -39,11 +39,14 @@ public class StackItem { public class MoleculeStackView: ViewConstrainingView { var contentView: UIView = MVMCoreUICommonViewsUtility.commonView() var items: [StackItem] = [] + var useStackSpacingBeforeFirstItem = false + private var moleculesShouldSetHorizontalMargins = true + private var moleculesShouldSetVerticalMargins = false + /// For setting the direction of the stack var axis: NSLayoutConstraint.Axis = .vertical { didSet { - updateViewHorizontalDefaults = axis == .horizontal if axis != oldValue { restack() } @@ -133,6 +136,17 @@ public class MoleculeStackView: ViewConstrainingView { } } + // If this item is in another container, do have the child molecules not use alignment. + public override func shouldSetHorizontalMargins(_ shouldSet: Bool) { + super.shouldSetHorizontalMargins(shouldSet) + moleculesShouldSetHorizontalMargins = false + } + + public override func shouldSetVerticalMargins(_ shouldSet: Bool) { + super.shouldSetVerticalMargins(shouldSet) + moleculesShouldSetVerticalMargins = false + } + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { let previousJSON = self.json super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) @@ -171,7 +185,6 @@ public class MoleculeStackView: ViewConstrainingView { if let moleculeJSON = map.optionalDictionaryForKey(KeyMolecule) { var view: UIView? if let item = items?[index] { - (item.view as? MVMCoreUIMoleculeViewProtocol)?.setWithJSON(moleculeJSON, delegateObject: delegateObject, additionalData: additionalData) item.update(with: moleculeJSON) view = item.view addStackItem(item, lastItem: index == molecules.count - 1) @@ -179,9 +192,9 @@ public class MoleculeStackView: ViewConstrainingView { view = molecule addStackItem(StackItem(with: molecule, json: map), lastItem: index == molecules.count - 1) } - - (view as? MVMCoreUIViewConstrainingProtocol)?.shouldSetHorizontalMargins?(axis == .vertical) - (view as? MVMCoreUIViewConstrainingProtocol)?.shouldSetVerticalMargins?(false) + (view as? MVMCoreUIViewConstrainingProtocol)?.shouldSetHorizontalMargins?(moleculesShouldSetHorizontalMargins && axis == .vertical) + (view as? MVMCoreUIViewConstrainingProtocol)?.shouldSetVerticalMargins?(moleculesShouldSetVerticalMargins) + (view as? MVMCoreUIMoleculeViewProtocol)?.setWithJSON(moleculeJSON, delegateObject: delegateObject, additionalData: nil) } } } @@ -221,7 +234,7 @@ public class MoleculeStackView: ViewConstrainingView { } if axis == .vertical { if items.count == 0 { - pinView(view, toView: contentView, attribute: .top, relation: .equal, priority: .required, constant: spacing) + pinView(view, toView: contentView, attribute: .top, relation: .equal, priority: .required, constant: useStackSpacingBeforeFirstItem ? spacing : stackItem.spacing ?? 0) } else if let previousView = items.last?.view { _ = NSLayoutConstraint(pinFirstView: previousView, toSecondView: view, withConstant: spacing, directionVertical: true) } @@ -236,7 +249,7 @@ public class MoleculeStackView: ViewConstrainingView { } else { if items.count == 0 { // First horizontal item has no spacing by default unless told otherwise. - pinView(view, toView: contentView, attribute: .leading, relation: .equal, priority: .required, constant: stackItem.spacing ?? 0) + pinView(view, toView: contentView, attribute: .leading, relation: .equal, priority: .required, constant: useStackSpacingBeforeFirstItem ? spacing : stackItem.spacing ?? 0) } else if let previousView = items.last?.view { _ = NSLayoutConstraint(pinFirstView: previousView, toSecondView: view, withConstant: spacing, directionVertical: false) } diff --git a/MVMCoreUI/Molecules/MoleculeTableViewCell.swift b/MVMCoreUI/Molecules/MoleculeTableViewCell.swift index be6f1a71..ed5bf1fc 100644 --- a/MVMCoreUI/Molecules/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/MoleculeTableViewCell.swift @@ -89,12 +89,7 @@ import UIKit if molecule == nil { if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: true) { contentView.addSubview(moleculeView) - var standardConstraints = true - if let castView = moleculeView as? MVMCoreUIViewConstrainingProtocol { - standardConstraints = castView.useStandardConstraints?() ?? true - castView.shouldSetHorizontalMargins?(!standardConstraints) - castView.shouldSetVerticalMargins?(!standardConstraints) - } + let standardConstraints = (moleculeView as? MVMCoreUIViewConstrainingProtocol)?.useStandardConstraints?() ?? true NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: standardConstraints).values)) if standardConstraints { let constraint = contentView.heightAnchor.constraint(equalToConstant: 80) @@ -103,14 +98,14 @@ import UIKit } molecule = moleculeView } - } else { - molecule?.setWithJSON(moleculeJSON, delegateObject: delegateObject, additionalData: additionalData) - if let castView = molecule as? MVMCoreUIViewConstrainingProtocol { - let standardConstraints = castView.useStandardConstraints?() ?? true - castView.shouldSetHorizontalMargins?(!standardConstraints) - castView.shouldSetVerticalMargins?(!standardConstraints) - } } + if let castView = molecule as? MVMCoreUIViewConstrainingProtocol { + let standardConstraints = castView.useStandardConstraints?() ?? true + castView.shouldSetHorizontalMargins?(!standardConstraints) + castView.shouldSetVerticalMargins?(!standardConstraints) + } + molecule?.setWithJSON(moleculeJSON, delegateObject: delegateObject, additionalData: additionalData) + backgroundColor = molecule?.backgroundColor // Add the caret if there is an action and it's not declared hidden. diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index 07d3e548..7ffc2959 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -94,7 +94,6 @@ if (constrainIfNeeded && [castMolecule respondsToSelector:@selector(needsToBeConstrained)] && [castMolecule needsToBeConstrained]) { molecule = [[ViewConstrainingView alloc] initWithMolecule:molecule alignment:[castMolecule respondsToSelector:@selector(alignment)] ? [castMolecule alignment] : UIStackViewAlignmentFill]; } - [molecule setWithJSON:moleculeJSON delegateObject:delegateObject additionalData:nil]; return molecule; } diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index ea3f94b4..9a3fd952 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -30,6 +30,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { return super.viewForTop() } + molecule.setWithJSON(moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, additionalData: nil) return molecule } @@ -38,6 +39,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { return super.viewForBottom() } + molecule.setWithJSON(moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, additionalData: nil) return molecule } diff --git a/MVMCoreUI/Templates/MoleculeStackTemplate.swift b/MVMCoreUI/Templates/MoleculeStackTemplate.swift index 3f5e04da..3d6d76d8 100644 --- a/MVMCoreUI/Templates/MoleculeStackTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeStackTemplate.swift @@ -28,6 +28,7 @@ public class MoleculeStackTemplate: ThreeLayerViewController { guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("header"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { return nil } + molecule.setWithJSON(moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, additionalData: nil) return molecule } @@ -35,13 +36,17 @@ public class MoleculeStackTemplate: ThreeLayerViewController { guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("moleculeStack") else { return nil } - return MoleculeStackView(withJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, additionalData: nil) + let stack = MoleculeStackView(frame: .zero) + stack.useStackSpacingBeforeFirstItem = true + stack.setWithJSON(moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, additionalData: nil) + return stack } override public func viewForBottom() -> UIView? { guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("footer"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { return nil } + molecule.setWithJSON(moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, additionalData: nil) return molecule }