updated shapelayer
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
d8a55d87bc
commit
7256f0971c
@ -100,16 +100,16 @@ import Combine
|
||||
private var mainStackView: UIStackView = {
|
||||
let stackView = UIStackView()
|
||||
stackView.translatesAutoresizingMaskIntoConstraints = false
|
||||
stackView.alignment = .top
|
||||
stackView.axis = .vertical
|
||||
stackView.distribution = .fill
|
||||
return stackView
|
||||
}()
|
||||
|
||||
private var checkBoxStackView: UIStackView = {
|
||||
private var checkboxStackView: UIStackView = {
|
||||
let stackView = UIStackView()
|
||||
stackView.translatesAutoresizingMaskIntoConstraints = false
|
||||
stackView.alignment = .top
|
||||
stackView.axis = .horizontal
|
||||
stackView.distribution = .fillProportionally
|
||||
return stackView
|
||||
}()
|
||||
|
||||
@ -117,8 +117,6 @@ import Combine
|
||||
let stackView = UIStackView()
|
||||
stackView.translatesAutoresizingMaskIntoConstraints = false
|
||||
stackView.axis = .vertical
|
||||
stackView.distribution = .fillProportionally
|
||||
stackView.spacing = 5
|
||||
return stackView
|
||||
}()
|
||||
|
||||
@ -242,13 +240,18 @@ import Combine
|
||||
|
||||
public override func setupView() {
|
||||
super.setupView()
|
||||
self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(VDSCheckbox.toggleAndAction)))
|
||||
|
||||
isAccessibilityElement = true
|
||||
accessibilityTraits = .button
|
||||
addSubview(mainStackView)
|
||||
|
||||
mainStackView.addArrangedSubview(checkBoxStackView)
|
||||
checkBoxStackView.addArrangedSubview(checkboxView)
|
||||
mainStackView.addArrangedSubview(checkboxStackView)
|
||||
mainStackView.addArrangedSubview(errorLabel)
|
||||
checkboxStackView.addArrangedSubview(checkboxView)
|
||||
checkboxStackView.addArrangedSubview(checkboxLabelStackView)
|
||||
checkboxLabelStackView.addArrangedSubview(primaryLabel)
|
||||
checkboxLabelStackView.addArrangedSubview(secondaryLabel)
|
||||
|
||||
checkboxHeightConstraint = checkboxView.heightAnchor.constraint(equalToConstant: checkboxSize.height)
|
||||
checkboxHeightConstraint?.isActive = true
|
||||
@ -272,10 +275,10 @@ import Combine
|
||||
let background = getCheckboxBackgroundColor(for: viewModel.disabled, surface: viewModel.surface)
|
||||
let border = getCheckboxBorderColor(for: viewModel.disabled, surface: viewModel.surface)
|
||||
let checkColor = getCheckboxCheckColor(for: viewModel.disabled, surface: viewModel.surface)
|
||||
|
||||
checkboxView.backgroundColor = viewModel.on ? background.on : background.off
|
||||
let backgroundColor = viewModel.on ? background.on : background.off
|
||||
checkboxView.backgroundColor = backgroundColor
|
||||
checkboxView.borderColor = viewModel.on ? border.on : border.off
|
||||
checkboxView.checkColor = checkColor
|
||||
checkboxView.checkColor = viewModel.on ? checkColor : backgroundColor
|
||||
checkboxView.isSelected = viewModel.on
|
||||
}
|
||||
|
||||
@ -284,41 +287,39 @@ import Combine
|
||||
//deal with labels
|
||||
if model.shouldShowLabels {
|
||||
//add the stackview to hold the 2 labels
|
||||
if checkBoxStackView.subviews.contains(checkboxLabelStackView) == false {
|
||||
checkBoxStackView.addArrangedSubview(checkboxLabelStackView)
|
||||
}
|
||||
//top label
|
||||
if let labelModel = viewModel.labelModel {
|
||||
primaryLabel.set(with: labelModel)
|
||||
if checkboxLabelStackView.subviews.contains(primaryLabel) == false {
|
||||
checkboxLabelStackView.insertArrangedSubview(primaryLabel, at: 0)
|
||||
}
|
||||
primaryLabel.isHidden = false
|
||||
} else {
|
||||
primaryLabel.removeFromSuperview()
|
||||
primaryLabel.isHidden = true
|
||||
}
|
||||
|
||||
//bottom label
|
||||
if let childModel = viewModel.childModel {
|
||||
secondaryLabel.set(with: childModel)
|
||||
if checkboxLabelStackView.subviews.contains(secondaryLabel) == false {
|
||||
checkboxLabelStackView.addArrangedSubview(secondaryLabel)
|
||||
}
|
||||
secondaryLabel.isHidden = false
|
||||
} else {
|
||||
secondaryLabel.removeFromSuperview()
|
||||
secondaryLabel.isHidden = true
|
||||
}
|
||||
checkboxStackView.spacing = 12
|
||||
checkboxLabelStackView.spacing = 4
|
||||
checkboxLabelStackView.isHidden = false
|
||||
|
||||
} else {
|
||||
checkboxLabelStackView.removeFromSuperview()
|
||||
checkboxStackView.spacing = 0
|
||||
checkboxLabelStackView.spacing = 0
|
||||
checkboxLabelStackView.isHidden = true
|
||||
}
|
||||
|
||||
//either add/remove the error from the main stack
|
||||
if let errorModel = model.errorModel, model.shouldShowError {
|
||||
errorLabel.set(with: errorModel)
|
||||
if mainStackView.subviews.contains(errorLabel) == false {
|
||||
mainStackView.spacing = 12
|
||||
mainStackView.addArrangedSubview(errorLabel)
|
||||
}
|
||||
mainStackView.spacing = 8
|
||||
errorLabel.isHidden = false
|
||||
} else {
|
||||
mainStackView.spacing = 0
|
||||
errorLabel.removeFromSuperview()
|
||||
errorLabel.isHidden = true
|
||||
}
|
||||
|
||||
}
|
||||
@ -360,8 +361,8 @@ import Combine
|
||||
//--------------------------------------------------
|
||||
// MARK: - UIResponder
|
||||
//--------------------------------------------------
|
||||
|
||||
public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
|
||||
sendActions(for: .touchUpInside)
|
||||
}
|
||||
|
||||
@ -389,7 +390,13 @@ import Combine
|
||||
public var checkColor: UIColor = .white
|
||||
public var isSelected: Bool = false {
|
||||
didSet {
|
||||
drawShapeLayer()
|
||||
if oldValue != isSelected {
|
||||
if let shapeLayer = shapeLayer, let sublayers = layer.sublayers, sublayers.contains(shapeLayer) {
|
||||
shapeLayer.removeFromSuperlayer()
|
||||
self.shapeLayer = nil
|
||||
}
|
||||
drawShapeLayer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -402,7 +409,7 @@ import Combine
|
||||
layer.cornerRadius = 2.0
|
||||
shapeLayer?.strokeColor = checkColor.cgColor
|
||||
|
||||
guard let path = try? checkMarkPath() else { return }
|
||||
guard let path = try? checkMarkPath(), shapeLayer == nil else { return }
|
||||
|
||||
if shapeLayer == nil {
|
||||
let shapeLayer = CAShapeLayer()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user