From 2eee432ac0786e6c90f02bf96bbf629637a7159a Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 17 Mar 2023 14:23:05 -0500 Subject: [PATCH] updated button for onClickPublisher Signed-off-by: Matt Bruce --- VDS/Components/Buttons/Button/ButtonBase.swift | 18 +++++++++++++++--- VDS/Publishers/UIControlPublisher.swift | 5 ++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index 3ced2661..61b628ce 100644 --- a/VDS/Components/Buttons/Button/ButtonBase.swift +++ b/VDS/Components/Buttons/Button/ButtonBase.swift @@ -29,6 +29,16 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab //-------------------------------------------------- public var subject = PassthroughSubject() public var subscribers = Set() + 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 } } - diff --git a/VDS/Publishers/UIControlPublisher.swift b/VDS/Publishers/UIControlPublisher.swift index dca48c3f..c7ccfa0c 100644 --- a/VDS/Publishers/UIControlPublisher.swift +++ b/VDS/Publishers/UIControlPublisher.swift @@ -23,8 +23,9 @@ public final class UIControlSubscription