diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 968ceff8..7fda38f1 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -154,7 +154,6 @@ D2A5146122121FBF00345BFB /* MoleculeStackTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A5146022121FBF00345BFB /* MoleculeStackTemplate.swift */; }; D2A514632213643100345BFB /* MoleculeStackCenteredTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A514622213643100345BFB /* MoleculeStackCenteredTemplate.swift */; }; D2A514672213885800345BFB /* MVMCoreUIHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A514662213885800345BFB /* MVMCoreUIHeaderView.swift */; }; - D2A514692213B5FB00345BFB /* PrimaryButtonViewMoleculeProtocolExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A514682213B5FB00345BFB /* PrimaryButtonViewMoleculeProtocolExtension.swift */; }; D2A5146B2214905000345BFB /* ThreeLayerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A5146A2214905000345BFB /* ThreeLayerViewController.swift */; }; D2A5146D2214C1E400345BFB /* LegacyLargeHeaderSingleLabelTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2A5146C2214C1E400345BFB /* LegacyLargeHeaderSingleLabelTemplate.swift */; }; D2C5001821F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.h in Headers */ = {isa = PBXBuildFile; fileRef = D2C5001621F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -315,7 +314,6 @@ D2A5146022121FBF00345BFB /* MoleculeStackTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeStackTemplate.swift; sourceTree = ""; }; D2A514622213643100345BFB /* MoleculeStackCenteredTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeStackCenteredTemplate.swift; sourceTree = ""; }; D2A514662213885800345BFB /* MVMCoreUIHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVMCoreUIHeaderView.swift; sourceTree = ""; }; - D2A514682213B5FB00345BFB /* PrimaryButtonViewMoleculeProtocolExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrimaryButtonViewMoleculeProtocolExtension.swift; sourceTree = ""; }; D2A5146A2214905000345BFB /* ThreeLayerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreeLayerViewController.swift; sourceTree = ""; }; D2A5146C2214C1E400345BFB /* LegacyLargeHeaderSingleLabelTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegacyLargeHeaderSingleLabelTemplate.swift; sourceTree = ""; }; D2C5001621F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIViewControllerMappingObject.h; sourceTree = ""; }; @@ -426,7 +424,6 @@ D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */, D29770F621F7C73800B2F0D0 /* PrimaryButtonView.h */, D29770F721F7C73800B2F0D0 /* PrimaryButtonView.m */, - D2A514682213B5FB00345BFB /* PrimaryButtonViewMoleculeProtocolExtension.swift */, D2A514662213885800345BFB /* MVMCoreUIHeaderView.swift */, D2A5145C2211D22A00345BFB /* MVMCoreUIMoleculeViewProtocol.h */, D2A5145E2211DDC100345BFB /* MVMCoreUIMoleculeStackView.swift */, @@ -870,7 +867,6 @@ D29DF17C21E69E1F003B2FB9 /* MFTextButton.m in Sources */, D29DF2C521E7BF57003B2FB9 /* MFTabBarSwipeAnimator.m in Sources */, D29DF2B421E7B76D003B2FB9 /* MFLoadingSpinner.m in Sources */, - D2A514692213B5FB00345BFB /* PrimaryButtonViewMoleculeProtocolExtension.swift in Sources */, D2C5001921F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m in Sources */, D29DF12E21E6851E003B2FB9 /* MVMCoreUITopAlertView.m in Sources */, D29DF2CF21E7C104003B2FB9 /* MFLoadingViewController.m in Sources */, diff --git a/MVMCoreUI/Atoms/Buttons/PrimaryButton.h b/MVMCoreUI/Atoms/Buttons/PrimaryButton.h index b451a196..ba1c06d2 100644 --- a/MVMCoreUI/Atoms/Buttons/PrimaryButton.h +++ b/MVMCoreUI/Atoms/Buttons/PrimaryButton.h @@ -10,6 +10,7 @@ #import #import #import +#import typedef enum : NSUInteger { PrimaryButtonTypeRed, @@ -19,15 +20,24 @@ typedef enum : NSUInteger { // 2.0 PrimaryButtonTypeBlack, PrimaryButtonTypeWhite, - + PrimaryButtonTypeCustom } PrimaryButtonType; static CGFloat const PrimaryButtonHeight = 42.0; static CGFloat const PrimaryButtonSmallHeight = 30.0; -@interface PrimaryButton : MFCustomButton +@interface PrimaryButton : MFCustomButton + +@property (nonatomic, readonly, assign) PrimaryButtonType primaryButtonType; //use reset function to set + +// For custom type. +@property (nonatomic, strong, nullable) UIColor *fillColor; +@property (nonatomic, strong, nullable) UIColor *borderColor; +@property (nonatomic, strong, nullable) UIColor *textColor; +@property (nonatomic, strong, nullable) UIColor *disabledFillColor; +@property (nonatomic, strong, nullable) UIColor *disabledBorderColor; +@property (nonatomic, strong, nullable) UIColor *disabledTextColor; -@property (nonatomic, readonly, assign) PrimaryButtonType primaryButtonType; //use reset function to set @property (nullable, copy, nonatomic) BOOL(^extraValidationBlock)(void); // Set as no to make button filled, set as yes to make button bordered. diff --git a/MVMCoreUI/Atoms/Buttons/PrimaryButton.m b/MVMCoreUI/Atoms/Buttons/PrimaryButton.m index c780aef8..3e44f2bd 100644 --- a/MVMCoreUI/Atoms/Buttons/PrimaryButton.m +++ b/MVMCoreUI/Atoms/Buttons/PrimaryButton.m @@ -13,6 +13,7 @@ #import "UIColor+MFConvenience.h" @import MVMCore.MVMCoreDispatchUtility; @import MVMCore.MVMCoreGetterUtility; +@import MVMCore.NSDictionary_MFConvenience; @interface PrimaryButton () @@ -32,6 +33,8 @@ @implementation PrimaryButton +#pragma mark - Sizing + - (MFSizeObject *)innerPadding { return [MFSizeObject sizeObjectWithStandardSize:24.0 standardiPadPortraitSize:32.0 iPadProLandscapeSize:36.0]; } @@ -110,7 +113,11 @@ } else { [self setAsInactiveGray]; } + break; } + case PrimaryButtonTypeCustom: + [self setAsCustom]; + break; default: break; } @@ -215,6 +222,10 @@ } else { [self setAsInactiveGray]; } + break; + case PrimaryButtonTypeCustom: + [self setAsCustom]; + break; default: break; } @@ -394,9 +405,39 @@ } } +- (void)setAsCustom { + if (self.enabled) { + self.backgroundColor = self.fillColor ?: [UIColor clearColor]; + if (self.bordered) { + self.layer.borderWidth = 1; + self.layer.borderColor = self.borderColor.CGColor ?: [UIColor blackColor].CGColor; + [self setTitleColor:(self.textColor ?: [UIColor colorWithCGColor:self.layer.borderColor]) forState:UIControlStateNormal]; + } else { + self.layer.borderWidth = 0; + self.layer.borderColor = [UIColor clearColor].CGColor; + [self setTitleColor:(self.textColor ?: [UIColor blackColor]) forState:UIControlStateNormal]; + } + } else { + if (self.disabledBorderColor || self.bordered) { + self.layer.borderWidth = 1; + self.layer.borderColor = self.disabledBorderColor.CGColor ?: [UIColor mfPrimaryWhiteButtonDisableColor].CGColor; + self.backgroundColor = self.disabledFillColor ?: [UIColor clearColor]; + [self setTitleColor:(self.disabledTextColor ?: [UIColor colorWithCGColor:self.layer.borderColor]) forState:UIControlStateNormal]; + } else { + self.layer.borderWidth = 0; + self.layer.borderColor = [UIColor clearColor].CGColor; + self.backgroundColor = self.disabledFillColor ?: [UIColor mfPrimaryWhiteButtonDisableColor]; + [self setTitleColor:(self.disabledTextColor ?: [UIColor blackColor]) forState:UIControlStateNormal]; + } + } +} + - (void)setBordered:(BOOL)bordered { if (bordered != _bordered) { - if (bordered) { + if (self.buttonType == PrimaryButtonTypeCustom) { + _bordered = bordered; + [self setAsCustom]; + } else if (bordered) { self.layer.borderWidth = 1; [self setTitleColor:self.backgroundColor forState:UIControlStateNormal]; self.layer.borderColor = self.backgroundColor.CGColor; @@ -521,6 +562,25 @@ #pragma mark - For Subclassing +- (void)setWithJSON:(NSDictionary *)json delegate:(NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData { + self.primaryButtonType = PrimaryButtonTypeCustom; + NSString *color = [json string:@"fillColor"]; + self.fillColor = (color ? [UIColor mfGetColorForHex:color] : nil); + color = [json string:@"textColor"]; + self.textColor = (color ? [UIColor mfGetColorForHex:color] : nil); + color = [json string:@"borderColor"]; + self.borderColor = (color ? [UIColor mfGetColorForHex:color] : nil); + _bordered = self.borderColor != nil; + color = [json string:@"disabledFillColor"]; + self.disabledFillColor = (color ? [UIColor mfGetColorForHex:color] : nil); + color = [json string:@"disabledTextColor"]; + self.disabledTextColor = (color ? [UIColor mfGetColorForHex:color] : nil); + color = [json string:@"disabledBorderColor"]; + self.disabledBorderColor = (color ? [UIColor mfGetColorForHex:color] : nil); + [self setAsSmallButton:[json boolForKey:@"small"]]; + [self setWithActionMap:json actionDelegate:([delegate conformsToProtocol:@protocol(MVMCoreActionDelegateProtocol)] ? (NSObject *)delegate : nil) additionalData:additionalData buttonDelegate:([delegate conformsToProtocol:@protocol(ButtonDelegateProtocol)] ? (id )delegate : nil)]; +} + - (instancetype)initWithCoder:(NSCoder *)aDecoder { if (self = [super initWithCoder:aDecoder]) { [self pinHeight]; diff --git a/MVMCoreUI/Atoms/Views/MFView.h b/MVMCoreUI/Atoms/Views/MFView.h index e985d1a9..eb76b858 100644 --- a/MVMCoreUI/Atoms/Views/MFView.h +++ b/MVMCoreUI/Atoms/Views/MFView.h @@ -7,9 +7,10 @@ // #import +#import @import MVMCore.MVMCoreViewProtocol; -@interface MFView : UIView +@interface MFView : UIView // Called in the initialization functions. Can setup ui here. - (void)setupView; diff --git a/MVMCoreUI/Atoms/Views/MFView.m b/MVMCoreUI/Atoms/Views/MFView.m index ffc25cfe..afe3476a 100644 --- a/MVMCoreUI/Atoms/Views/MFView.m +++ b/MVMCoreUI/Atoms/Views/MFView.m @@ -41,5 +41,7 @@ - (void)updateView:(CGFloat)size { } +- (void)setWithJSON:(NSDictionary *)json delegate:(NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData { +} @end diff --git a/MVMCoreUI/Molecules/MVMCoreUIHeaderView.swift b/MVMCoreUI/Molecules/MVMCoreUIHeaderView.swift index 556e800d..82babc58 100644 --- a/MVMCoreUI/Molecules/MVMCoreUIHeaderView.swift +++ b/MVMCoreUI/Molecules/MVMCoreUIHeaderView.swift @@ -8,7 +8,7 @@ import UIKit -public class MVMCoreUIHeaderView: ViewConstrainingView, MVMCoreUIMoleculeViewProtocol { +public class MVMCoreUIHeaderView: ViewConstrainingView { let headlineLabel = MFLabel.commonLabelH2(true) let messageLabel = MFLabel.commonLabelB2(true) var separatorView: SeparatorView? @@ -86,7 +86,8 @@ public class MVMCoreUIHeaderView: ViewConstrainingView, MVMCoreUIMoleculeViewPro separatorView?.rightPin?.constant = constant } - public func setWithJSON(_ json: [AnyHashable : Any]?, delegate: NSObject?) { + public override func setWithJSON(_ json: [AnyHashable : Any]?, delegate: NSObject?, additionalData: [AnyHashable : Any]?) { + super.setWithJSON(json, delegate: delegate, additionalData: additionalData) headlineLabel.text = json?.optionalStringForKey(KeyTitle) messageLabel.text = json?.optionalStringForKey(KeyMessage) separatorView?.isHidden = !(json?.boolForKey("showSeparator") ?? false) diff --git a/MVMCoreUI/Molecules/MVMCoreUIMoleculeStackView.swift b/MVMCoreUI/Molecules/MVMCoreUIMoleculeStackView.swift index ec30c49e..af336673 100644 --- a/MVMCoreUI/Molecules/MVMCoreUIMoleculeStackView.swift +++ b/MVMCoreUI/Molecules/MVMCoreUIMoleculeStackView.swift @@ -8,17 +8,17 @@ import UIKit -public class MVMCoreUIMoleculeStackView: MFView, MVMCoreUIMoleculeViewProtocol { +public class MVMCoreUIMoleculeStackView: MFView { var spacingBlock: ((Any) -> UIEdgeInsets)? var moleculesArray: [UIView]? - init(withJSON json: [AnyHashable : Any]?, delegate: NSObject?) { + init(withJSON json: [AnyHashable : Any]?, delegate: NSObject?, additionalData: [AnyHashable : Any]?) { super.init(frame: CGRect.zero) - setWithJSON(json, delegate: delegate) + setWithJSON(json, delegate: delegate, additionalData: additionalData) } convenience init(withJSON json: [AnyHashable : Any]?, delegate: NSObject?, spacingBlock: ((Any) -> UIEdgeInsets)?) { - self.init(withJSON: json, delegate: delegate) + self.init(withJSON: json, delegate: delegate, additionalData: nil) self.spacingBlock = spacingBlock } @@ -43,7 +43,8 @@ public class MVMCoreUIMoleculeStackView: MFView, MVMCoreUIMoleculeViewProtocol { } } - public func setWithJSON(_ json: [AnyHashable : Any]?, delegate: NSObject?) { + public override func setWithJSON(_ json: [AnyHashable : Any]?, delegate: NSObject?, additionalData: [AnyHashable : Any]?) { + super.setWithJSON(json, delegate: delegate, additionalData: additionalData) guard let molecules = json?.arrayForKey("molecules") as? [[String: Any]] else { return } @@ -52,7 +53,7 @@ public class MVMCoreUIMoleculeStackView: MFView, MVMCoreUIMoleculeViewProtocol { var moleculesArray = [] as [UIView] for moleculeJSON in molecules { if let name = moleculeJSON.optionalStringForKey("moleculeName"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeForName(name) { - molecule.setWithJSON(moleculeJSON, delegate: delegate) + molecule.setWithJSON(moleculeJSON, delegate: delegate, additionalData: additionalData) moleculesArray.append(molecule) } } diff --git a/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h b/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h index 2d6c7b58..cfb28c3f 100644 --- a/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h +++ b/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h @@ -11,7 +11,7 @@ @protocol MVMCoreUIMoleculeViewProtocol // Sets up the ui based on the json -- (void)setWithJSON:(nullable NSDictionary *)json delegate:(nullable NSObject *)delegate; +- (void)setWithJSON:(nullable NSDictionary *)json delegate:(nullable NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData; @end diff --git a/MVMCoreUI/Molecules/PrimaryButtonView.h b/MVMCoreUI/Molecules/PrimaryButtonView.h index 8b7f39bc..7140a0d3 100644 --- a/MVMCoreUI/Molecules/PrimaryButtonView.h +++ b/MVMCoreUI/Molecules/PrimaryButtonView.h @@ -28,7 +28,10 @@ - (nonnull instancetype)initButtonSmall:(BOOL)small buttonMap:(nullable NSDictionary *)buttonMap actionDelegate:(nullable NSObject *)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id )buttonDelegate; - (nonnull instancetype)initWithPrimaryButtonMap:(nullable NSDictionary *)primaryButtonMap secondaryButtonMap:(nullable NSDictionary *)secondaryButtonMap actionDelegate:(nullable NSObject *)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id )buttonDelegate; -// Sets up with whatever is in the passed in button map. (could be 0, 1, or 2 buttons) +// Sets up with whatever is in the passed in. (could be 0, 1, or 2 buttons) +- (void)setupWithFirstButtonJSON:(nullable NSDictionary *)firstButtonJSON secondButtonJSON:(nullable NSDictionary *)secondButtonJSON additionalData:(nullable NSDictionary *)additionalData actionDelegate:(nullable NSObject *)actionDelegate buttonDelegate:(nullable id )buttonDelegate; + +// Legacy: Sets up with whatever is in the passed in button map. (could be 0, 1, or 2 buttons) - (void)setupWithButtonMap:(nullable NSDictionary *)buttonMap actionDelegate:(nullable NSObject *)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id )buttonDelegate; - (void)setupWithPrimaryButtonMap:(nullable NSDictionary *)primaryButtonMap secondaryButtonMap:(nullable NSDictionary *)secondaryButtonMap actionDelegate:(nullable NSObject *)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id )buttonDelegate; diff --git a/MVMCoreUI/Molecules/PrimaryButtonView.m b/MVMCoreUI/Molecules/PrimaryButtonView.m index 97178560..818f6785 100644 --- a/MVMCoreUI/Molecules/PrimaryButtonView.m +++ b/MVMCoreUI/Molecules/PrimaryButtonView.m @@ -12,6 +12,7 @@ #import #import "MVMCoreUICommonViewsUtility.h" #import "MVMCoreUIConstants.h" +#import "UIColor+MFConvenience.h" @interface PrimaryButtonView () @@ -26,6 +27,25 @@ @end @implementation PrimaryButtonView + +- (void)updateView:(CGFloat)size { + [super updateView:size]; + [MVMCoreDispatchUtility performBlockOnMainThread:^{ + [self.primaryButton updateView:size]; + [self.secondaryButton updateView:size]; + }]; +} + +- (void)setWithJSON:(NSDictionary *)json delegate:(NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData { + [super setWithJSON:json delegate:delegate additionalData:additionalData]; + NSString *backgroundColorString = [json string:@"backgroundColor"]; + if (backgroundColorString) { + self.backgroundColor = [UIColor mfGetColorForHex:backgroundColorString]; + } + [self setupWithFirstButtonJSON:[json dict:@"FirstButton"] secondButtonJSON:[json dict:@"SecondButton"] additionalData:nil actionDelegate:([delegate conformsToProtocol:@protocol(MVMCoreActionDelegateProtocol)] ? (NSObject *)delegate : nil) buttonDelegate:([delegate conformsToProtocol:@protocol(ButtonDelegateProtocol)] ? (id )delegate : nil)]; +} + +#pragma mark - Inits - (instancetype)init { if (self = [super init]) { @@ -85,6 +105,8 @@ return self; } +#pragma mark - Setup + - (void)setupWithButtonMap:(nullable NSDictionary *)buttonMap actionDelegate:(nullable NSObject *)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id )buttonDelegate { NSDictionary *secondaryButtonMap = [buttonMap dict:KeySecondaryButton]; @@ -92,8 +114,15 @@ [self setupWithPrimaryButtonMap:primaryButtonMap secondaryButtonMap:secondaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate]; } +- (void)setupWithFirstButtonJSON:(nullable NSDictionary *)firstButtonJSON secondButtonJSON:(nullable NSDictionary *)secondButtonJSON additionalData:(nullable NSDictionary *)additionalData actionDelegate:(nullable NSObject *)actionDelegate buttonDelegate:(nullable id )buttonDelegate { + [self setupWithPrimaryButtonMap:firstButtonJSON secondaryButtonMap:secondButtonJSON additionalData:additionalData actionDelegate:actionDelegate buttonDelegate:buttonDelegate legacyJSON:NO]; +} + - (void)setupWithPrimaryButtonMap:(nullable NSDictionary *)primaryButtonMap secondaryButtonMap:(nullable NSDictionary *)secondaryButtonMap actionDelegate:(nullable NSObject *)actionDelegate additionalData:(nullable NSDictionary *)additionalData buttonDelegate:(nullable id )buttonDelegate { - + [self setupWithPrimaryButtonMap:primaryButtonMap secondaryButtonMap:secondaryButtonMap additionalData:additionalData actionDelegate:actionDelegate buttonDelegate:buttonDelegate legacyJSON:YES]; +} + +- (void)setupWithPrimaryButtonMap:(nullable NSDictionary *)primaryButtonMap secondaryButtonMap:(nullable NSDictionary *)secondaryButtonMap additionalData:(nullable NSDictionary *)additionalData actionDelegate:(nullable NSObject *)actionDelegate buttonDelegate:(nullable id )buttonDelegate legacyJSON:(BOOL)legacyJSON { if (primaryButtonMap && secondaryButtonMap) { self.height.active = NO; @@ -103,11 +132,16 @@ self.twoButtonView = nil; [self setupWithTwoButtons]; } - [self.primaryButton setWithActionMap:primaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate]; - [self.secondaryButton setWithActionMap:secondaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate]; + if (legacyJSON) { + [self.primaryButton setWithActionMap:primaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate]; + [self.secondaryButton setWithActionMap:secondaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate]; + } else { + [self.primaryButton setWithJSON:primaryButtonMap delegate:actionDelegate additionalData:additionalData]; + [self.secondaryButton setWithJSON:secondaryButtonMap delegate:actionDelegate additionalData:additionalData]; + } } else if (primaryButtonMap || secondaryButtonMap) { self.height.active = NO; - + // Setup with one button. if (!self.primaryButton || self.secondaryButton) { [self removeSubviews]; @@ -117,16 +151,20 @@ } [self alignCenter]; - if (primaryButtonMap) { - - // Only primary button - [self.primaryButton setWithActionMap:primaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate]; - self.primaryButton.bordered = NO; + if (legacyJSON) { + if (primaryButtonMap) { + + // Only primary button + [self.primaryButton setWithActionMap:primaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate]; + self.primaryButton.bordered = NO; + } else { + + // Only secondary button + [self.primaryButton setWithActionMap:secondaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate]; + self.primaryButton.bordered = YES; + } } else { - - // Only secondary button - [self.primaryButton setWithActionMap:secondaryButtonMap actionDelegate:actionDelegate additionalData:additionalData buttonDelegate:buttonDelegate]; - self.primaryButton.bordered = YES; + [self.primaryButton setWithJSON:primaryButtonMap delegate:actionDelegate additionalData:additionalData]; } } else { [self removeSubviews]; @@ -230,13 +268,7 @@ centerRightPin.active = YES; } -- (void)updateView:(CGFloat)size { - [super updateView:size]; - [MVMCoreDispatchUtility performBlockOnMainThread:^{ - [self.primaryButton updateView:size]; - [self.secondaryButton updateView:size]; - }]; -} +#pragma mark - Configuring - (void)alignLeft { self.alignCenterPin.active = NO; diff --git a/MVMCoreUI/Molecules/PrimaryButtonViewMoleculeProtocolExtension.swift b/MVMCoreUI/Molecules/PrimaryButtonViewMoleculeProtocolExtension.swift deleted file mode 100644 index 7856a5d9..00000000 --- a/MVMCoreUI/Molecules/PrimaryButtonViewMoleculeProtocolExtension.swift +++ /dev/null @@ -1,22 +0,0 @@ -// -// PrimaryButtonViewMoleculeProtocolExtension.swift -// MVMCoreUI -// -// Created by Scott Pfeil on 2/12/19. -// Copyright © 2019 Verizon Wireless. All rights reserved. -// - -import Foundation - -extension PrimaryButtonView: MVMCoreUIMoleculeViewProtocol { - public func setWithJSON(_ json: [AnyHashable : Any]?, delegate: NSObject?) { - let firstButtonMap = json?.optionalDictionaryForKey("FirstButton") - let secondButtonMap = json?.optionalDictionaryForKey("SecondButton") - if let backgroundColor = json?.optionalStringForKey("backgroundColor") { - self.backgroundColor = UIColor.mfGet(forHex: backgroundColor) - } - let actionDelegate = delegate as? MVMCoreActionDelegateProtocol & NSObjectProtocol - let buttonDelegate = delegate as? ButtonDelegateProtocol - setup(withPrimaryButtonMap: firstButtonMap, secondaryButtonMap: secondButtonMap, actionDelegate: actionDelegate, additionalData: nil, buttonDelegate: buttonDelegate) - } -} diff --git a/MVMCoreUI/Molecules/TopLabelsView.h b/MVMCoreUI/Molecules/TopLabelsView.h index 04c2d8be..e4e6494a 100644 --- a/MVMCoreUI/Molecules/TopLabelsView.h +++ b/MVMCoreUI/Molecules/TopLabelsView.h @@ -50,7 +50,4 @@ - (void)setLeftConstant:(CGFloat)leftConstant; - (void)setRightConstant:(CGFloat)rightConstant; -// Sets up the ui based on the json -- (void)setWithJSON:(nullable NSDictionary *)json; - @end diff --git a/MVMCoreUI/Molecules/TopLabelsView.m b/MVMCoreUI/Molecules/TopLabelsView.m index 5452871f..04c9b758 100644 --- a/MVMCoreUI/Molecules/TopLabelsView.m +++ b/MVMCoreUI/Molecules/TopLabelsView.m @@ -14,7 +14,6 @@ #import #import #import -#import @interface TopLabelsView () @@ -215,34 +214,4 @@ self.rightConstraintSeparator.constant = rightConstant; } -- (void)setWithJSON:(nullable NSDictionary *)json { - [self setHeadlineString:[json stringForKey:KeyTitle] messageString:[json stringForKey:KeyMessage]]; - UIColor *textColor = [self colorForTopLabelsWithJSON:json]; - self.headlineLabel.textColor = textColor; - self.messageLabel.textColor = textColor; - self.backgroundColor = [self colorForBackgroundWithJSON:json]; - NSNumber *showBottomLine = [json objectForKey:@"showBottomLine" ofType:[NSNumber class]]; - if (showBottomLine) { - self.separatorView.hidden = ![showBottomLine boolValue]; - } -} - -- (nonnull UIColor *)colorForTopLabelsWithJSON:(nullable NSDictionary *)json { - NSString *titleColor = [json string:@"titleBgColor"]; - if (titleColor) { - return [UIColor mfGetColorForHex:titleColor]; - } else { - return [UIColor blackColor]; - } -} - -- (nonnull UIColor *)colorForBackgroundWithJSON:(nullable NSDictionary *)json { - NSString *color = [json string:@"backgroundColor"]; - if (color) { - return [UIColor mfGetColorForHex:color]; - } else { - return [UIColor clearColor]; - } -} - @end diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index b80f7894..7693e93b 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -48,7 +48,7 @@ return nil; } UIView *molecule = [self getMoleculeForName:moleculeName]; - [molecule setWithJSON:json delegate:delegate]; + [molecule setWithJSON:json delegate:delegate additionalData:nil]; return molecule; } diff --git a/MVMCoreUI/Templates/MoleculeStackCenteredTemplate.swift b/MVMCoreUI/Templates/MoleculeStackCenteredTemplate.swift index dbdf3837..0a781bc6 100644 --- a/MVMCoreUI/Templates/MoleculeStackCenteredTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeStackCenteredTemplate.swift @@ -12,7 +12,7 @@ public class MoleculeStackCenteredTemplate: ThreeLayerViewController { public override func viewForMiddle() -> UIView? { let molecule = loadObject?.pageJSON?.optionalDictionaryForKey("MoleculeStack") - let moleculeStack = MVMCoreUIMoleculeStackView(withJSON: molecule, delegate: self) + let moleculeStack = MVMCoreUIMoleculeStackView(withJSON: molecule, delegate: self, additionalData: nil) return moleculeStack } diff --git a/MVMCoreUI/Templates/MoleculeStackTemplate.swift b/MVMCoreUI/Templates/MoleculeStackTemplate.swift index d13692d0..c31d9c4e 100644 --- a/MVMCoreUI/Templates/MoleculeStackTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeStackTemplate.swift @@ -26,7 +26,7 @@ public class MoleculeStackTemplate: ThreeLayerViewController { guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("MoleculeStack") else { return nil } - return MVMCoreUIMoleculeStackView(withJSON: moleculeJSON, delegate: self) + return MVMCoreUIMoleculeStackView(withJSON: moleculeJSON, delegate: self, additionalData: nil) } override public func viewForBottom() -> UIView? {