updated button for onClickPublisher

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-03-17 14:23:05 -05:00
parent 2920559d84
commit 2eee432ac0
2 changed files with 19 additions and 4 deletions

View File

@ -29,6 +29,16 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
//--------------------------------------------------
public var subject = PassthroughSubject<Void, Never>()
public var subscribers = Set<AnyCancellable>()
open var onClickSubscriber: AnyCancellable? {
willSet {
if let onClickSubscriber {
onClickSubscriber.cancel()
}
}
didSet {
enabledHighlight = onClickSubscriber != nil
}
}
//--------------------------------------------------
// MARK: - Private Properties
@ -50,10 +60,13 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
open var userInfo = [String: Primitive]()
var isHighlightAnimating = false
internal var enabledHighlight: Bool = false
internal var isHighlightAnimating = false
open override var isHighlighted: Bool {
didSet {
if isHighlightAnimating == false {
if isHighlightAnimating == false && enabledHighlight {
isHighlightAnimating = true
UIView.animate(withDuration: 0.1, animations: { [weak self] in
self?.updateView()
@ -227,4 +240,3 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
}
}

View File

@ -23,8 +23,9 @@ public final class UIControlSubscription<SubscriberType: Subscriber, Control: UI
//allow highlight for VDS.Controls on "onClick" events
if let c = control as? VDS.Control, event == .touchUpInside {
c.enabledHighlight = true
} else if let c = control as? VDS.ButtonBase, event == .touchUpInside {
c.enabledHighlight = true
}
control.addTarget(self, action: #selector(eventHandler), for: event)
}
@ -41,6 +42,8 @@ public final class UIControlSubscription<SubscriberType: Subscriber, Control: UI
//remove highlight for VDS.Controls on "onClick" events
if let c = control as? VDS.Control, event == .touchUpInside {
c.enabledHighlight = false
} else if let c = control as? VDS.ButtonBase, event == .touchUpInside {
c.enabledHighlight = false
}
}