From bbdb2181f22e96db7ca96f9c8b1536158cc564a4 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 8 Oct 2019 11:30:25 -0400 Subject: [PATCH 1/9] aligning with invision. --- MVMCoreUI/Atoms/Views/Checkbox.swift | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index 6f308651..f82d6bed 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -244,10 +244,17 @@ import MVMCore /// Returns a UIBezierPath detailing the path of a checkmark func checkMarkPath() -> CGPath { - let sideLength = max(bounds.size.height, bounds.size.width) - let startPoint = CGPoint(x: 0.33871 * sideLength, y: 0.53225 * sideLength) - let pivotOffSet = CGPoint(x: 0.46774 * sideLength, y: 0.64516 * sideLength) - let endOffset = CGPoint(x: 0.66935 * sideLength , y: 0.37097 * sideLength) + let length = max(bounds.size.height, bounds.size.width) + let xInsetLeft = length * 0.25 + let xInsetRight = length * 0.25 + let yInsetTop = length * 0.3 + let yInsetBottom = length * 0.35 + let innerWidth = length - (xInsetLeft + xInsetRight) + let innerHeight = length - (yInsetTop + yInsetBottom) + + let startPoint = CGPoint(x: xInsetLeft, y: yInsetTop + (innerHeight / 2)) + let pivotOffSet = CGPoint(x: xInsetLeft + (innerWidth * 0.33), y: yInsetTop + innerHeight) + let endOffset = CGPoint(x: xInsetLeft + innerWidth, y: yInsetTop) let bezierPath = UIBezierPath() bezierPath.move(to: startPoint) From ec190a28bdf137a1134762400fda080ebdd90328 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 8 Oct 2019 11:47:08 -0400 Subject: [PATCH 2/9] Further updates made. --- MVMCoreUI/Atoms/Views/Checkbox.swift | 32 ++++++---------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index f82d6bed..187d9d7c 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -8,22 +8,6 @@ import MVMCore -/* - !!! -- DO NOT REMOVE -- !!! - (Unless Design changes the appearance of the checkmark). - - // Offsets based on the 124x124 example checkmark - let startXOffset: Float = 42.0 / 124.0 ~~ 0.33871 - let startYOffset: Float = 66.0 / 124.0 ~~ 0.53225 - let pivotXOffset: Float = 58.0 / 124.0 ~~ 0.46774 - let pivotYOffset: Float = 80.0 / 124.0 ~~ 0.64516 - let endXOffset: Float = 83.0 / 124.0 ~~ 0.66935 - let endYOffset: Float = 46.0 / 124.0 ~~ 0.37097 - let pivotPercentage: Float = 0.34 - let endPercentage = 1.0 - pivotPercentage - let animationInterval: Float = 0.01 - */ - /** This class expects its height and width to be equal. */ @@ -182,7 +166,7 @@ import MVMCore override open func layoutSubviews() { super.layoutSubviews() - drawCheck() + drawShapeLayer() layer.cornerRadius = isRound ? cornerRadiusValue : 0 layer.borderWidth = borderWidth layer.borderColor = borderColor.cgColor @@ -220,8 +204,8 @@ import MVMCore // MARK: - Methods //-------------------------------------------------- - /// Creates the check mark used for the checkbox. - private func drawCheck() { + /// Creates the check mark layer. + private func drawShapeLayer() { if shapeLayer == nil { @@ -241,16 +225,14 @@ import MVMCore } } - /// Returns a UIBezierPath detailing the path of a checkmark + /// - returns: The CGPath of a UIBezierPath detailing the path of a checkmark func checkMarkPath() -> CGPath { let length = max(bounds.size.height, bounds.size.width) let xInsetLeft = length * 0.25 - let xInsetRight = length * 0.25 let yInsetTop = length * 0.3 - let yInsetBottom = length * 0.35 - let innerWidth = length - (xInsetLeft + xInsetRight) - let innerHeight = length - (yInsetTop + yInsetBottom) + let innerWidth = length - (xInsetLeft + length * 0.25) // + Right X Inset + let innerHeight = length - (yInsetTop + length * 0.35) // + Bottom Y Inset let startPoint = CGPoint(x: xInsetLeft, y: yInsetTop + (innerHeight / 2)) let pivotOffSet = CGPoint(x: xInsetLeft + (innerWidth * 0.33), y: yInsetTop + innerHeight) @@ -274,7 +256,7 @@ import MVMCore self.updateSelectionOnly = true self.isSelected = selected self.updateSelectionOnly = false - self.drawCheck() + self.drawShapeLayer() self.shapeLayer?.removeAllAnimations() self.updateCheckboxUI(isSelected: selected, isAnimated: animated) } From 03f12b8a7a014d4a2533dcc440a9e4b9eff23c04 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 8 Oct 2019 13:15:10 -0400 Subject: [PATCH 3/9] added isEnabled func. --- MVMCoreUI/Atoms/Views/Checkbox.swift | 36 ++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index 187d9d7c..1f6a429a 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -62,7 +62,7 @@ import MVMCore private var shapeLayer: CAShapeLayer? /// Width of the check mark. - public var checkWidth: CGFloat = 2 { + public var checkWidth: CGFloat = 2.3 { didSet { if let shapeLayer = shapeLayer { CATransaction.withDisabledAnimations { @@ -75,11 +75,7 @@ import MVMCore /// Color of the check mark. public var checkColor: UIColor = .black { didSet { - if let shapeLayer = shapeLayer { - CATransaction.withDisabledAnimations { - shapeLayer.strokeColor = checkColor.cgColor - } - } + setshapeLayerStrokeColor(checkColor) } } @@ -285,7 +281,7 @@ import MVMCore self.shapeLayer?.strokeEnd = isSelected ? 1 : 0 } - self.backgroundColor = isSelected ? self.checkedBackgroundColor : self.unCheckedBackgroundColor + backgroundColor = isSelected ? checkedBackgroundColor : unCheckedBackgroundColor } } @@ -297,6 +293,32 @@ import MVMCore } } + func isEnabled(_ enabled: Bool) { + + isUserInteractionEnabled = enabled + + if enabled { + layer.borderColor = borderColor.cgColor + backgroundColor = isSelected ? checkedBackgroundColor : unCheckedBackgroundColor + alpha = 1.0 + setshapeLayerStrokeColor(checkColor) + } else { + layer.borderColor = UIColor.mfSilver().cgColor + backgroundColor = .white + alpha = DisableOppacity + setshapeLayerStrokeColor(UIColor.mfSilver()) + } + } + + private func setshapeLayerStrokeColor(_ color: UIColor) { + + if let shapeLayer = shapeLayer { + CATransaction.withDisabledAnimations { + shapeLayer.strokeColor = color.cgColor + } + } + } + //-------------------------------------------------- // MARK: - UITouch //-------------------------------------------------- From 1618583acce693418af22bb1cd758875f9bb2b88 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 8 Oct 2019 15:19:12 -0400 Subject: [PATCH 4/9] corrected comment. --- MVMCoreUI/Atoms/Views/Checkbox.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index 1f6a429a..0d2c3e75 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -259,7 +259,7 @@ import MVMCore } /// updates the visuals of the check mark and background. - /// - parameter isSelection: the check state of the checkbox. + /// - parameter isSelected: the check state of the checkbox. /// - parameter isAnimated: determines of the changes should animate or immediately refelect. public func updateCheckboxUI(isSelected: Bool, isAnimated: Bool) { From 9922ef467422d6b007f9b6b6213eeb9a1855ed6c Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 8 Oct 2019 16:45:34 -0400 Subject: [PATCH 5/9] added enabled molecule logic. --- MVMCoreUI/Atoms/Views/Checkbox.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index 0d2c3e75..2ece7d4a 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -354,6 +354,7 @@ import MVMCore open func reset() { + isEnabled(true) shapeLayer?.removeAllAnimations() shapeLayer?.removeFromSuperlayer() shapeLayer = nil @@ -424,9 +425,15 @@ import MVMCore self.isRound = isRound } + if let enabled = dictionary["isEnabled"] as? Bool { + isEnabled(enabled) + } + if let actionMap = dictionary.optionalDictionaryForKey("actionMap") { actionBlock = { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) } } + +// layoutIfNeeded() } } From 960d9e0e7ca847191819cde67a49080c59530000 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 9 Oct 2019 10:18:18 -0400 Subject: [PATCH 6/9] removed comment. --- MVMCoreUI/Atoms/Views/Checkbox.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index 2ece7d4a..c43accb2 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -432,8 +432,6 @@ import MVMCore if let actionMap = dictionary.optionalDictionaryForKey("actionMap") { actionBlock = { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) } } - -// layoutIfNeeded() } } From 5ef9754e2cb8a362f098dd74941f6dc17caebed7 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 9 Oct 2019 12:45:18 -0400 Subject: [PATCH 7/9] defaulting to clear. --- MVMCoreUI/Atoms/Views/Checkbox.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index c43accb2..c3879f96 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -33,7 +33,7 @@ import MVMCore public var updateSelectionOnly: Bool = false /// The color of the background when checked. - public var checkedBackgroundColor: UIColor = .white { + public var checkedBackgroundColor: UIColor = .clear { didSet { if isSelected { backgroundColor = checkedBackgroundColor @@ -42,7 +42,7 @@ import MVMCore } /// The color of the background when unChecked. - public var unCheckedBackgroundColor: UIColor = .white { + public var unCheckedBackgroundColor: UIColor = .clear { didSet { if !isSelected { backgroundColor = unCheckedBackgroundColor @@ -62,7 +62,7 @@ import MVMCore private var shapeLayer: CAShapeLayer? /// Width of the check mark. - public var checkWidth: CGFloat = 2.3 { + public var checkWidth: CGFloat = 2 { didSet { if let shapeLayer = shapeLayer { CATransaction.withDisabledAnimations { @@ -172,7 +172,7 @@ import MVMCore isUserInteractionEnabled = true translatesAutoresizingMaskIntoConstraints = false - backgroundColor = .white + backgroundColor = .clear } //-------------------------------------------------- @@ -304,7 +304,7 @@ import MVMCore setshapeLayerStrokeColor(checkColor) } else { layer.borderColor = UIColor.mfSilver().cgColor - backgroundColor = .white + backgroundColor = .clear alpha = DisableOppacity setshapeLayerStrokeColor(UIColor.mfSilver()) } @@ -358,7 +358,7 @@ import MVMCore shapeLayer?.removeAllAnimations() shapeLayer?.removeFromSuperlayer() shapeLayer = nil - backgroundColor = nil + backgroundColor = .clear borderColor = .black borderWidth = 1.0 checkColor = .black From f267b98438dbd5711e8d0124a3959f499476aea1 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 17 Oct 2019 11:57:30 -0400 Subject: [PATCH 8/9] constraints added. changes made. --- MVMCoreUI/Atoms/Views/Checkbox.swift | 35 ++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index c3879f96..a568622b 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -75,7 +75,7 @@ import MVMCore /// Color of the check mark. public var checkColor: UIColor = .black { didSet { - setshapeLayerStrokeColor(checkColor) + setShapeLayerStrokeColor(checkColor) } } @@ -115,6 +115,21 @@ import MVMCore } } + //-------------------------------------------------- + // MARK: - Constraints + //-------------------------------------------------- + + private var heightConstraint: NSLayoutConstraint? + private var widthConstraint: NSLayoutConstraint? + + /// Updates the height and width anchors of the Checkbox with the assigned value. + public var heigthWidthConstant: Int = Checkbox.defaultHeightWidth { + didSet { + heightConstraint?.constant = heigthWidthConstant + widthConstraint?.constant = heigthWidthConstant + } + } + //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- @@ -170,9 +185,15 @@ import MVMCore open func setupView() { + guard constraints.isEmpty else { return } + isUserInteractionEnabled = true translatesAutoresizingMaskIntoConstraints = false backgroundColor = .clear + + widthConstraint = widthAnchor.constraint(equalToConstant: Checkbox.defaultHeightWidth) + heightConstraint = heightAnchor.constraint(equalToConstant: Checkbox.defaultHeightWidth) + heightWidthIsActive(true) } //-------------------------------------------------- @@ -301,16 +322,16 @@ import MVMCore layer.borderColor = borderColor.cgColor backgroundColor = isSelected ? checkedBackgroundColor : unCheckedBackgroundColor alpha = 1.0 - setshapeLayerStrokeColor(checkColor) + setShapeLayerStrokeColor(checkColor) } else { layer.borderColor = UIColor.mfSilver().cgColor backgroundColor = .clear alpha = DisableOppacity - setshapeLayerStrokeColor(UIColor.mfSilver()) + setShapeLayerStrokeColor(UIColor.mfSilver()) } } - private func setshapeLayerStrokeColor(_ color: UIColor) { + private func setShapeLayerStrokeColor(_ color: UIColor) { if let shapeLayer = shapeLayer { CATransaction.withDisabledAnimations { @@ -319,6 +340,12 @@ import MVMCore } } + public func heightWidthIsActive(_ isActive: Bool) { + + heightConstraint?.isActive = isActive + widthConstraint?.isActive = isActive + } + //-------------------------------------------------- // MARK: - UITouch //-------------------------------------------------- From 2fdc4795f40859be9cd9ade4d4f99a10f25998f2 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 17 Oct 2019 12:00:44 -0400 Subject: [PATCH 9/9] correcting type. --- MVMCoreUI/Atoms/Views/Checkbox.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index a568622b..d139f130 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -123,7 +123,7 @@ import MVMCore private var widthConstraint: NSLayoutConstraint? /// Updates the height and width anchors of the Checkbox with the assigned value. - public var heigthWidthConstant: Int = Checkbox.defaultHeightWidth { + public var heigthWidthConstant: CGFloat = Checkbox.defaultHeightWidth { didSet { heightConstraint?.constant = heigthWidthConstant widthConstraint?.constant = heigthWidthConstant @@ -140,7 +140,6 @@ import MVMCore accessibilityTraits = .button accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "checkbox_action_hint") updateAccessibilityLabel() - setupView() }