From f5e7b24601daf85ac243ed95b01c7347a3ca7474 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Tue, 18 Jan 2022 17:03:53 -0500 Subject: [PATCH 1/4] hide the panels when not showing --- .../SplitViewController/MVMCoreUISplitViewController.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m index 616b5d75..e16daa56 100644 --- a/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m +++ b/MVMCoreUI/Containers/SplitViewController/MVMCoreUISplitViewController.m @@ -337,6 +337,7 @@ CGFloat const PanelAnimationDuration = 0.2; }; void (^completion)(BOOL) = ^(BOOL finished){ + self.leftView.hidden = true; self.mainViewCoverView.hidden = YES; [self panelDidDisappear:self.leftPanel animated:animated]; self.mainView.accessibilityElementsHidden = NO; @@ -360,6 +361,7 @@ CGFloat const PanelAnimationDuration = 0.2; return; } [MVMCoreDispatchUtility performBlockOnMainThread:^{ + self.leftView.hidden = false; if (self.mainViewLeading.constant < .1) { BOOL shouldExtendLeftPanel = [self shouldExtendLeftPanel]; @@ -540,6 +542,7 @@ CGFloat const PanelAnimationDuration = 0.2; }; void (^completion)(BOOL) = ^(BOOL finished){ + self.rightView.hidden = true; self.mainViewCoverView.hidden = YES; [self panelDidDisappear:self.rightPanel animated:animated]; self.mainView.accessibilityElementsHidden = NO; @@ -563,6 +566,7 @@ CGFloat const PanelAnimationDuration = 0.2; return; } [MVMCoreDispatchUtility performBlockOnMainThread:^{ + self.rightView.hidden = false; if (self.mainViewTrailing.constant < .1) { BOOL shouldExtendRightPanel = [self shouldExtendRightPanel]; @@ -726,9 +730,9 @@ CGFloat const PanelAnimationDuration = 0.2; [self addPanel:panel]; self.leftView = panel.view; self.leftPanel = panel; + self.leftView.hidden = YES; self.leftView.translatesAutoresizingMaskIntoConstraints = NO; NSLayoutConstraint *leftPanelWidth = [NSLayoutConstraint constraintWithItem:self.leftView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:270]; - self.leftView.translatesAutoresizingMaskIntoConstraints = NO; leftPanelWidth.active = YES; self.leftPanelWidth = leftPanelWidth; [NSLayoutConstraint constraintWithItem:self.mainView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.leftView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0].active = YES; @@ -762,6 +766,7 @@ CGFloat const PanelAnimationDuration = 0.2; [self addPanel:panel]; self.rightView = panel.view; self.rightPanel = panel; + self.rightView.hidden = YES; self.rightView.translatesAutoresizingMaskIntoConstraints = NO; NSLayoutConstraint *rightPanelWidth = [NSLayoutConstraint constraintWithItem:self.rightView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:270]; rightPanelWidth.active = YES; From 69799be944224d41f3325ed81a4df2d0b41d82df Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 19 Jan 2022 10:38:23 -0600 Subject: [PATCH 2/4] reverse order of method to do FormFieldEffects first, then validation. This is so the validation only runs 1 time instead of 2 times which could cause UI issues. Signed-off-by: Matt Bruce --- MVMCoreUI/FormUIHelpers/FormValidator.swift | 45 +++++++++------------ 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/MVMCoreUI/FormUIHelpers/FormValidator.swift b/MVMCoreUI/FormUIHelpers/FormValidator.swift index 4a1d36c7..42c385e8 100644 --- a/MVMCoreUI/FormUIHelpers/FormValidator.swift +++ b/MVMCoreUI/FormUIHelpers/FormValidator.swift @@ -111,22 +111,6 @@ import MVMCore /// - counter: keeps track of how many times causes another group validation /// - Returns: validity for the FormGroupRule.rules public func validateGroup(_ group: FormGroupRule, counter: Int = 0) throws -> Bool { - let tuple = group.validate(fields) - - group.rules.forEach { rule in - for formKey in rule.fields { - guard let formField = fields[formKey] as? FormRuleWatcherFieldProtocol, - let fieldValidity = tuple.fieldValidity[formKey] else { continue } - formField.setValidity(fieldValidity, rule: rule) - } - } - - // Notify the group watchers of validity. - for watcher in groupWatchers.filter({$0.groupName == group.groupName}) { - watcher.setValidity(tuple.valid) - } - - var ruleChange = false //loop the effects group.effects?.forEach({ effect in @@ -140,24 +124,30 @@ import MVMCore //update the group form rules if let ruleIds = effect.activatedRuleIds { - let didChange = self.updateRules(for: group, with: effectTuple.valid, for: effect.fieldKey, and: ruleIds) - if(didChange) { - ruleChange = didChange - } + self.updateRules(for: group, with: effectTuple.valid, for: effect.fieldKey, and: ruleIds) } } }) - if ruleChange { - if counter > 3 { - throw ValidationError.other(error: "Effect caused validation loop error") - } else { - return try self.validateGroup(group, counter: counter + 1) + //validate the form + let tuple = group.validate(fields) + + //set the validity for the fields + group.rules.forEach { rule in + for formKey in rule.fields { + guard let formField = fields[formKey] as? FormRuleWatcherFieldProtocol, + let fieldValidity = tuple.fieldValidity[formKey] else { continue } + formField.setValidity(fieldValidity, rule: rule) } - } else { - return tuple.valid } + // Notify the group watchers of validity. + for watcher in groupWatchers.filter({$0.groupName == group.groupName}) { + watcher.setValidity(tuple.valid) + } + + return tuple.valid + } /// Updates the Fields in which a specific rule within a FormGroupRule validates against. @@ -166,6 +156,7 @@ import MVMCore /// - validity: If you the fieldKey should be added or removed from a rule /// - fieldKey: FieldKey that will be added or removed from a rule /// - ruleIds: Array of ruleIds to add or remove the fieldKey into the rule.fields property + @discardableResult public func updateRules(for group: FormGroupRule, with validity: Bool, for fieldKey: String, and ruleIds: [String]) -> Bool{ //update the group rules based on the validation of this rule to show/hide var ruleChange = false From 67312fefd3cea787b1a071ac3c5ab03528f1da35 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 19 Jan 2022 11:45:59 -0600 Subject: [PATCH 3/4] if false, the loop was breaking out before the previousValidity was set with the fieldKey that failed. Signed-off-by: Matt Bruce --- MVMCoreUI/FormUIHelpers/Rules/Rules/RuleEqualsModel.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleEqualsModel.swift b/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleEqualsModel.swift index 70b787bf..aa07cb29 100644 --- a/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleEqualsModel.swift +++ b/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleEqualsModel.swift @@ -43,6 +43,7 @@ public class RuleEqualsModel: RulesProtocol { if compareValue != formField.formFieldValue() { valid = false + previousValidity[formKey] = valid break } else { var fieldValidity = valid @@ -50,9 +51,8 @@ public class RuleEqualsModel: RulesProtocol { if let validity = previousFieldValidity[formKey], !validity, fieldValidity { fieldValidity = false } + previousValidity[formKey] = valid } - previousValidity[formKey] = valid - } return (valid: valid, fieldValidity: previousValidity) } From a2319babc738362d70b395b3b874c510fc2b78df Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 19 Jan 2022 11:52:04 -0600 Subject: [PATCH 4/4] ensure the previousValidity is set before breaks Signed-off-by: Matt Bruce --- .../FormUIHelpers/Rules/Rules/RuleEqualsIgnoreCaseModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleEqualsIgnoreCaseModel.swift b/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleEqualsIgnoreCaseModel.swift index 25e21d4f..95149551 100644 --- a/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleEqualsIgnoreCaseModel.swift +++ b/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleEqualsIgnoreCaseModel.swift @@ -50,7 +50,7 @@ public class RuleEqualsIgnoreCaseModel: RulesProtocol { if let validity = previousFieldValidity[formKey], !validity, fieldValidity { fieldValidity = false } - + previousValidity[formKey] = valid break }