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:
parent
dc62e16c07
commit
ed87bd2cfc
@ -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];
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <MVMCoreUI/MFView.h>
|
||||
#import <MVMCoreUI/MVMCoreUIViewConstrainingProtocol.h>
|
||||
@class MFSizeObject;
|
||||
|
||||
typedef enum : NSUInteger {
|
||||
@ -15,7 +16,7 @@ typedef enum : NSUInteger {
|
||||
SeparatorPositionBot
|
||||
} SeparatorPosition;
|
||||
|
||||
@interface SeparatorView : MFView
|
||||
@interface SeparatorView : MFView <MVMCoreUIViewConstrainingProtocol>
|
||||
|
||||
@property (nullable, weak, nonatomic) NSLayoutConstraint *height;
|
||||
@property (nullable, weak, nonatomic) NSLayoutConstraint *leftPin;
|
||||
|
||||
@ -165,5 +165,11 @@
|
||||
[self setNeedsLayout];
|
||||
[self layoutIfNeeded];
|
||||
}
|
||||
|
||||
#pragma mark - Molecule
|
||||
|
||||
- (BOOL)needsToBeConstrained {
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user