From b443c4a3897c0031019af5dfd5d9a76d5b2f1f0a Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 2 Dec 2019 17:33:06 -0500 Subject: [PATCH 01/11] Reducing constraints. --- .../Atoms/Views/CheckboxWithLabelView.swift | 49 +++++-------------- 1 file changed, 12 insertions(+), 37 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift index f148863b..55f32ae9 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift @@ -7,7 +7,7 @@ // -@objcMembers open class CheckboxWithLabelView: ViewConstrainingView { +@objcMembers open class CheckboxWithLabelView: View { //-------------------------------------------------- // MARK: - Outlets //-------------------------------------------------- @@ -33,12 +33,10 @@ // MARK: - Constraints //-------------------------------------------------- - var checkboxWidthConstraint: NSLayoutConstraint? var checkboxHeightConstraint: NSLayoutConstraint? var checkboxTopConstraint: NSLayoutConstraint? var checkboxBottomConstraint: NSLayoutConstraint? var checkboxCenterYConstraint: NSLayoutConstraint? - var centerLabelCheckboxConstraint: NSLayoutConstraint? //-------------------------------------------------- // MARK: - Life Cycle @@ -56,33 +54,24 @@ label.text = "" - let dimension = sizeObject?.getValueBasedOnApplicationWidth() ?? Checkbox.defaultHeightWidth - checkboxWidthConstraint = checkbox.heightAnchor.constraint(equalToConstant: dimension) - checkboxWidthConstraint?.isActive = true - checkboxHeightConstraint = checkbox.widthAnchor.constraint(equalToConstant: dimension) - checkboxHeightConstraint?.isActive = true - checkbox.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true - checkbox.topAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.topAnchor).isActive = true - layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: checkbox.bottomAnchor).isActive = true - let checboxBottom = checkbox.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor) - checboxBottom.priority = UILayoutPriority(249) - checboxBottom.isActive = true - - // Allows various positions of checkbox. checkboxBottomConstraint = layoutMarginsGuide.bottomAnchor.constraint(equalTo: checkbox.bottomAnchor) + checkboxBottomConstraint?.priority = .defaultHigh + checkboxBottomConstraint?.isActive = true + checkboxTopConstraint = checkbox.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor) + checkboxTopConstraint?.priority = .defaultHigh + checkboxTopConstraint?.isActive = true + checkboxCenterYConstraint = checkbox.centerYAnchor.constraint(equalTo: centerYAnchor) - centerLabelCheckboxConstraint = label.centerYAnchor.constraint(equalTo: checkbox.centerYAnchor) label.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true layoutMarginsGuide.trailingAnchor.constraint(equalTo: label.trailingAnchor).isActive = true label.leadingAnchor.constraint(equalTo: checkbox.trailingAnchor, constant: PaddingTwo).isActive = true - layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: label.bottomAnchor).isActive = true let bottomLabelConstraint = layoutMarginsGuide.bottomAnchor.constraint(equalTo: label.bottomAnchor) - bottomLabelConstraint.priority = UILayoutPriority(249) + bottomLabelConstraint.priority = UILayoutPriority(250) bottomLabelConstraint.isActive = true alignCheckbox(.center) @@ -102,7 +91,7 @@ setupView() } - public convenience init() { + public convenience override init() { self.init(frame: .zero) } @@ -125,19 +114,16 @@ checkboxBottomConstraint?.isActive = false checkboxTopConstraint?.isActive = false checkboxCenterYConstraint?.isActive = true - centerLabelCheckboxConstraint?.isActive = true case .top: checkboxBottomConstraint?.isActive = false checkboxTopConstraint?.isActive = true checkboxCenterYConstraint?.isActive = false - centerLabelCheckboxConstraint?.isActive = false case .bottom: checkboxBottomConstraint?.isActive = true checkboxTopConstraint?.isActive = false checkboxCenterYConstraint?.isActive = false - centerLabelCheckboxConstraint?.isActive = false } } } @@ -145,7 +131,7 @@ /// MARK: - Molecular extension CheckboxWithLabelView { - override open class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + open class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { return CGFloat(Checkbox.defaultHeightWidth) } @@ -153,29 +139,18 @@ extension CheckboxWithLabelView { super.updateView(size) label.updateView(size) - - if self.checkbox.responds(to: #selector(self.updateView(_:))) { - if let dimension = sizeObject?.getValueBased(onSize: size) { - checkboxWidthConstraint?.constant = dimension - checkboxHeightConstraint?.constant = dimension - checkbox.updateView(size) - } - } - layoutIfNeeded() } - override open func alignment() -> UIStackView.Alignment { + open func alignment() -> UIStackView.Alignment { return .leading } - open override func resetConstraints() { - super.resetConstraints() + open func resetConstraints() { checkboxCenterYConstraint?.isActive = false checkboxBottomConstraint?.isActive = false checkboxTopConstraint?.isActive = false - centerLabelCheckboxConstraint?.isActive = false } open override func reset() { From 9b53f4bac04e3ba6e9868ad46d02ca213c629ebe Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 3 Dec 2019 09:07:43 -0500 Subject: [PATCH 02/11] Paired down constraints. Made variables public. Mild formatting. --- .../Atoms/Views/CheckboxWithLabelView.swift | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift index 55f32ae9..30722295 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift @@ -19,9 +19,9 @@ // MARK: - Properties //-------------------------------------------------- - var sizeObject: MFSizeObject? = MFSizeObject(standardSize: Checkbox.defaultHeightWidth, standardiPadPortraitSize: Checkbox.defaultHeightWidth + 6.0) + public var sizeObject: MFSizeObject? = MFSizeObject(standardSize: Checkbox.defaultHeightWidth, standardiPadPortraitSize: Checkbox.defaultHeightWidth + 6.0) - var checkboxPosition: CheckboxPosition = .center + public var checkboxPosition: CheckboxPosition = .center public enum CheckboxPosition: String { case center @@ -33,10 +33,10 @@ // MARK: - Constraints //-------------------------------------------------- - var checkboxHeightConstraint: NSLayoutConstraint? - var checkboxTopConstraint: NSLayoutConstraint? - var checkboxBottomConstraint: NSLayoutConstraint? - var checkboxCenterYConstraint: NSLayoutConstraint? + public var checkboxHeightConstraint: NSLayoutConstraint? + public var checkboxTopConstraint: NSLayoutConstraint? + public var checkboxBottomConstraint: NSLayoutConstraint? + public var checkboxCenterYConstraint: NSLayoutConstraint? //-------------------------------------------------- // MARK: - Life Cycle @@ -81,12 +81,7 @@ // MARK: - Initializers //-------------------------------------------------- - required public init?(coder: NSCoder) { - super.init(coder: coder) - fatalError("xib file is not implemented for CheckboxWithLabelView") - } - - override public init(frame: CGRect) { + public override init(frame: CGRect) { super.init(frame: frame) setupView() } @@ -101,6 +96,11 @@ alignCheckbox(position) } + required public init?(coder: NSCoder) { + super.init(coder: coder) + fatalError("xib file is not implemented for CheckboxWithLabelView") + } + //-------------------------------------------------- // MARK: - Methods //-------------------------------------------------- @@ -128,11 +128,11 @@ } } -/// MARK: - Molecular +// MARK: - Molecular extension CheckboxWithLabelView { - open class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { - return CGFloat(Checkbox.defaultHeightWidth) + open class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + return 200 } @objc override open func updateView(_ size: CGFloat) { @@ -142,10 +142,6 @@ extension CheckboxWithLabelView { layoutIfNeeded() } - open func alignment() -> UIStackView.Alignment { - return .leading - } - open func resetConstraints() { checkboxCenterYConstraint?.isActive = false From aaa8e4132ebb454db8a3cd8244a7ea8d64128bf0 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 4 Dec 2019 16:25:31 -0500 Subject: [PATCH 03/11] Brought back resizing to checkbox. --- MVMCoreUI/Atoms/Views/Checkbox.swift | 11 +++++++++-- MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift | 3 +-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index 370f5826..2dc32675 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -16,6 +16,8 @@ import MVMCore // MARK: - Properties //-------------------------------------------------- + public var sizeObject: MFSizeObject? = MFSizeObject(standardSize: Checkbox.defaultHeightWidth, standardiPadPortraitSize: Checkbox.defaultHeightWidth + 6.0) + // Form Validation var isRequired = false var fieldKey: String? @@ -117,8 +119,8 @@ import MVMCore // MARK: - Constraints //-------------------------------------------------- - private var heightConstraint: NSLayoutConstraint? - private var widthConstraint: NSLayoutConstraint? + public var heightConstraint: NSLayoutConstraint? + public var widthConstraint: NSLayoutConstraint? /// Updates the height and width anchors of the Checkbox with the assigned value. public var heigthWidthConstant: CGFloat = Checkbox.defaultHeightWidth { @@ -398,6 +400,11 @@ import MVMCore public func updateView(_ size: CGFloat) { + if let dimension = sizeObject?.getValueBased(onSize: size) { + widthConstraint?.constant = dimension + heightConstraint?.constant = dimension + } + layoutIfNeeded() } diff --git a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift index 30722295..b2ef5ab2 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift @@ -19,8 +19,6 @@ // MARK: - Properties //-------------------------------------------------- - public var sizeObject: MFSizeObject? = MFSizeObject(standardSize: Checkbox.defaultHeightWidth, standardiPadPortraitSize: Checkbox.defaultHeightWidth + 6.0) - public var checkboxPosition: CheckboxPosition = .center public enum CheckboxPosition: String { @@ -139,6 +137,7 @@ extension CheckboxWithLabelView { super.updateView(size) label.updateView(size) + checkbox.updateView(size) layoutIfNeeded() } From a7989c589f6f6bfae225d71ae8ea5253525a1c10 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 9 Dec 2019 11:03:31 -0500 Subject: [PATCH 04/11] Increased the tappable space of the Checkbox. --- MVMCoreUI/Atoms/Views/Checkbox.swift | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index 2dc32675..6d831d82 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -351,18 +351,14 @@ import MVMCore open override func touchesEnded(_ touches: Set, with event: UIEvent?) { - sendActions(for: touchIsAcceptablyOutside(touches.first) ? .touchUpOutside : .touchUpInside) + sendActions(for: .touchUpInside) } - func touchIsAcceptablyOutside(_ touch: UITouch?) -> Bool { - let endLocation = touch?.location(in: self) - let x = endLocation?.x ?? 0.0 - let y = endLocation?.y ?? 0.0 - let faultTolerance: CGFloat = 20.0 - let widthLimit = CGFloat(bounds.size.width + faultTolerance) - let heightLimt = CGFloat(bounds.size.height + faultTolerance) + override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool { - return x < -faultTolerance || y < -faultTolerance || x > widthLimit || y > heightLimt + let faultTolerance: CGFloat = 20.0 + let area = bounds.insetBy(dx: -faultTolerance, dy: -faultTolerance) + return area.contains(point) } override open func accessibilityActivate() -> Bool { @@ -413,7 +409,7 @@ import MVMCore FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol) guard let dictionary = json else { return } - + groupName = dictionary.optionalStringForKey("groupName") fieldValue = dictionary.optionalStringForKey("value") if let fieldKey = dictionary[KeyFieldKey] as? String { @@ -470,7 +466,7 @@ import MVMCore // MARK:- FormValidationProtocol extension Checkbox: FormValidationFormFieldProtocol { - + public func formFieldGroupName() -> String? { return groupName } From 335649860b8dfeccaa9fc95bb830aa4dae481544 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 10 Dec 2019 11:15:09 -0500 Subject: [PATCH 05/11] constraint adjustments. --- MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift index b2ef5ab2..0cbfee07 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift @@ -55,11 +55,9 @@ checkbox.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true checkboxBottomConstraint = layoutMarginsGuide.bottomAnchor.constraint(equalTo: checkbox.bottomAnchor) - checkboxBottomConstraint?.priority = .defaultHigh checkboxBottomConstraint?.isActive = true checkboxTopConstraint = checkbox.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor) - checkboxTopConstraint?.priority = .defaultHigh checkboxTopConstraint?.isActive = true checkboxCenterYConstraint = checkbox.centerYAnchor.constraint(equalTo: centerYAnchor) @@ -68,10 +66,13 @@ layoutMarginsGuide.trailingAnchor.constraint(equalTo: label.trailingAnchor).isActive = true label.leadingAnchor.constraint(equalTo: checkbox.trailingAnchor, constant: PaddingTwo).isActive = true + layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: label.bottomAnchor).isActive = true + let bottomLabelConstraint = layoutMarginsGuide.bottomAnchor.constraint(equalTo: label.bottomAnchor) - bottomLabelConstraint.priority = UILayoutPriority(250) bottomLabelConstraint.isActive = true + label.heightAnchor.constraint(greaterThanOrEqualToConstant: 15).isActive = true + alignCheckbox(.center) } From ed1897062574eb5e6fad797a75e10b796ef2a4bd Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 12 Dec 2019 09:23:04 -0500 Subject: [PATCH 06/11] correcting errors. Improving Control. --- MVMCoreUI/Atoms/Views/Checkbox.swift | 16 ++++++++++------ MVMCoreUI/BaseClasses/Control.swift | 21 ++++++++++++++++++--- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index 6d831d82..27576bc8 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -11,7 +11,7 @@ import MVMCore /** This class expects its height and width to be equal. */ -@objcMembers open class Checkbox: UIControl, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewConstrainingProtocol { +@objcMembers open class Checkbox: Control, MVMCoreUIViewConstrainingProtocol { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- @@ -149,7 +149,7 @@ import MVMCore fatalError("xib file is not implemented for Checkbox.") } - public convenience init() { + public convenience override init() { self.init(frame:.zero) } @@ -182,7 +182,8 @@ import MVMCore layer.borderColor = borderColor.cgColor } - open func setupView() { + open override func setupView() { + super.setupView() guard constraints.isEmpty else { return } @@ -374,7 +375,8 @@ import MVMCore return true } - open func reset() { + open override func reset() { + super.reset() isEnabled(true) shapeLayer?.removeAllAnimations() @@ -394,7 +396,8 @@ import MVMCore setupView() } - public func updateView(_ size: CGFloat) { + public override func updateView(_ size: CGFloat) { + super.updateView(size) if let dimension = sizeObject?.getValueBased(onSize: size) { widthConstraint?.constant = dimension @@ -404,7 +407,8 @@ import MVMCore layoutIfNeeded() } - public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + public override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { + super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) self.delegateObject = delegateObject FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol) diff --git a/MVMCoreUI/BaseClasses/Control.swift b/MVMCoreUI/BaseClasses/Control.swift index fdf8204f..79db2c6d 100644 --- a/MVMCoreUI/BaseClasses/Control.swift +++ b/MVMCoreUI/BaseClasses/Control.swift @@ -8,17 +8,25 @@ import UIKit -public class Control: UIControl { - var json: [AnyHashable: Any]? +@objcMembers open class Control: UIControl { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + + public var json: [AnyHashable: Any]? private var initialSetupPerformed = false + //-------------------------------------------------- + // MARK: - Initializers + //-------------------------------------------------- + public override init(frame: CGRect) { super.init(frame: .zero) initialSetup() } - init() { + public init() { super.init(frame: .zero) initialSetup() } @@ -28,6 +36,10 @@ public class Control: UIControl { initialSetup() } + //-------------------------------------------------- + // MARK: - Setup + //-------------------------------------------------- + public func initialSetup() { if !initialSetupPerformed { initialSetupPerformed = true @@ -36,7 +48,9 @@ public class Control: UIControl { } } +// MARK: - MVMCoreViewProtocol extension Control: MVMCoreViewProtocol { + public func updateView(_ size: CGFloat) { } @@ -47,6 +61,7 @@ extension Control: MVMCoreViewProtocol { } } +// MARK: - MVMCoreUIMoleculeViewProtocol extension Control: MVMCoreUIMoleculeViewProtocol { public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { self.json = json From 8804e21d3ce08f3faf63d96431c195ff5a344729 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 12 Dec 2019 14:42:32 -0500 Subject: [PATCH 07/11] New constant. Updated control to work with Apple's design guidelines with control. Updates made to checkbox and checkboxLabel. --- MVMCoreUI/Atoms/Views/Checkbox.swift | 8 ------- .../Atoms/Views/CheckboxWithLabelView.swift | 3 +-- MVMCoreUI/BaseClasses/Control.swift | 21 +++++++++++++++---- MVMCoreUI/Utility/MVMCoreUIConstants.h | 4 ++++ MVMCoreUI/Utility/MVMCoreUIConstants.m | 4 ++++ 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index 27576bc8..a206953a 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -140,7 +140,6 @@ import MVMCore accessibilityTraits = .button accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "checkbox_action_hint") updateAccessibilityLabel() - setupView() } /// There is currently no intention on using xib files. @@ -355,13 +354,6 @@ import MVMCore sendActions(for: .touchUpInside) } - override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool { - - let faultTolerance: CGFloat = 20.0 - let area = bounds.insetBy(dx: -faultTolerance, dy: -faultTolerance) - return area.contains(point) - } - override open func accessibilityActivate() -> Bool { sendActions(for: .touchUpInside) return true diff --git a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift index 0cbfee07..404764fe 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift @@ -30,8 +30,7 @@ //-------------------------------------------------- // MARK: - Constraints //-------------------------------------------------- - - public var checkboxHeightConstraint: NSLayoutConstraint? + public var checkboxTopConstraint: NSLayoutConstraint? public var checkboxBottomConstraint: NSLayoutConstraint? public var checkboxCenterYConstraint: NSLayoutConstraint? diff --git a/MVMCoreUI/BaseClasses/Control.swift b/MVMCoreUI/BaseClasses/Control.swift index 79db2c6d..5774ff5a 100644 --- a/MVMCoreUI/BaseClasses/Control.swift +++ b/MVMCoreUI/BaseClasses/Control.swift @@ -33,7 +33,7 @@ import UIKit public required init?(coder: NSCoder) { super.init(coder: coder) - initialSetup() + fatalError("Control does not support xib.") } //-------------------------------------------------- @@ -41,18 +41,31 @@ import UIKit //-------------------------------------------------- public func initialSetup() { + if !initialSetupPerformed { initialSetupPerformed = true setupView() } } + + //-------------------------------------------------- + // MARK: - UITouch + //-------------------------------------------------- + + override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool { + + // If the control is smaller than 44pt by width or height, this will compensate. + let faultToleranceX: CGFloat = max((MinimumTappableArea - bounds.size.width) / 2.0, 0) + let faultToleranceY: CGFloat = max((MinimumTappableArea - bounds.size.height) / 2.0, 0) + let area = bounds.insetBy(dx: -faultToleranceX, dy: -faultToleranceY) + return area.contains(point) + } } // MARK: - MVMCoreViewProtocol extension Control: MVMCoreViewProtocol { - public func updateView(_ size: CGFloat) { - } + public func updateView(_ size: CGFloat) {} /// Will be called only once. public func setupView() { @@ -63,7 +76,7 @@ extension Control: MVMCoreViewProtocol { // MARK: - MVMCoreUIMoleculeViewProtocol extension Control: MVMCoreUIMoleculeViewProtocol { - public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { + public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { self.json = json if let backgroundColorString = json?.optionalStringForKey(KeyBackgroundColor) { diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.h b/MVMCoreUI/Utility/MVMCoreUIConstants.h index 778ede4f..e5587745 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.h +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.h @@ -77,3 +77,7 @@ typedef NS_ENUM(NSInteger, CoreUIErrorCode) { ErrorCodeModuleMolecule = 100, ErrorCodeListMolecule = 101 }; + +#pragma mark - Apple Design Guidelines + +extern CGFloat const MinimumTappableArea; diff --git a/MVMCoreUI/Utility/MVMCoreUIConstants.m b/MVMCoreUI/Utility/MVMCoreUIConstants.m index 26636266..6211cfee 100644 --- a/MVMCoreUI/Utility/MVMCoreUIConstants.m +++ b/MVMCoreUI/Utility/MVMCoreUIConstants.m @@ -69,3 +69,7 @@ BOOL DisableAnimations = NO; // Hand Scroll Key NSString * const KeyHandScrollAnimation = @"handScrollAnimation"; NSString * const KeyHandScroll = @"hand_scroll"; + +#pragma mark - Apple Design Guidelines + +CGFloat const MinimumTappableArea = 44.0f; From 3dd9decfed16043a881a248d00cdc6c3dbc61b40 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 12 Dec 2019 14:53:52 -0500 Subject: [PATCH 08/11] Removed height constraint. This class will expect text to function properly. --- MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift index 404764fe..7d60d1bf 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift @@ -44,8 +44,6 @@ guard subviews.isEmpty else { return } - translatesAutoresizingMaskIntoConstraints = false - addSubview(checkbox) addSubview(label) @@ -66,12 +64,10 @@ label.leadingAnchor.constraint(equalTo: checkbox.trailingAnchor, constant: PaddingTwo).isActive = true layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: label.bottomAnchor).isActive = true - let bottomLabelConstraint = layoutMarginsGuide.bottomAnchor.constraint(equalTo: label.bottomAnchor) + bottomLabelConstraint.priority = .defaultLow bottomLabelConstraint.isActive = true - label.heightAnchor.constraint(greaterThanOrEqualToConstant: 15).isActive = true - alignCheckbox(.center) } From 9e5ccb01a795f59c1f9b48ebfac997ba3b90e8d5 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 19 Dec 2019 11:09:18 -0500 Subject: [PATCH 09/11] removed unused func. --- MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift | 7 ------- 1 file changed, 7 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift index 7d60d1bf..7cd7d1a7 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift @@ -137,13 +137,6 @@ extension CheckboxWithLabelView { layoutIfNeeded() } - open func resetConstraints() { - - checkboxCenterYConstraint?.isActive = false - checkboxBottomConstraint?.isActive = false - checkboxTopConstraint?.isActive = false - } - open override func reset() { super.reset() From 6c9fede0b9d94db0b8fa27a16b2f7d6bef9775d3 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 19 Dec 2019 11:12:59 -0500 Subject: [PATCH 10/11] improved reset. --- MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift index 7cd7d1a7..6991adef 100644 --- a/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift +++ b/MVMCoreUI/Atoms/Views/CheckboxWithLabelView.swift @@ -142,6 +142,7 @@ extension CheckboxWithLabelView { label.text = "" checkbox.reset() + alignCheckbox(.center) } override open func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { From e36d487d326f710d7302c6d9bcb758d209ad329c Mon Sep 17 00:00:00 2001 From: panxi Date: Fri, 20 Dec 2019 15:00:42 -0500 Subject: [PATCH 11/11] change model name to containerModel to avoid compiling error --- MVMCoreUI/Containers/Container.swift | 4 +-- MVMCoreUI/Molecules/Items/StackItem.swift | 4 +-- MVMCoreUI/Molecules/ModuleMolecule.swift | 2 +- MVMCoreUI/Molecules/StandardHeaderView.swift | 38 ++++++++++---------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/MVMCoreUI/Containers/Container.swift b/MVMCoreUI/Containers/Container.swift index 069cd9e3..6beb72e0 100644 --- a/MVMCoreUI/Containers/Container.swift +++ b/MVMCoreUI/Containers/Container.swift @@ -185,7 +185,7 @@ public class ContainerHelper: NSObject { } open class Container: View { - var model: ContainerModelProtocol? + var containerModel: ContainerModelProtocol? var view: UIView? let containerHelper = ContainerHelper() @@ -198,7 +198,7 @@ public extension Container { override func updateView(_ size: CGFloat) { super.updateView(size) (view as? MVMCoreViewProtocol)?.updateView(size) - MFStyler.setMarginsFor(self, size: size, defaultHorizontal: model?.useHorizontalMargins ?? true, top: model?.useHorizontalMargins ?? true ? topMarginPadding : 0, bottom: model?.useHorizontalMargins ?? true ? bottomMarginPadding : 0) + MFStyler.setMarginsFor(self, size: size, defaultHorizontal: containerModel?.useHorizontalMargins ?? true, top: containerModel?.useHorizontalMargins ?? true ? topMarginPadding : 0, bottom: containerModel?.useHorizontalMargins ?? true ? bottomMarginPadding : 0) } /// Will be called only once. diff --git a/MVMCoreUI/Molecules/Items/StackItem.swift b/MVMCoreUI/Molecules/Items/StackItem.swift index 6ee5ae88..88dd5c43 100644 --- a/MVMCoreUI/Molecules/Items/StackItem.swift +++ b/MVMCoreUI/Molecules/Items/StackItem.swift @@ -20,12 +20,12 @@ open class StackItemModel: ContainerModelProtocol { init(with view: StackItem) { self.view = view - view.model = self + view.containerModel = self } init(with view: StackItem, json: [AnyHashable: Any]?) { self.view = view - view.model = self + view.containerModel = self update(with: json) } diff --git a/MVMCoreUI/Molecules/ModuleMolecule.swift b/MVMCoreUI/Molecules/ModuleMolecule.swift index 66e18d47..18dc43fa 100644 --- a/MVMCoreUI/Molecules/ModuleMolecule.swift +++ b/MVMCoreUI/Molecules/ModuleMolecule.swift @@ -18,7 +18,7 @@ struct ModuleMoleculeModel: ContainerModelProtocol { open class ModuleMolecule: Container { public override func setupView() { super.setupView() - model = ModuleMoleculeModel() + containerModel = ModuleMoleculeModel() } // MARK: - MVMCoreUIMoleculeViewProtocol diff --git a/MVMCoreUI/Molecules/StandardHeaderView.swift b/MVMCoreUI/Molecules/StandardHeaderView.swift index dba3fde2..8ed1a879 100644 --- a/MVMCoreUI/Molecules/StandardHeaderView.swift +++ b/MVMCoreUI/Molecules/StandardHeaderView.swift @@ -40,25 +40,25 @@ public class StandardHeaderView: MoleculeContainer { } } - open func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { - //TODO: Need to create setWithModel in ViewConstraining View - - #warning("This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView.") - //TODO: This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView. - setUpWithModel(model, delegateObject, additionalData) - - // This molecule will by default handle margins. - (molecule as? MVMCoreUIViewConstrainingProtocol)?.shouldSetHorizontalMargins?(false) - (molecule as? MVMCoreUIViewConstrainingProtocol)?.shouldSetVerticalMargins?(false) - - guard let headerModel = model as? HeaderModel else { - return - } - - if let seperatorModel = headerModel.seperator as? LineModel { - line?.setWithJSON(seperatorModel.toJSON(), delegateObject: delegateObject, additionalData: additionalData) - } - } +// open func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { +// //TODO: Need to create setWithModel in ViewConstraining View +// +// #warning("This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView.") +// //TODO: This below call should be repaced with super.setWithModel once we get rid of ViewConstrainingView. +// setUpWithModel(model, delegateObject, additionalData) +// +// // This molecule will by default handle margins. +// (molecule as? MVMCoreUIViewConstrainingProtocol)?.shouldSetHorizontalMargins?(false) +// (molecule as? MVMCoreUIViewConstrainingProtocol)?.shouldSetVerticalMargins?(false) +// +// guard let headerModel = model as? HeaderModel else { +// return +// } +// +// if let seperatorModel = headerModel.seperator as? LineModel { +// line?.setWithJSON(seperatorModel.toJSON(), delegateObject: delegateObject, additionalData: additionalData) +// } +// } open override func reset() { super.reset()