From 01803e90d628d6cf8e17101ffcf5fa360383779f Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 26 Jun 2019 12:58:43 -0400 Subject: [PATCH] background color consolidation --- MVMCoreUI/Atoms/Views/CaretView.swift | 4 ---- MVMCoreUI/Atoms/Views/DashLine.swift | 4 ---- MVMCoreUI/Atoms/Views/LeftRightLabelView.swift | 4 ---- MVMCoreUI/Atoms/Views/MFLoadImageView.swift | 3 --- MVMCoreUI/Atoms/Views/MFView.m | 8 ++++++++ MVMCoreUI/Atoms/Views/SeparatorView.m | 5 +---- MVMCoreUI/Atoms/Views/ViewConstrainingView.m | 3 +++ MVMCoreUI/Molecules/MoleculeStackView.swift | 7 ++----- MVMCoreUI/Molecules/StandardFooterView.swift | 3 --- MVMCoreUI/Molecules/StandardHeaderView.swift | 3 --- MVMCoreUI/Molecules/TwoButtonView.swift | 3 --- MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m | 2 +- 12 files changed, 15 insertions(+), 34 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/CaretView.swift b/MVMCoreUI/Atoms/Views/CaretView.swift index 62b82b90..ec4457c2 100644 --- a/MVMCoreUI/Atoms/Views/CaretView.swift +++ b/MVMCoreUI/Atoms/Views/CaretView.swift @@ -108,10 +108,6 @@ open class CaretView: MFView { // Configure class properties with JSON values guard let dictionary = json else { return } - if let backgroundColorHex = dictionary[KeyBackgroundColor] as? String { - backgroundColor = UIColor.mfGet(forHex: backgroundColorHex) - } - if let strokeColorHex = dictionary["strokeColor"] as? String { strokeColor = UIColor.mfGet(forHex: strokeColorHex) } diff --git a/MVMCoreUI/Atoms/Views/DashLine.swift b/MVMCoreUI/Atoms/Views/DashLine.swift index e9ca4a78..512b48cd 100644 --- a/MVMCoreUI/Atoms/Views/DashLine.swift +++ b/MVMCoreUI/Atoms/Views/DashLine.swift @@ -74,10 +74,6 @@ open class DashLine: MFView { // Configure class properties with JSON values guard let jsonDictionary = json else { return } - if let backgroundColorHex = jsonDictionary[KeyBackgroundColor] as? String { - backgroundColor = UIColor.mfGet(forHex: backgroundColorHex) - } - if let isHiddenValue = jsonDictionary[KeyIsHidden] as? Bool { isHidden = isHiddenValue } diff --git a/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift b/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift index 1ca1402a..a059aef5 100644 --- a/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift +++ b/MVMCoreUI/Atoms/Views/LeftRightLabelView.swift @@ -170,10 +170,6 @@ import Foundation leftTextLabel.setWithJSON(dictionary.optionalDictionaryForKey("leftText"), delegateObject: delegateObject as? MVMCoreUIDelegateObject, additionalData: additionalData) rightTextLabel.setWithJSON(dictionary.optionalDictionaryForKey("rightText"), delegateObject: delegateObject as? MVMCoreUIDelegateObject, additionalData: additionalData) - if let backgroundColorHex = dictionary[KeyBackgroundColor] as? String { - backgroundColor = UIColor.mfGet(forHex: backgroundColorHex) - } - if !leftTextLabel.hasText { constrainRightLabel() } else if !rightTextLabel.hasText { diff --git a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift index 9bd22c19..795dea86 100644 --- a/MVMCoreUI/Atoms/Views/MFLoadImageView.swift +++ b/MVMCoreUI/Atoms/Views/MFLoadImageView.swift @@ -186,9 +186,6 @@ import UIKit open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - if let backgroundColorString = json?.optionalStringForKey(KeyBackgroundColor) { - backgroundColor = UIColor.mfGet(forHex: backgroundColorString) - } if let accessibilityString = json?.optionalStringForKey("accessibilityText") { imageView.accessibilityLabel = accessibilityString imageView.accessibilityTraits = .staticText diff --git a/MVMCoreUI/Atoms/Views/MFView.m b/MVMCoreUI/Atoms/Views/MFView.m index 029c6ce2..a5754b2a 100644 --- a/MVMCoreUI/Atoms/Views/MFView.m +++ b/MVMCoreUI/Atoms/Views/MFView.m @@ -8,6 +8,9 @@ #import "MFView.h" @import MVMCore.Swift; +@import MVMCore.NSDictionary_MFConvenience; +#import "MVMCoreUIConstants.h" +#import "UIColor+MFConvenience.h" @implementation MFView @@ -46,6 +49,11 @@ - (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { self.json = json; + + NSString *colorString = [json string:KeyBackgroundColor]; + if (colorString) { + self.backgroundColor = [UIColor mfGetColorForHex:colorString]; + } } @end diff --git a/MVMCoreUI/Atoms/Views/SeparatorView.m b/MVMCoreUI/Atoms/Views/SeparatorView.m index 44e95d3c..9abaeaab 100644 --- a/MVMCoreUI/Atoms/Views/SeparatorView.m +++ b/MVMCoreUI/Atoms/Views/SeparatorView.m @@ -115,10 +115,7 @@ [self setAsLight]; } } - NSString *backgroundColor = [json string:KeyBackgroundColor]; - if (backgroundColor) { - self.backgroundColor = [UIColor mfGetColorForHex:backgroundColor]; - } + } else { self.hidden = YES; } diff --git a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m index 2f97c09a..7166efee 100644 --- a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m +++ b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m @@ -326,6 +326,9 @@ if (self.molecule) { [self.molecule setWithJSON:json delegateObject:delegateObject additionalData:additionalData]; } + if (self.constrainedView) { + self.backgroundColor = self.constrainedView.backgroundColor; + } } @end diff --git a/MVMCoreUI/Molecules/MoleculeStackView.swift b/MVMCoreUI/Molecules/MoleculeStackView.swift index ad667d16..59c8280d 100644 --- a/MVMCoreUI/Molecules/MoleculeStackView.swift +++ b/MVMCoreUI/Molecules/MoleculeStackView.swift @@ -111,7 +111,8 @@ public class MoleculeStackView: ViewConstrainingView { } translatesAutoresizingMaskIntoConstraints = false backgroundColor = .clear - addConstrainedView(contentView) + addSubview(contentView) + pinView(toSuperView: contentView) contentView.setContentHuggingPriority(.defaultHigh, for: .vertical) contentView.setContentHuggingPriority(.defaultHigh, for: .horizontal) } @@ -164,10 +165,6 @@ public class MoleculeStackView: ViewConstrainingView { items = self.items } self.items = [] - - if let colorString = json?.optionalStringForKey(KeyBackgroundColor) { - backgroundColor = .mfGet(forHex: colorString) - } guard let molecules = json?.arrayForKey(KeyMolecules) as? [[String: Any]] else { return diff --git a/MVMCoreUI/Molecules/StandardFooterView.swift b/MVMCoreUI/Molecules/StandardFooterView.swift index 73088b2e..b99ad5d0 100644 --- a/MVMCoreUI/Molecules/StandardFooterView.swift +++ b/MVMCoreUI/Molecules/StandardFooterView.swift @@ -95,9 +95,6 @@ public class StandardFooterView: ViewConstrainingView { open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - if let colorString = json?.optionalStringForKey(KeyBackgroundColor) { - backgroundColor = .mfGet(forHex: colorString) - } twoButtonView.setWithJSON(json?.optionalDictionaryForKey("twoButtonView"), delegateObject: delegateObject, additionalData: additionalData) textButton.setWithJSON(json?.optionalDictionaryForKey("textButton"), delegateObject: delegateObject, additionalData: additionalData) } diff --git a/MVMCoreUI/Molecules/StandardHeaderView.swift b/MVMCoreUI/Molecules/StandardHeaderView.swift index 2391f062..b9639f07 100644 --- a/MVMCoreUI/Molecules/StandardHeaderView.swift +++ b/MVMCoreUI/Molecules/StandardHeaderView.swift @@ -122,9 +122,6 @@ public class StandardHeaderView: ViewConstrainingView { // MARK: - MVMCoreUIMoleculeViewProtocol open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - if let colorString = json?.optionalStringForKey(KeyBackgroundColor) { - backgroundColor = .mfGet(forHex: colorString) - } if let colorString = json?.optionalStringForKey("contentColor") { let color = UIColor.mfGet(forHex: colorString) headlineLabel.textColor = color diff --git a/MVMCoreUI/Molecules/TwoButtonView.swift b/MVMCoreUI/Molecules/TwoButtonView.swift index c5085cce..4b4f64d9 100644 --- a/MVMCoreUI/Molecules/TwoButtonView.swift +++ b/MVMCoreUI/Molecules/TwoButtonView.swift @@ -41,9 +41,6 @@ import UIKit // MARK: - MVMCoreUIMoleculeViewProtocol open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) - if let backgroundColorString = json?.optionalStringForKey(KeyBackgroundColor) { - backgroundColor = UIColor.mfGet(forHex: backgroundColorString) - } let primaryButtonMap = json?.optionalDictionaryForKey("primaryButton") let secondaryButtonMap = json?.optionalDictionaryForKey("secondaryButton") set(primaryButtonJSON: primaryButtonMap, secondaryButtonJSON: secondaryButtonMap, delegateObject: delegateObject, additionalData: additionalData) diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index 148932bb..b9177192 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -89,13 +89,13 @@ return nil; } UIView *molecule = [self createMoleculeForName:moleculeName]; - [molecule setWithJSON:json delegateObject:delegateObject additionalData:nil]; // Check if we need to constrain this view. UIView *castMolecule = [molecule conformsToProtocol:@protocol(MVMCoreUIViewConstrainingProtocol)] ? (UIView *)molecule : nil; if (constrainIfNeeded && [castMolecule respondsToSelector:@selector(needsToBeConstrained)] && [castMolecule needsToBeConstrained]) { molecule = [[ViewConstrainingView alloc] initWithMolecule:molecule alignment:[castMolecule respondsToSelector:@selector(alignment)] ? [castMolecule alignment] : UIStackViewAlignmentFill]; } + [molecule setWithJSON:json delegateObject:delegateObject additionalData:nil]; return molecule; }