Merge branch 'feature/checkbox_update' into 'develop'
Improved checkbox. See merge request BPHV_MIPS/mvm_core_ui!144
This commit is contained in:
commit
fc098b85e2
@ -80,8 +80,10 @@ import MVMCore
|
|||||||
/// Width of the check mark.
|
/// Width of the check mark.
|
||||||
public var checkWidth: CGFloat = 2 {
|
public var checkWidth: CGFloat = 2 {
|
||||||
didSet {
|
didSet {
|
||||||
CATransaction.withDisabledAnimations {
|
if let shapeLayer = shapeLayer {
|
||||||
shapeLayer?.lineWidth = checkWidth
|
CATransaction.withDisabledAnimations {
|
||||||
|
shapeLayer.lineWidth = checkWidth
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,8 +91,10 @@ import MVMCore
|
|||||||
/// Color of the check mark.
|
/// Color of the check mark.
|
||||||
public var checkColor: UIColor = .black {
|
public var checkColor: UIColor = .black {
|
||||||
didSet {
|
didSet {
|
||||||
CATransaction.withDisabledAnimations {
|
if let shapeLayer = shapeLayer {
|
||||||
shapeLayer?.strokeColor = checkColor.cgColor
|
CATransaction.withDisabledAnimations {
|
||||||
|
shapeLayer.strokeColor = checkColor.cgColor
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,8 +113,11 @@ import MVMCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The represented state of the Checkbox.
|
/**
|
||||||
/// If updateSelectionOnly = true, then this will behave only as a stored property.
|
The represented state of the Checkbox.
|
||||||
|
|
||||||
|
Setting updateSelectionOnly to true bypasses the animation logic inherent with setting this property.
|
||||||
|
*/
|
||||||
override open var isSelected: Bool {
|
override open var isSelected: Bool {
|
||||||
didSet {
|
didSet {
|
||||||
if !updateSelectionOnly {
|
if !updateSelectionOnly {
|
||||||
@ -181,7 +188,7 @@ import MVMCore
|
|||||||
layer.borderColor = borderColor.cgColor
|
layer.borderColor = borderColor.cgColor
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setupView() {
|
open func setupView() {
|
||||||
|
|
||||||
isUserInteractionEnabled = true
|
isUserInteractionEnabled = true
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
translatesAutoresizingMaskIntoConstraints = false
|
||||||
@ -225,7 +232,7 @@ import MVMCore
|
|||||||
shapeLayer.strokeColor = checkColor.cgColor
|
shapeLayer.strokeColor = checkColor.cgColor
|
||||||
shapeLayer.fillColor = UIColor.clear.cgColor
|
shapeLayer.fillColor = UIColor.clear.cgColor
|
||||||
shapeLayer.path = checkMarkPath()
|
shapeLayer.path = checkMarkPath()
|
||||||
shapeLayer.lineJoin = .bevel
|
shapeLayer.lineJoin = .miter
|
||||||
shapeLayer.lineWidth = checkWidth
|
shapeLayer.lineWidth = checkWidth
|
||||||
|
|
||||||
CATransaction.withDisabledAnimations {
|
CATransaction.withDisabledAnimations {
|
||||||
@ -237,7 +244,7 @@ import MVMCore
|
|||||||
/// Returns a UIBezierPath detailing the path of a checkmark
|
/// Returns a UIBezierPath detailing the path of a checkmark
|
||||||
func checkMarkPath() -> CGPath {
|
func checkMarkPath() -> CGPath {
|
||||||
|
|
||||||
let sideLength = bounds.size.height
|
let sideLength = max(bounds.size.height, bounds.size.width)
|
||||||
let startPoint = CGPoint(x: 0.33871 * sideLength, y: 0.53225 * sideLength)
|
let startPoint = CGPoint(x: 0.33871 * sideLength, y: 0.53225 * sideLength)
|
||||||
let pivotOffSet = CGPoint(x: 0.46774 * sideLength, y: 0.64516 * sideLength)
|
let pivotOffSet = CGPoint(x: 0.46774 * sideLength, y: 0.64516 * sideLength)
|
||||||
let endOffset = CGPoint(x: 0.66935 * sideLength , y: 0.37097 * sideLength)
|
let endOffset = CGPoint(x: 0.66935 * sideLength , y: 0.37097 * sideLength)
|
||||||
@ -336,16 +343,27 @@ import MVMCore
|
|||||||
|
|
||||||
open func reset() {
|
open func reset() {
|
||||||
|
|
||||||
backgroundColor = nil
|
shapeLayer?.removeAllAnimations()
|
||||||
|
shapeLayer?.removeFromSuperlayer()
|
||||||
shapeLayer = nil
|
shapeLayer = nil
|
||||||
|
backgroundColor = nil
|
||||||
|
borderColor = .black
|
||||||
|
borderWidth = 1.0
|
||||||
|
checkColor = .black
|
||||||
|
checkWidth = 2.0
|
||||||
|
updateSelectionOnly = true
|
||||||
isSelected = false
|
isSelected = false
|
||||||
|
updateSelectionOnly = false
|
||||||
}
|
}
|
||||||
|
|
||||||
open func setAsMolecule() {
|
open func setAsMolecule() {
|
||||||
setupView()
|
setupView()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func updateView(_ size: CGFloat) { }
|
public func updateView(_ size: CGFloat) {
|
||||||
|
|
||||||
|
layoutIfNeeded()
|
||||||
|
}
|
||||||
|
|
||||||
public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||||
self.delegateObject = delegateObject
|
self.delegateObject = delegateObject
|
||||||
|
|||||||
@ -38,6 +38,7 @@
|
|||||||
var checkboxTopConstraint: NSLayoutConstraint?
|
var checkboxTopConstraint: NSLayoutConstraint?
|
||||||
var checkboxBottomConstraint: NSLayoutConstraint?
|
var checkboxBottomConstraint: NSLayoutConstraint?
|
||||||
var checkboxCenterYConstraint: NSLayoutConstraint?
|
var checkboxCenterYConstraint: NSLayoutConstraint?
|
||||||
|
var centerLabelCheckboxConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Life Cycle
|
// MARK: - Life Cycle
|
||||||
@ -62,14 +63,8 @@
|
|||||||
checkboxHeightConstraint?.isActive = true
|
checkboxHeightConstraint?.isActive = true
|
||||||
|
|
||||||
checkbox.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true
|
checkbox.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true
|
||||||
|
checkbox.topAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.topAnchor).isActive = true
|
||||||
let generalTop = checkbox.topAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.topAnchor)
|
layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: checkbox.bottomAnchor).isActive = true
|
||||||
generalTop.priority = UILayoutPriority(800)
|
|
||||||
generalTop.isActive = true
|
|
||||||
|
|
||||||
let generalBottom = checkbox.bottomAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.bottomAnchor)
|
|
||||||
generalBottom.priority = UILayoutPriority(800)
|
|
||||||
generalBottom.isActive = true
|
|
||||||
|
|
||||||
let checboxBottom = checkbox.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor)
|
let checboxBottom = checkbox.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor)
|
||||||
checboxBottom.priority = UILayoutPriority(249)
|
checboxBottom.priority = UILayoutPriority(249)
|
||||||
@ -79,20 +74,17 @@
|
|||||||
checkboxBottomConstraint = layoutMarginsGuide.bottomAnchor.constraint(equalTo: checkbox.bottomAnchor)
|
checkboxBottomConstraint = layoutMarginsGuide.bottomAnchor.constraint(equalTo: checkbox.bottomAnchor)
|
||||||
checkboxTopConstraint = checkbox.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor)
|
checkboxTopConstraint = checkbox.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor)
|
||||||
checkboxCenterYConstraint = checkbox.centerYAnchor.constraint(equalTo: centerYAnchor)
|
checkboxCenterYConstraint = checkbox.centerYAnchor.constraint(equalTo: centerYAnchor)
|
||||||
|
centerLabelCheckboxConstraint = label.centerYAnchor.constraint(equalTo: checkbox.centerYAnchor)
|
||||||
|
|
||||||
label.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
|
label.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
|
||||||
layoutMarginsGuide.trailingAnchor.constraint(equalTo: label.trailingAnchor).isActive = true
|
layoutMarginsGuide.trailingAnchor.constraint(equalTo: label.trailingAnchor).isActive = true
|
||||||
label.leadingAnchor.constraint(equalTo: checkbox.trailingAnchor, constant: PaddingTwo).isActive = true
|
label.leadingAnchor.constraint(equalTo: checkbox.trailingAnchor, constant: PaddingTwo).isActive = true
|
||||||
|
|
||||||
let bottomLabelConstraint = layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: label.bottomAnchor)
|
layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: label.bottomAnchor).isActive = true
|
||||||
bottomLabelConstraint.priority = UILayoutPriority(500)
|
let bottomLabelConstraint = layoutMarginsGuide.bottomAnchor.constraint(equalTo: label.bottomAnchor)
|
||||||
|
bottomLabelConstraint.priority = UILayoutPriority(249)
|
||||||
bottomLabelConstraint.isActive = true
|
bottomLabelConstraint.isActive = true
|
||||||
|
|
||||||
// layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: label.bottomAnchor).isActive = true
|
|
||||||
// let labelBottom = label.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor)
|
|
||||||
// labelBottom.priority = UILayoutPriority(249)
|
|
||||||
// labelBottom.isActive = true
|
|
||||||
|
|
||||||
alignCheckbox(.center)
|
alignCheckbox(.center)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,19 +122,22 @@
|
|||||||
|
|
||||||
switch position {
|
switch position {
|
||||||
case .center:
|
case .center:
|
||||||
checkboxCenterYConstraint?.isActive = true
|
|
||||||
checkboxBottomConstraint?.isActive = false
|
checkboxBottomConstraint?.isActive = false
|
||||||
checkboxTopConstraint?.isActive = false
|
checkboxTopConstraint?.isActive = false
|
||||||
|
checkboxCenterYConstraint?.isActive = true
|
||||||
|
centerLabelCheckboxConstraint?.isActive = true
|
||||||
|
|
||||||
case .top:
|
case .top:
|
||||||
checkboxBottomConstraint?.isActive = false
|
checkboxBottomConstraint?.isActive = false
|
||||||
checkboxTopConstraint?.isActive = true
|
checkboxTopConstraint?.isActive = true
|
||||||
checkboxCenterYConstraint?.isActive = false
|
checkboxCenterYConstraint?.isActive = false
|
||||||
|
centerLabelCheckboxConstraint?.isActive = false
|
||||||
|
|
||||||
case .bottom:
|
case .bottom:
|
||||||
checkboxBottomConstraint?.isActive = true
|
checkboxBottomConstraint?.isActive = true
|
||||||
checkboxTopConstraint?.isActive = false
|
checkboxTopConstraint?.isActive = false
|
||||||
checkboxCenterYConstraint?.isActive = false
|
checkboxCenterYConstraint?.isActive = false
|
||||||
|
centerLabelCheckboxConstraint?.isActive = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,6 +171,11 @@ extension CheckboxWithLabelView {
|
|||||||
|
|
||||||
open override func resetConstraints() {
|
open override func resetConstraints() {
|
||||||
super.resetConstraints()
|
super.resetConstraints()
|
||||||
|
|
||||||
|
checkboxCenterYConstraint?.isActive = false
|
||||||
|
checkboxBottomConstraint?.isActive = false
|
||||||
|
checkboxTopConstraint?.isActive = false
|
||||||
|
centerLabelCheckboxConstraint?.isActive = false
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func reset() {
|
open override func reset() {
|
||||||
|
|||||||
@ -39,10 +39,10 @@
|
|||||||
@"textField" : MFTextField.class,
|
@"textField" : MFTextField.class,
|
||||||
@"digitTextField" : MFDigitTextField.class,
|
@"digitTextField" : MFDigitTextField.class,
|
||||||
@"checkbox" : Checkbox.class,
|
@"checkbox" : Checkbox.class,
|
||||||
|
@"checkboxWithLabelView" : CheckboxWithLabelView.class,
|
||||||
@"cornerLabels" : CornerLabels.class,
|
@"cornerLabels" : CornerLabels.class,
|
||||||
@"progressBar": ProgressBar.class,
|
@"progressBar": ProgressBar.class,
|
||||||
@"multiProgressBar": MultiProgress.class,
|
@"multiProgressBar": MultiProgress.class,
|
||||||
@"checkboxWithLabelView": CheckboxWithLabelView.class,
|
|
||||||
@"listItem": MoleculeTableViewCell.class,
|
@"listItem": MoleculeTableViewCell.class,
|
||||||
@"accordionListItem": AccordionMoleculeTableViewCell.class,
|
@"accordionListItem": AccordionMoleculeTableViewCell.class,
|
||||||
@"switch": MVMCoreUISwitch.class,
|
@"switch": MVMCoreUISwitch.class,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user