Button json to have style and size.

Separator alone in stack fix.
remove view constraining view auto background color
fix padding for stack in stack
This commit is contained in:
Pfeil, Scott Robert 2019-06-21 12:52:30 -04:00
parent dc62e16c07
commit ed87bd2cfc
9 changed files with 62 additions and 25 deletions

View File

@ -669,6 +669,13 @@
[FormValidator setupValidationWithMolecule:self delegate:delegateObject.formValidationProtocol]; [FormValidator setupValidationWithMolecule:self delegate:delegateObject.formValidationProtocol];
self.primaryButtonType = PrimaryButtonTypeCustom; 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"]; NSString *color = [json string:@"fillColor"];
if (color) { if (color) {
self.fillColor = [UIColor mfGetColorForHex:color]; self.fillColor = [UIColor mfGetColorForHex:color];
@ -691,7 +698,14 @@
} }
self.validationRequired = [json boolForKey:@"validationRequired"]; 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]; [self setWithActionMap:json delegateObject:delegateObject additionalData:additionalData];
} }

View File

@ -8,6 +8,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <MVMCoreUI/MFView.h> #import <MVMCoreUI/MFView.h>
#import <MVMCoreUI/MVMCoreUIViewConstrainingProtocol.h>
@class MFSizeObject; @class MFSizeObject;
typedef enum : NSUInteger { typedef enum : NSUInteger {
@ -15,7 +16,7 @@ typedef enum : NSUInteger {
SeparatorPositionBot SeparatorPositionBot
} SeparatorPosition; } SeparatorPosition;
@interface SeparatorView : MFView @interface SeparatorView : MFView <MVMCoreUIViewConstrainingProtocol>
@property (nullable, weak, nonatomic) NSLayoutConstraint *height; @property (nullable, weak, nonatomic) NSLayoutConstraint *height;
@property (nullable, weak, nonatomic) NSLayoutConstraint *leftPin; @property (nullable, weak, nonatomic) NSLayoutConstraint *leftPin;

View File

@ -165,5 +165,11 @@
[self setNeedsLayout]; [self setNeedsLayout];
[self layoutIfNeeded]; [self layoutIfNeeded];
} }
#pragma mark - Molecule
- (BOOL)needsToBeConstrained {
return YES;
}
@end @end

View File

@ -267,6 +267,9 @@
- (void)shouldSetHorizontalMargins:(BOOL)shouldSet { - (void)shouldSetHorizontalMargins:(BOOL)shouldSet {
self.updateViewHorizontalDefaults = shouldSet; self.updateViewHorizontalDefaults = shouldSet;
} }
- (void)shouldSetVerticalMargins:(BOOL)shouldSet {
}
#pragma mark - MVMCoreViewProtocol #pragma mark - MVMCoreViewProtocol
@ -307,7 +310,6 @@
[super setWithJSON:json delegateObject:delegateObject additionalData:additionalData]; [super setWithJSON:json delegateObject:delegateObject additionalData:additionalData];
if (self.molecule) { if (self.molecule) {
[self.molecule setWithJSON:json delegateObject:delegateObject additionalData:additionalData]; [self.molecule setWithJSON:json delegateObject:delegateObject additionalData:additionalData];
self.backgroundColor = self.molecule.backgroundColor;
} }
} }

View File

@ -39,11 +39,14 @@ public class StackItem {
public class MoleculeStackView: ViewConstrainingView { public class MoleculeStackView: ViewConstrainingView {
var contentView: UIView = MVMCoreUICommonViewsUtility.commonView() var contentView: UIView = MVMCoreUICommonViewsUtility.commonView()
var items: [StackItem] = [] var items: [StackItem] = []
var useStackSpacingBeforeFirstItem = false
private var moleculesShouldSetHorizontalMargins = true
private var moleculesShouldSetVerticalMargins = false
/// For setting the direction of the stack /// For setting the direction of the stack
var axis: NSLayoutConstraint.Axis = .vertical { var axis: NSLayoutConstraint.Axis = .vertical {
didSet { didSet {
updateViewHorizontalDefaults = axis == .horizontal
if axis != oldValue { if axis != oldValue {
restack() 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]?) { open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
let previousJSON = self.json let previousJSON = self.json
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
@ -171,7 +185,6 @@ public class MoleculeStackView: ViewConstrainingView {
if let moleculeJSON = map.optionalDictionaryForKey(KeyMolecule) { if let moleculeJSON = map.optionalDictionaryForKey(KeyMolecule) {
var view: UIView? var view: UIView?
if let item = items?[index] { if let item = items?[index] {
(item.view as? MVMCoreUIMoleculeViewProtocol)?.setWithJSON(moleculeJSON, delegateObject: delegateObject, additionalData: additionalData)
item.update(with: moleculeJSON) item.update(with: moleculeJSON)
view = item.view view = item.view
addStackItem(item, lastItem: index == molecules.count - 1) addStackItem(item, lastItem: index == molecules.count - 1)
@ -179,9 +192,9 @@ public class MoleculeStackView: ViewConstrainingView {
view = molecule view = molecule
addStackItem(StackItem(with: molecule, json: map), lastItem: index == molecules.count - 1) addStackItem(StackItem(with: molecule, json: map), lastItem: index == molecules.count - 1)
} }
(view as? MVMCoreUIViewConstrainingProtocol)?.shouldSetHorizontalMargins?(moleculesShouldSetHorizontalMargins && axis == .vertical)
(view as? MVMCoreUIViewConstrainingProtocol)?.shouldSetHorizontalMargins?(axis == .vertical) (view as? MVMCoreUIViewConstrainingProtocol)?.shouldSetVerticalMargins?(moleculesShouldSetVerticalMargins)
(view as? MVMCoreUIViewConstrainingProtocol)?.shouldSetVerticalMargins?(false) (view as? MVMCoreUIMoleculeViewProtocol)?.setWithJSON(moleculeJSON, delegateObject: delegateObject, additionalData: nil)
} }
} }
} }
@ -221,7 +234,7 @@ public class MoleculeStackView: ViewConstrainingView {
} }
if axis == .vertical { if axis == .vertical {
if items.count == 0 { 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 { } else if let previousView = items.last?.view {
_ = NSLayoutConstraint(pinFirstView: previousView, toSecondView: view, withConstant: spacing, directionVertical: true) _ = NSLayoutConstraint(pinFirstView: previousView, toSecondView: view, withConstant: spacing, directionVertical: true)
} }
@ -236,7 +249,7 @@ public class MoleculeStackView: ViewConstrainingView {
} else { } else {
if items.count == 0 { if items.count == 0 {
// First horizontal item has no spacing by default unless told otherwise. // 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 { } else if let previousView = items.last?.view {
_ = NSLayoutConstraint(pinFirstView: previousView, toSecondView: view, withConstant: spacing, directionVertical: false) _ = NSLayoutConstraint(pinFirstView: previousView, toSecondView: view, withConstant: spacing, directionVertical: false)
} }

View File

@ -89,12 +89,7 @@ import UIKit
if molecule == nil { if molecule == nil {
if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: true) { if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: true) {
contentView.addSubview(moleculeView) contentView.addSubview(moleculeView)
var standardConstraints = true let standardConstraints = (moleculeView as? MVMCoreUIViewConstrainingProtocol)?.useStandardConstraints?() ?? true
if let castView = moleculeView as? MVMCoreUIViewConstrainingProtocol {
standardConstraints = castView.useStandardConstraints?() ?? true
castView.shouldSetHorizontalMargins?(!standardConstraints)
castView.shouldSetVerticalMargins?(!standardConstraints)
}
NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: standardConstraints).values)) NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: standardConstraints).values))
if standardConstraints { if standardConstraints {
let constraint = contentView.heightAnchor.constraint(equalToConstant: 80) let constraint = contentView.heightAnchor.constraint(equalToConstant: 80)
@ -103,14 +98,14 @@ import UIKit
} }
molecule = moleculeView 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 backgroundColor = molecule?.backgroundColor
// Add the caret if there is an action and it's not declared hidden. // Add the caret if there is an action and it's not declared hidden.

View File

@ -94,7 +94,6 @@
if (constrainIfNeeded && [castMolecule respondsToSelector:@selector(needsToBeConstrained)] && [castMolecule needsToBeConstrained]) { if (constrainIfNeeded && [castMolecule respondsToSelector:@selector(needsToBeConstrained)] && [castMolecule needsToBeConstrained]) {
molecule = [[ViewConstrainingView alloc] initWithMolecule:molecule alignment:[castMolecule respondsToSelector:@selector(alignment)] ? [castMolecule alignment] : UIStackViewAlignmentFill]; molecule = [[ViewConstrainingView alloc] initWithMolecule:molecule alignment:[castMolecule respondsToSelector:@selector(alignment)] ? [castMolecule alignment] : UIStackViewAlignmentFill];
} }
[molecule setWithJSON:moleculeJSON delegateObject:delegateObject additionalData:nil];
return molecule; return molecule;
} }

View File

@ -30,6 +30,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController {
let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else {
return super.viewForTop() return super.viewForTop()
} }
molecule.setWithJSON(moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, additionalData: nil)
return molecule return molecule
} }
@ -38,6 +39,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController {
let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else {
return super.viewForBottom() return super.viewForBottom()
} }
molecule.setWithJSON(moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, additionalData: nil)
return molecule return molecule
} }

View File

@ -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 { guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("header"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else {
return nil return nil
} }
molecule.setWithJSON(moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, additionalData: nil)
return molecule return molecule
} }
@ -35,13 +36,17 @@ public class MoleculeStackTemplate: ThreeLayerViewController {
guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("moleculeStack") else { guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("moleculeStack") else {
return nil 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? { 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 { guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("footer"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else {
return nil return nil
} }
molecule.setWithJSON(moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, additionalData: nil)
return molecule return molecule
} }