Merge branch 'feature/tilet' into 'develop'

fixed bug for enable hightlight

See merge request BPHV_MIPS/vds_ios!26
This commit is contained in:
Bruce, Matt R 2023-01-12 18:43:09 +00:00
commit 9872154c09
2 changed files with 37 additions and 4 deletions

View File

@ -98,7 +98,8 @@ open class CheckboxBase: Control, Accessable, DataTrackable, Errorable {
$0.translatesAutoresizingMaskIntoConstraints = false
}
//can't bind to @Proxy
open var isAnimated: Bool = true { didSet { didChange() }}
open override var isSelected: Bool { didSet { didChange() }}
open var labelText: String? { didSet { didChange() }}
@ -369,8 +370,6 @@ open class CheckboxBase: Control, Accessable, DataTrackable, Errorable {
self.shapeLayer = nil
}
selectorView.backgroundColor = backgroundColor
selectorView.layer.borderColor = borderColor.cgColor
selectorView.layer.cornerRadius = VDSFormControls.borderradius
selectorView.layer.borderWidth = VDSFormControls.widthBorder
@ -407,5 +406,30 @@ open class CheckboxBase: Control, Accessable, DataTrackable, Errorable {
shapeLayer.strokeEnd = isSelected ? 1 : 0
}
}
shapeLayer?.removeAllAnimations()
if isAnimated {
let animateStrokeEnd = CABasicAnimation(keyPath: "strokeEnd")
animateStrokeEnd.timingFunction = CAMediaTimingFunction(name: .linear)
animateStrokeEnd.duration = 0.3
animateStrokeEnd.fillMode = .both
animateStrokeEnd.isRemovedOnCompletion = false
animateStrokeEnd.fromValue = !isSelected ? 1 : 0
animateStrokeEnd.toValue = isSelected ? 1 : 0
self.shapeLayer?.add(animateStrokeEnd, forKey: "strokeEnd")
UIView.animate(withDuration: 0.2, delay: 0.1, options: .curveEaseOut, animations: {
self.selectorView.backgroundColor = backgroundColor
self.selectorView.layer.borderColor = borderColor.cgColor
})
} else {
CATransaction.withDisabledAnimations {
self.shapeLayer?.strokeEnd = isSelected ? 1 : 0
}
selectorView.backgroundColor = backgroundColor
selectorView.layer.borderColor = borderColor.cgColor
}
}
}

View File

@ -13,10 +13,12 @@ import Combine
public final class UIControlSubscription<SubscriberType: Subscriber, Control: UIControl>: Subscription where SubscriberType.Input == Control {
private var subscriber: SubscriberType?
private let control: Control
private let event: UIControl.Event
public init(subscriber: SubscriberType, control: Control, event: UIControl.Event) {
self.subscriber = subscriber
self.control = control
self.event = event
//allow highlight for VDS.Controls on "onClick" events
if let c = control as? VDS.Control, event == .touchUpInside {
@ -34,6 +36,13 @@ public final class UIControlSubscription<SubscriberType: Subscriber, Control: UI
public func cancel() {
subscriber = nil
}
deinit {
//remove highlight for VDS.Controls on "onClick" events
if let c = control as? VDS.Control, event == .touchUpInside {
c.enabledHighlight = false
}
}
@objc private func eventHandler() {
_ = subscriber?.receive(control)