From 2b4d8b95c961fb5dee5bd5575454c23ab920c246 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 3 Apr 2019 14:46:34 -0400 Subject: [PATCH 1/9] checkbox --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ++ MVMCoreUI/Atoms/Views/CheckBoxWithLabel.swift | 31 ++++++++++++ MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.h | 3 ++ MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m | 47 ++++++++++++++++++- MVMCoreUI/Atoms/Views/ViewConstrainingView.h | 3 ++ MVMCoreUI/Atoms/Views/ViewConstrainingView.m | 28 ++++++----- .../MVMCoreUIMoleculeMappingObject.m | 3 +- .../Protocols/FormValidationProtocol.swift | 2 +- 8 files changed, 104 insertions(+), 17 deletions(-) create mode 100644 MVMCoreUI/Atoms/Views/CheckBoxWithLabel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 5df32702..201e8d9a 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 0105618E224BBE7700E1557D /* FormValidator+TextFields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */; }; 0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */; }; 01056191224BBE8000E1557D /* FormValidationProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01056190224BBE7F00E1557D /* FormValidationProtocol.swift */; }; + 013DAB042254FCE00092ABB7 /* CheckBoxWithLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 013DAB032254FCE00092ABB7 /* CheckBoxWithLabel.swift */; }; 01DF55E021F8FAA800CC099B /* MFTextFieldListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */; }; 01DF567021FA5AB300CC099B /* TextFieldListFormViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */; }; 01E569D3223FFFA500327251 /* ThreeLayerViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = D2A5146A2214905000345BFB /* ThreeLayerViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -167,6 +168,7 @@ 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+TextFields.swift"; sourceTree = ""; }; 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+FormParams.swift"; sourceTree = ""; }; 01056190224BBE7F00E1557D /* FormValidationProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidationProtocol.swift; sourceTree = ""; }; + 013DAB032254FCE00092ABB7 /* CheckBoxWithLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckBoxWithLabel.swift; sourceTree = ""; }; 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MFTextFieldListView.swift; sourceTree = ""; }; 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFieldListFormViewController.swift; sourceTree = ""; }; D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUINavigationController.h; sourceTree = ""; }; @@ -595,6 +597,7 @@ D22D1F19220341F50077CEC0 /* MVMCoreUICheckBox.m */, D22D1F44220496A30077CEC0 /* MVMCoreUISwitch.h */, D22D1F45220496A30077CEC0 /* MVMCoreUISwitch.m */, + 013DAB032254FCE00092ABB7 /* CheckBoxWithLabel.swift */, ); path = Views; sourceTree = ""; @@ -870,6 +873,7 @@ D29770F221F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m in Sources */, DBC4391922442197001AB423 /* DashLine.swift in Sources */, D29DF29621E7ADB8003B2FB9 /* StackableViewController.m in Sources */, + 013DAB042254FCE00092ABB7 /* CheckBoxWithLabel.swift in Sources */, D22D1F1F220343560077CEC0 /* MVMCoreUICheckMarkView.m in Sources */, D282AAB4223FDDAE00C46919 /* MFLoadImageView.swift in Sources */, D29DF11721E6805F003B2FB9 /* UIColor+MFConvenience.m in Sources */, diff --git a/MVMCoreUI/Atoms/Views/CheckBoxWithLabel.swift b/MVMCoreUI/Atoms/Views/CheckBoxWithLabel.swift new file mode 100644 index 00000000..533ee060 --- /dev/null +++ b/MVMCoreUI/Atoms/Views/CheckBoxWithLabel.swift @@ -0,0 +1,31 @@ +// +// ChecckBoxWithLabel.swift +// MVMCoreUI +// +// Created by Suresh, Kamlesh on 4/3/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers public class CheckBoxWithLabel: ViewConstrainingView { + let mvmCheckBox = MVMCoreUICheckBox(frame: .zero) + + public init() { + super.init(frame: .zero) + } + + public required init?(coder decoder: NSCoder) { + super.init(coder: decoder) + } + + public override func setupView() { + super.setupView() + addConstrainedView(mvmCheckBox) + } + + override open func setWithJSON(_ json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) { + super.setWithJSON(json, delegate: delegate, additionalData: additionalData) + mvmCheckBox.setWithJSON(json, delegate: delegate, additionalData: additionalData) + } +} diff --git a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.h b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.h index 853293c7..32fb1e02 100644 --- a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.h +++ b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.h @@ -59,4 +59,7 @@ - (void)setValueForAccessibilityText:(nullable NSString *)text; - (void)hideDescriptionLabelAndPinCheckboxToRight; +// Molecule Design +- (void)setWithJSON:(nullable NSDictionary *)json delegate:(nullable NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData; + @end diff --git a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m index c67c628f..f00d9101 100644 --- a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m +++ b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m @@ -16,10 +16,13 @@ #import "UIColor+MFConvenience.h" #import "MVMCoreUIUtility.h" #import "MFStyler.h" +#import + static const CGFloat FaultTolerance = 20.f; static const CGFloat CheckBoxHeightWidth = 18.0; -@interface MVMCoreUICheckBox () + +@interface MVMCoreUICheckBox () @property (nonatomic, readwrite) BOOL isSelected; @property (weak, nonatomic) UIView *checkedSquare; @@ -38,12 +41,32 @@ static const CGFloat CheckBoxHeightWidth = 18.0; @property (nullable, strong, nonatomic) NSLayoutConstraint *checkboxWidth; @property (nullable, strong, nonatomic) NSLayoutConstraint *checkboxHeight; +@property (nonatomic) BOOL isRequired; +@property (nullable, strong, nonatomic) NSString *fieldKey; +@property (nullable, weak) id delegate; + @end @implementation MVMCoreUICheckBox #pragma mark - convenient class methods +- (void)setWithJSON:(nullable NSDictionary *)json delegate:(nullable NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData { + [FormValidator setupValidationWithMolecule:self delegate:(id)delegate]; + self.delegate = (id)delegate; + self.fieldKey = [json stringForKey:@"fieldKey"]; + self.isRequired = [json boolForKey:@"required"]; + + NSString *checkedColorHex = [json string:@"checkedColor"]; + NSString *unCheckedColorHex = [json string:@"unCheckedColor"]; + + UIColor *checkedColor = checkedColorHex ? [UIColor mfGetColorForHex:checkedColorHex]: [UIColor blackColor]; + UIColor *unCheckedColor = unCheckedColorHex ? [UIColor mfGetColorForHex:unCheckedColorHex]: [UIColor clearColor]; + NSString *label = [json string:@"label"]; + + [self setupWithCheckedColor:checkedColor unCheckColor:unCheckedColor text:label]; +} + + (instancetype)mfCheckBox { MVMCoreUICheckBox *checkBox = [[self alloc] initWithFrame:CGRectZero]; checkBox.translatesAutoresizingMaskIntoConstraints = NO; @@ -68,6 +91,23 @@ static const CGFloat CheckBoxHeightWidth = 18.0; return checkBox; } +#pragma mark - FormValidationProtocol + +- (BOOL)isValidField { + if (self.isRequired) { + return self.isSelected; + } + return true; +} + +- (nullable NSString *)formFieldName { + return self.fieldKey; +} + +- (nullable id)formFieldValue { + return @(self.isSelected); +} + #pragma mark - inits - (instancetype)initWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor text:(NSString *)text { @@ -253,7 +293,7 @@ static const CGFloat CheckBoxHeightWidth = 18.0; [self setSelected:selected animated:animated runBlock:YES]; } -- (void)setSelected:(BOOL)selected animated:(BOOL)animated runBlock:(BOOL)runBlock{ +- (void)setSelected:(BOOL)selected animated:(BOOL)animated runBlock:(BOOL)runBlock { [self addAccessibilityLabel:selected]; self.isSelected = selected; @@ -271,6 +311,9 @@ static const CGFloat CheckBoxHeightWidth = 18.0; } completion:nil]; [self.checkMark updateCheckSelected:NO animated:animated]; } + + FormValidator *formValidator = [FormValidator getFormValidatorForDelegate:self.delegate]; + [formValidator enableByValidation]; } - (void)setColor:(nullable UIColor *)color forState:(UIControlState)state { diff --git a/MVMCoreUI/Atoms/Views/ViewConstrainingView.h b/MVMCoreUI/Atoms/Views/ViewConstrainingView.h index bb4740a7..939c3b6f 100644 --- a/MVMCoreUI/Atoms/Views/ViewConstrainingView.h +++ b/MVMCoreUI/Atoms/Views/ViewConstrainingView.h @@ -47,4 +47,7 @@ // For setting up the view. - (void)setupView; +// Add a View Constraining View +- (void)addConstrainedView:(nonnull UIView *)view; + @end diff --git a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m index a88b61c3..1ef339fb 100644 --- a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m +++ b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m @@ -28,28 +28,30 @@ ViewConstrainingView *constrainingView = [[ViewConstrainingView alloc] initWithFrame:CGRectZero]; constrainingView.translatesAutoresizingMaskIntoConstraints = NO; constrainingView.backgroundColor = [UIColor clearColor]; - + [constrainingView addConstrainedView:view]; + return constrainingView; +} + +- (void)addConstrainedView:(nonnull UIView *)view { view.translatesAutoresizingMaskIntoConstraints = NO; - [constrainingView addSubview:view]; - constrainingView.constrainedView = view; + [self addSubview:view]; + self.constrainedView = view; - NSLayoutConstraint *leftPin = [view.leftAnchor constraintEqualToAnchor:constrainingView.leftAnchor]; - constrainingView.leftPin = leftPin; + NSLayoutConstraint *leftPin = [view.leftAnchor constraintEqualToAnchor:self.leftAnchor]; + self.leftPin = leftPin; leftPin.active = YES; - NSLayoutConstraint *topPin = [view.topAnchor constraintEqualToAnchor:constrainingView.topAnchor]; - constrainingView.topPin = topPin; + NSLayoutConstraint *topPin = [view.topAnchor constraintEqualToAnchor:self.topAnchor]; + self.topPin = topPin; topPin.active = YES; - NSLayoutConstraint *bottomPin = [constrainingView.bottomAnchor constraintEqualToAnchor:view.bottomAnchor]; - constrainingView.bottomPin = bottomPin; + NSLayoutConstraint *bottomPin = [self.bottomAnchor constraintEqualToAnchor:view.bottomAnchor]; + self.bottomPin = bottomPin; bottomPin.active = YES; - NSLayoutConstraint *rightPin = [constrainingView.rightAnchor constraintEqualToAnchor:view.rightAnchor]; - constrainingView.rightPin = rightPin; + NSLayoutConstraint *rightPin = [self.rightAnchor constraintEqualToAnchor:view.rightAnchor]; + self.rightPin = rightPin; rightPin.active = YES; - - return constrainingView; } - (void)pinToSuperView { diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index 0936f9df..4eb66001 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -32,7 +32,8 @@ @"standardFooter": StandardFooterView.class, @"caretView": CaretView.class, @"caretButton": CaretButton.class, - @"textField" : MFTextField.class + @"textField" : MFTextField.class, + @"checkbox" : CheckBoxWithLabel.class } mutableCopy]; }); return mapping; diff --git a/MVMCoreUI/Protocols/FormValidationProtocol.swift b/MVMCoreUI/Protocols/FormValidationProtocol.swift index bfdbb0fd..5336af24 100644 --- a/MVMCoreUI/Protocols/FormValidationProtocol.swift +++ b/MVMCoreUI/Protocols/FormValidationProtocol.swift @@ -15,5 +15,5 @@ import Foundation @objc optional func enableField(_ enable: Bool) @objc optional func formFieldName() -> String? - @objc optional func formFieldValue() -> String? + @objc optional func formFieldValue() -> Any? } From 4b02477592314de0fdd0b8876f7f10a93586d8bf Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 9 Apr 2019 14:33:41 -0400 Subject: [PATCH 2/9] merge From fa4b03ac1d0b2f67c68df8f74d827704f63f42cd Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 11 Apr 2019 11:20:46 -0400 Subject: [PATCH 3/9] code review --- MVMCoreUI.xcodeproj/project.pbxproj | 1 - MVMCoreUI/Atoms/TextFields/MFTextField.m | 2 +- MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.h | 1 - MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m | 8 ++++---- MVMCoreUI/Utility/MVMCoreUIConstants.h | 3 +++ MVMCoreUI/Utility/MVMCoreUIConstants.m | 3 +++ 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index c32e376c..eca11941 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -869,7 +869,6 @@ D29770F221F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m in Sources */, DBC4391922442197001AB423 /* DashLine.swift in Sources */, D29DF29621E7ADB8003B2FB9 /* StackableViewController.m in Sources */, - 013DAB042254FCE00092ABB7 /* CheckBoxWithLabel.swift in Sources */, D22D1F1F220343560077CEC0 /* MVMCoreUICheckMarkView.m in Sources */, D282AAB4223FDDAE00C46919 /* MFLoadImageView.swift in Sources */, D29DF11721E6805F003B2FB9 /* UIColor+MFConvenience.m in Sources */, diff --git a/MVMCoreUI/Atoms/TextFields/MFTextField.m b/MVMCoreUI/Atoms/TextFields/MFTextField.m index 565e086c..ff1d3fd8 100644 --- a/MVMCoreUI/Atoms/TextFields/MFTextField.m +++ b/MVMCoreUI/Atoms/TextFields/MFTextField.m @@ -326,7 +326,7 @@ } // key used to send text value to server - string = [map string:@"fieldKey"]; + string = [map string:KeyFieldKey]; if (string.length > 0) { self.fieldKey = string; } diff --git a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.h b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.h index 32fb1e02..831c1994 100644 --- a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.h +++ b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.h @@ -59,7 +59,6 @@ - (void)setValueForAccessibilityText:(nullable NSString *)text; - (void)hideDescriptionLabelAndPinCheckboxToRight; -// Molecule Design - (void)setWithJSON:(nullable NSDictionary *)json delegate:(nullable NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData; @end diff --git a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m index f00d9101..fb81e0b5 100644 --- a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m +++ b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m @@ -54,15 +54,15 @@ static const CGFloat CheckBoxHeightWidth = 18.0; - (void)setWithJSON:(nullable NSDictionary *)json delegate:(nullable NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData { [FormValidator setupValidationWithMolecule:self delegate:(id)delegate]; self.delegate = (id)delegate; - self.fieldKey = [json stringForKey:@"fieldKey"]; - self.isRequired = [json boolForKey:@"required"]; - + self.fieldKey = [json stringForKey:KeyFieldKey]; + self.isRequired = [json boolForKey:KeyRequired]; + NSString *checkedColorHex = [json string:@"checkedColor"]; NSString *unCheckedColorHex = [json string:@"unCheckedColor"]; UIColor *checkedColor = checkedColorHex ? [UIColor mfGetColorForHex:checkedColorHex]: [UIColor blackColor]; UIColor *unCheckedColor = unCheckedColorHex ? [UIColor mfGetColorForHex:unCheckedColorHex]: [UIColor clearColor]; - NSString *label = [json string:@"label"]; + NSString *label = [json string:KeyLabel]; [self setupWithCheckedColor:checkedColor unCheckColor:unCheckedColor text:label]; } diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.h b/MVMCoreUI/Utility/MVMCoreUIConstants.h index 93f77713..ba0eff4d 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.h +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.h @@ -35,6 +35,9 @@ extern NSString * const KeyTextColor; extern NSString * const KeyIsHidden; extern NSString * const KeyIsOpaque; +extern NSString * const KeyFieldKey; +extern NSString * const KeyRequired; + #pragma mark - Values extern NSString * const StringY; diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.m b/MVMCoreUI/Utility/MVMCoreUIConstants.m index 684f013b..43763ae2 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.m +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.m @@ -18,6 +18,8 @@ NSString * const KeyValue = @"value"; NSString * const KeyLabel = @"label"; NSString * const KeyDisable = @"disable"; NSString * const KeyFieldName = @"fieldName"; +NSString * const KeyFieldKey = @"fieldKey"; +NSString * const KeyRequired = @"required"; NSString * const KeyHideMainMenu = @"hideMainMenu"; NSString * const KeyProgressPercent = @"progressPercent"; @@ -34,6 +36,7 @@ NSString * const KeyTextColor = @"textColor"; NSString * const KeyIsHidden = @"isHidden"; NSString * const KeyIsOpaque = @"isOpaque"; + #pragma mark - Values NSString * const StringY = @"Y"; From 0abefbcdc00ad1ee90a678361d4590ca18dac3d1 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 17 Apr 2019 11:40:44 -0400 Subject: [PATCH 4/9] using MVMCoreUIDelegateObject --- MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.h | 2 -- MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m | 11 ++++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.h b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.h index 831c1994..853293c7 100644 --- a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.h +++ b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.h @@ -59,6 +59,4 @@ - (void)setValueForAccessibilityText:(nullable NSString *)text; - (void)hideDescriptionLabelAndPinCheckboxToRight; -- (void)setWithJSON:(nullable NSDictionary *)json delegate:(nullable NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData; - @end diff --git a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m index fb81e0b5..00415b71 100644 --- a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m +++ b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m @@ -43,7 +43,7 @@ static const CGFloat CheckBoxHeightWidth = 18.0; @property (nonatomic) BOOL isRequired; @property (nullable, strong, nonatomic) NSString *fieldKey; -@property (nullable, weak) id delegate; +@property (nullable, weak) DelegateObject *delegate; @end @@ -51,9 +51,10 @@ static const CGFloat CheckBoxHeightWidth = 18.0; #pragma mark - convenient class methods -- (void)setWithJSON:(nullable NSDictionary *)json delegate:(nullable NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData { - [FormValidator setupValidationWithMolecule:self delegate:(id)delegate]; - self.delegate = (id)delegate; +- (void)setWithJSON:(NSDictionary *)json delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { + + [FormValidator setupValidationWithMolecule:self delegate:((MVMCoreUIDelegateObject *)delegateObject).formValidationProtocol]; + self.delegate = delegateObject; self.fieldKey = [json stringForKey:KeyFieldKey]; self.isRequired = [json boolForKey:KeyRequired]; @@ -312,7 +313,7 @@ static const CGFloat CheckBoxHeightWidth = 18.0; [self.checkMark updateCheckSelected:NO animated:animated]; } - FormValidator *formValidator = [FormValidator getFormValidatorForDelegate:self.delegate]; + FormValidator *formValidator = [FormValidator getFormValidatorForDelegate:((MVMCoreUIDelegateObject *)self.delegate).formValidationProtocol]; [formValidator enableByValidation]; } From 9709c7195dd9e40a45820e2011097ab4330a90d9 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Mon, 29 Apr 2019 15:00:29 -0400 Subject: [PATCH 5/9] use molecule label --- MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m | 35 +++++++++++++++++------ 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m index 9d3b80a9..bd717f88 100644 --- a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m +++ b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m @@ -62,9 +62,17 @@ static const CGFloat CheckBoxHeightWidth = 18.0; UIColor *checkedColor = checkedColorHex ? [UIColor mfGetColorForHex:checkedColorHex]: [UIColor blackColor]; UIColor *unCheckedColor = unCheckedColorHex ? [UIColor mfGetColorForHex:unCheckedColorHex]: [UIColor clearColor]; + NSString *label = [json string:KeyLabel]; - - [self setupWithCheckedColor:checkedColor unCheckColor:unCheckedColor text:label]; + if (label) { + [self setupWithCheckedColor:checkedColor unCheckColor:unCheckedColor text:label]; + } else { + [self setupWithCheckedColor:checkedColor + unCheckColor:unCheckedColor + label:[json dict:KeyLabel] + delegateObject:delegateObject + additionalData: additionalData]; + } } + (instancetype)mfCheckBox { @@ -246,17 +254,26 @@ static const CGFloat CheckBoxHeightWidth = 18.0; } } +- (void)setupWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor { + [self setupView]; + if (checkedColor) { + self.checkedColor = checkedColor; + } + if (unCheckedColor) { + self.unCheckedColor = unCheckedColor; + } +} + - (void)setupWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor text:(NSString *)text { - [self setupView]; - if (checkedColor) { - self.checkedColor = checkedColor; - } - if (unCheckedColor) { - self.unCheckedColor = unCheckedColor; - } + [self setupWithCheckedColor:checkedColor unCheckColor:unCheckedColor]; [self setDescriptionText:text]; } +- (void)setupWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor label:(NSDictionary *)labelJson delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData{ + [self setupWithCheckedColor:checkedColor unCheckColor:unCheckedColor]; + [self.descriptionLabel setWithJSON:labelJson delegateObject:delegateObject additionalData:additionalData]; +} + - (void)updateView:(CGFloat)size { [MVMCoreDispatchUtility performBlockOnMainThread:^{ [self.descriptionLabel updateView:size]; From d2d4c30cf69f4f21bcc93cdbd7042fcb4a0d2c66 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Mon, 29 Apr 2019 16:20:27 -0400 Subject: [PATCH 6/9] labelMap --- MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m index bd717f88..1aa182ab 100644 --- a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m +++ b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m @@ -69,7 +69,7 @@ static const CGFloat CheckBoxHeightWidth = 18.0; } else { [self setupWithCheckedColor:checkedColor unCheckColor:unCheckedColor - label:[json dict:KeyLabel] + label:[json dict:@"labelMap"] delegateObject:delegateObject additionalData: additionalData]; } @@ -118,6 +118,14 @@ static const CGFloat CheckBoxHeightWidth = 18.0; #pragma mark - inits +- (instancetype)init { + self = [super init]; + if (self) { + [self setupView]; + } + return self; +} + - (instancetype)initWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor text:(NSString *)text { if (self = [super init]) { [self setupWithCheckedColor:checkedColor unCheckColor:unCheckedColor text:text]; @@ -255,7 +263,6 @@ static const CGFloat CheckBoxHeightWidth = 18.0; } - (void)setupWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor { - [self setupView]; if (checkedColor) { self.checkedColor = checkedColor; } @@ -269,7 +276,7 @@ static const CGFloat CheckBoxHeightWidth = 18.0; [self setDescriptionText:text]; } -- (void)setupWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor label:(NSDictionary *)labelJson delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData{ +- (void)setupWithCheckedColor:(UIColor *)checkedColor unCheckColor:(UIColor *)unCheckedColor label:(NSDictionary *)labelJson delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { [self setupWithCheckedColor:checkedColor unCheckColor:unCheckedColor]; [self.descriptionLabel setWithJSON:labelJson delegateObject:delegateObject additionalData:additionalData]; } From 257cac3794860e62ed463eeb764a3e30384688f4 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 30 Apr 2019 13:47:08 -0400 Subject: [PATCH 7/9] file --- .../Molecules/MVMCoreUIMoleculeViewProtocol.h | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h diff --git a/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h b/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h new file mode 100644 index 00000000..12557967 --- /dev/null +++ b/MVMCoreUI/Molecules/MVMCoreUIMoleculeViewProtocol.h @@ -0,0 +1,33 @@ +// +// MVMCoreUIMoleculeViewProtocol.h +// MVMCoreUI +// +// Created by Scott Pfeil on 2/11/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +#import +@class DelegateObject; + +@protocol MVMCoreUIMoleculeViewProtocol + +// Sets up the ui based on the json +- (void)setWithJSON:(nullable NSDictionary *)json delegateObject:(nullable DelegateObject *)delegateObject additionalData:(nullable NSDictionary *)additionalData; + +@optional + +// Called after init to provide an early setter for any molecule specific logic +- (void)setAsMolecule; + +// Notifies the creator that the view needs to be constrained in a view. +- (BOOL)needsToBeConstrained; + +// The alignment for the molecule if constrained. +- (UIStackViewAlignment)moleculeAlignment; + +// For the molecule list to load more efficiently. ++ (CGFloat)estimatedHeightForRow; + +@end + + From 8282e9a61737f8e35ccc0cb61df5a88cb5118474 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 30 Apr 2019 15:14:38 -0400 Subject: [PATCH 8/9] fixes with constaints --- MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m | 21 ++++++++++++++----- MVMCoreUI/Atoms/Views/ViewConstrainingView.h | 3 --- .../FormValidationProtocol.swift | 4 ++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m index 4a57aeb7..f7239def 100644 --- a/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m +++ b/MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m @@ -21,7 +21,7 @@ static const CGFloat FaultTolerance = 20.f; static const CGFloat CheckBoxHeightWidth = 18.0; -@interface MVMCoreUICheckBox () +@interface MVMCoreUICheckBox () @property (nonatomic, readwrite) BOOL isSelected; @property (weak, nonatomic) UIView *checkedSquare; @@ -42,16 +42,24 @@ static const CGFloat CheckBoxHeightWidth = 18.0; @property (nonatomic) BOOL isRequired; @property (nullable, strong, nonatomic) NSString *fieldKey; -@property (nullable, weak) DelegateObject *delegate; +@property (nullable, strong, nonatomic) DelegateObject *delegate; @end @implementation MVMCoreUICheckBox -#pragma mark - convenient class methods +#pragma mark - MVMCoreUIMoleculeViewProtocol + +- (BOOL)needsToBeConstrained { + return YES; +} + +- (UIStackViewAlignment)moleculeAlignment { + return UIStackViewAlignmentLeading; +} - (void)setWithJSON:(NSDictionary *)json delegateObject:(DelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { - + [FormValidator setupValidationWithMolecule:self delegate:((MVMCoreUIDelegateObject *)delegateObject).formValidationProtocol]; self.delegate = delegateObject; self.fieldKey = [json stringForKey:KeyFieldKey]; @@ -70,6 +78,9 @@ static const CGFloat CheckBoxHeightWidth = 18.0; additionalData: additionalData]; } + +#pragma mark - convenient class methods + + (instancetype)mfCheckBox { MVMCoreUICheckBox *checkBox = [[self alloc] initWithFrame:CGRectZero]; checkBox.translatesAutoresizingMaskIntoConstraints = NO; @@ -331,7 +342,7 @@ static const CGFloat CheckBoxHeightWidth = 18.0; [self.checkMark updateCheckSelected:NO animated:animated]; } - FormValidator *formValidator = [FormValidator getFormValidatorForDelegate:((MVMCoreUIDelegateObject *)self.delegate).formValidationProtocol]; + FormValidator *formValidator = ((MVMCoreUIDelegateObject *)self.delegate).formValidationProtocol.formValidatorModel; [formValidator enableByValidation]; } diff --git a/MVMCoreUI/Atoms/Views/ViewConstrainingView.h b/MVMCoreUI/Atoms/Views/ViewConstrainingView.h index 9e1f0316..e4b9e585 100644 --- a/MVMCoreUI/Atoms/Views/ViewConstrainingView.h +++ b/MVMCoreUI/Atoms/Views/ViewConstrainingView.h @@ -44,9 +44,6 @@ // Pins all edges to its super. 0 constant - (void)pinToSuperView; -// Add a view to be constrained in this view. -- (void)addConstrainedView:(nonnull UIView *)view; - // Resets all the constraints to default. - (void)resetConstraints; diff --git a/MVMCoreUI/FormUIHelpers/FormValidationProtocol.swift b/MVMCoreUI/FormUIHelpers/FormValidationProtocol.swift index afce4d28..63ef182d 100644 --- a/MVMCoreUI/FormUIHelpers/FormValidationProtocol.swift +++ b/MVMCoreUI/FormUIHelpers/FormValidationProtocol.swift @@ -22,6 +22,6 @@ import Foundation // The Field name key value pair for sending to server @objc optional func formFieldName() -> String? - // The Feild value key value paid for sending to server - @objc optional func formFieldValue() -> String? + // The Feild value key value pair for sending to server + @objc optional func formFieldValue() -> Any? } From 175fe574c71474ef461b4e931289c0a1285bd85c Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 30 Apr 2019 16:04:51 -0400 Subject: [PATCH 9/9] typo --- MVMCoreUI/Atoms/Views/ViewConstrainingView.h | 2 +- MVMCoreUI/FormUIHelpers/FormValidationProtocol.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/ViewConstrainingView.h b/MVMCoreUI/Atoms/Views/ViewConstrainingView.h index e4b9e585..6b97f891 100644 --- a/MVMCoreUI/Atoms/Views/ViewConstrainingView.h +++ b/MVMCoreUI/Atoms/Views/ViewConstrainingView.h @@ -50,7 +50,7 @@ // For setting up the view. - (void)setupView; -// Add a View Constraining View +// Add a view to be constrained in this view. - (void)addConstrainedView:(nonnull UIView *)view; @end diff --git a/MVMCoreUI/FormUIHelpers/FormValidationProtocol.swift b/MVMCoreUI/FormUIHelpers/FormValidationProtocol.swift index 63ef182d..b593a503 100644 --- a/MVMCoreUI/FormUIHelpers/FormValidationProtocol.swift +++ b/MVMCoreUI/FormUIHelpers/FormValidationProtocol.swift @@ -22,6 +22,6 @@ import Foundation // The Field name key value pair for sending to server @objc optional func formFieldName() -> String? - // The Feild value key value pair for sending to server + // The Field value key value pair for sending to server @objc optional func formFieldValue() -> Any? }