refactored more on clickable
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
248caeb480
commit
334f9b798c
@ -43,7 +43,7 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
|
||||
var isHighlightAnimating = false
|
||||
open override var isHighlighted: Bool {
|
||||
didSet {
|
||||
if isHighlightAnimating == false && isClickable {
|
||||
if isHighlightAnimating == false && touchUpInsideCount > 0 {
|
||||
isHighlightAnimating = true
|
||||
UIView.animate(withDuration: 0.1, animations: { [weak self] in
|
||||
self?.updateView()
|
||||
|
||||
@ -64,7 +64,7 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
|
||||
|
||||
open override var isHighlighted: Bool {
|
||||
didSet {
|
||||
if isHighlightAnimating == false && isClickable {
|
||||
if isHighlightAnimating == false && touchUpInsideCount > 0 {
|
||||
isHighlightAnimating = true
|
||||
UIView.animate(withDuration: 0.1, animations: { [weak self] in
|
||||
self?.updateView()
|
||||
|
||||
@ -9,23 +9,19 @@ import Foundation
|
||||
import UIKit
|
||||
import Combine
|
||||
|
||||
public protocol Clickable where Self: UIControl {
|
||||
public protocol Clickable: Handlerable where Self: UIControl {
|
||||
var touchUpInsideCount: Int { get set }
|
||||
var onClickSubscriber: AnyCancellable? { get set }
|
||||
}
|
||||
|
||||
extension Clickable where Self: Handlerable {
|
||||
extension Clickable {
|
||||
public func addEvent(event: UIControl.Event, block: @escaping (Self)->()) {
|
||||
publisher(for: event)
|
||||
.sink(receiveValue: { c in
|
||||
block(c)
|
||||
}).store(in: &subscribers)
|
||||
}
|
||||
|
||||
internal var isClickable: Bool { return touchUpInsideCount > 0 }
|
||||
}
|
||||
|
||||
extension Clickable {
|
||||
public var onClick: ((Self) -> ())? {
|
||||
get { return nil }
|
||||
set {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user