From b0ae313d420154f9cf8ae4bd1a966681aefd1f65 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 24 Mar 2020 22:39:44 -0400 Subject: [PATCH] undo legacy changes --- MVMCoreUI/Legacy/Views/ButtonView.swift | 10 ++++++ MVMCoreUI/Legacy/Views/PrimaryButton.h | 4 +++ MVMCoreUI/Legacy/Views/PrimaryButton.m | 41 +++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/MVMCoreUI/Legacy/Views/ButtonView.swift b/MVMCoreUI/Legacy/Views/ButtonView.swift index 4c489ae5..3bdb909b 100644 --- a/MVMCoreUI/Legacy/Views/ButtonView.swift +++ b/MVMCoreUI/Legacy/Views/ButtonView.swift @@ -30,6 +30,11 @@ import UIKit primaryButton?.isEnabled = enabled } + public init(withJSON json: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) { + super.init(frame: .zero) + setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + } + // MARK: - MVMCoreViewProtocol open override func updateView(_ size: CGFloat) { super.updateView(size) @@ -44,6 +49,11 @@ import UIKit alignCenterHorizontal() } + // MARK: - MVMCoreUIMoleculeViewProtocol + open func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + primaryButton?.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + } + // MARK: - Constraining open override func copyBackgroundColor() -> Bool { return true diff --git a/MVMCoreUI/Legacy/Views/PrimaryButton.h b/MVMCoreUI/Legacy/Views/PrimaryButton.h index 511519be..a93e6fc5 100644 --- a/MVMCoreUI/Legacy/Views/PrimaryButton.h +++ b/MVMCoreUI/Legacy/Views/PrimaryButton.h @@ -10,6 +10,7 @@ #import #import #import +@class MVMCoreUIDelegateObject; typedef enum : NSUInteger { PrimaryButtonTypeRed, @@ -117,6 +118,9 @@ static CGFloat const PrimaryButtonSmallHeight = 30.0; - (void)resetButtonType:(PrimaryButtonType)type small:(BOOL)isSmall bordered:(BOOL)bordered; - (void)resetButtonType:(PrimaryButtonType)type tiny:(BOOL)isTiny bordered:(BOOL)bordered; +// Convenience setter for common keys +- (void)setWithJSON:(nullable NSDictionary *)json delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData; + #pragma mark - Handling Validations // Sets the enabled property depending on the validity checks diff --git a/MVMCoreUI/Legacy/Views/PrimaryButton.m b/MVMCoreUI/Legacy/Views/PrimaryButton.m index 7a235fce..ded6bac2 100644 --- a/MVMCoreUI/Legacy/Views/PrimaryButton.m +++ b/MVMCoreUI/Legacy/Views/PrimaryButton.m @@ -655,6 +655,47 @@ return button; } +- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { + 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]; + } + if ((color = [json string:KeyTextColor])) { + self.textColor = [UIColor mfGetColorForHex:color]; + } + if ((color = [json string:@"borderColor"])) { + self.borderColor = [UIColor mfGetColorForHex:color]; + } + _bordered = self.borderColor != nil; + if ((color = [json string:@"disabledFillColor"])) { + self.disabledFillColor = [UIColor mfGetColorForHex:color]; + } + if ((color = [json string:@"disabledTextColor"])) { + self.disabledTextColor = [UIColor mfGetColorForHex:color]; + } + if ((color = [json string:@"disabledBorderColor"])) { + self.disabledBorderColor = [UIColor mfGetColorForHex:color]; + } + + 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]; +} + #pragma mark - Constraining Protocol - (UIStackViewAlignment)horizontalAlignment {