Commit 6215469e by Orkhan Alikhanov

Fixed laying out checkmark sign incorrectly

Before this commit, cgPath and lineWidth of the check mark layer were only updated on the change of selected state.
Fixed to react to size changes made to the parent layer by iOS framework
Fixes bug when CheckButton is changed to have selected state when it has no size (CGSize.zero)
parent 2d066026
...@@ -66,6 +66,9 @@ internal class CheckBoxLayer: BaseIconLayer { ...@@ -66,6 +66,9 @@ internal class CheckBoxLayer: BaseIconLayer {
checkMarkLayer.addSublayer(checkMarkRightLayer) checkMarkLayer.addSublayer(checkMarkRightLayer)
checkMarkLeftLayer.lineCap = kCALineCapSquare checkMarkLeftLayer.lineCap = kCALineCapSquare
checkMarkRightLayer.lineCap = kCALineCapSquare checkMarkRightLayer.lineCap = kCALineCapSquare
checkMarkLeftLayer.strokeEnd = 0
checkMarkRightLayer.strokeEnd = 0
checkmarkColor = { checkmarkColor }() // calling didSet
} }
override func prepareForFirstAnimation() { override func prepareForFirstAnimation() {
...@@ -103,16 +106,6 @@ internal class CheckBoxLayer: BaseIconLayer { ...@@ -103,16 +106,6 @@ internal class CheckBoxLayer: BaseIconLayer {
checkMarkLayer.opacity = 0 checkMarkLayer.opacity = 0
checkMarkLayer.animate(#keyPath(CALayer.opacity), to: 1, dur: totalDuration * 0.1) checkMarkLayer.animate(#keyPath(CALayer.opacity), to: 1, dur: totalDuration * 0.1)
checkMarkLeftLayer.strokeColor = checkmarkColor.cgColor
checkMarkRightLayer.strokeColor = checkmarkColor.cgColor
checkMarkLeftLayer.path = checkMarkPathLeft.cgPath
checkMarkRightLayer.path = checkMarkPathRigth.cgPath
checkMarkLeftLayer.lineWidth = lineWidth
checkMarkRightLayer.lineWidth = lineWidth
checkMarkLeftLayer.strokeEnd = 0
checkMarkRightLayer.strokeEnd = 0
} else { } else {
borderLayer.borderWidth = borderLayerCenterDotBorderWidth borderLayer.borderWidth = borderLayerCenterDotBorderWidth
} }
...@@ -133,10 +126,16 @@ internal class CheckBoxLayer: BaseIconLayer { ...@@ -133,10 +126,16 @@ internal class CheckBoxLayer: BaseIconLayer {
super.layoutSublayers() super.layoutSublayers()
guard !isAnimating else { return } guard !isAnimating else { return }
borderLayer.frame.size = CGSize(width: sideLength, height: sideLength) let s = CGSize(width: sideLength, height: sideLength)
checkMarkLayer.frame.size = borderLayer.frame.size borderLayer.frame.size = s
checkMarkLeftLayer.frame.size = borderLayer.frame.size checkMarkLayer.frame.size = s
checkMarkRightLayer.frame.size = borderLayer.frame.size checkMarkLeftLayer.frame.size = s
checkMarkRightLayer.frame.size = s
checkMarkLeftLayer.path = checkMarkPathLeft.cgPath
checkMarkRightLayer.path = checkMarkPathRigth.cgPath
checkMarkLeftLayer.lineWidth = lineWidth
checkMarkRightLayer.lineWidth = lineWidth
borderLayer.borderWidth = borderLayerNormalBorderWidth borderLayer.borderWidth = borderLayerNormalBorderWidth
borderLayer.cornerRadius = borderLayerCornerRadius borderLayer.cornerRadius = borderLayerCornerRadius
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment