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
|
var isHighlightAnimating = false
|
||||||
open override var isHighlighted: Bool {
|
open override var isHighlighted: Bool {
|
||||||
didSet {
|
didSet {
|
||||||
if isHighlightAnimating == false && isClickable {
|
if isHighlightAnimating == false && touchUpInsideCount > 0 {
|
||||||
isHighlightAnimating = true
|
isHighlightAnimating = true
|
||||||
UIView.animate(withDuration: 0.1, animations: { [weak self] in
|
UIView.animate(withDuration: 0.1, animations: { [weak self] in
|
||||||
self?.updateView()
|
self?.updateView()
|
||||||
|
|||||||
@ -64,7 +64,7 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
|
|||||||
|
|
||||||
open override var isHighlighted: Bool {
|
open override var isHighlighted: Bool {
|
||||||
didSet {
|
didSet {
|
||||||
if isHighlightAnimating == false && isClickable {
|
if isHighlightAnimating == false && touchUpInsideCount > 0 {
|
||||||
isHighlightAnimating = true
|
isHighlightAnimating = true
|
||||||
UIView.animate(withDuration: 0.1, animations: { [weak self] in
|
UIView.animate(withDuration: 0.1, animations: { [weak self] in
|
||||||
self?.updateView()
|
self?.updateView()
|
||||||
|
|||||||
@ -9,12 +9,12 @@ import Foundation
|
|||||||
import UIKit
|
import UIKit
|
||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
public protocol Clickable where Self: UIControl {
|
public protocol Clickable: Handlerable where Self: UIControl {
|
||||||
var touchUpInsideCount: Int { get set }
|
var touchUpInsideCount: Int { get set }
|
||||||
var onClickSubscriber: AnyCancellable? { get set }
|
var onClickSubscriber: AnyCancellable? { get set }
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Clickable where Self: Handlerable {
|
extension Clickable {
|
||||||
public func addEvent(event: UIControl.Event, block: @escaping (Self)->()) {
|
public func addEvent(event: UIControl.Event, block: @escaping (Self)->()) {
|
||||||
publisher(for: event)
|
publisher(for: event)
|
||||||
.sink(receiveValue: { c in
|
.sink(receiveValue: { c in
|
||||||
@ -22,10 +22,6 @@ extension Clickable where Self: Handlerable {
|
|||||||
}).store(in: &subscribers)
|
}).store(in: &subscribers)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal var isClickable: Bool { return touchUpInsideCount > 0 }
|
|
||||||
}
|
|
||||||
|
|
||||||
extension Clickable {
|
|
||||||
public var onClick: ((Self) -> ())? {
|
public var onClick: ((Self) -> ())? {
|
||||||
get { return nil }
|
get { return nil }
|
||||||
set {
|
set {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user