updated for maintaining a clickable count
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
f164429ece
commit
248caeb480
@ -17,15 +17,12 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
|
||||
//--------------------------------------------------
|
||||
public var subject = PassthroughSubject<Void, Never>()
|
||||
public var subscribers = Set<AnyCancellable>()
|
||||
internal var onClickSubscriber: AnyCancellable? {
|
||||
public var onClickSubscriber: AnyCancellable? {
|
||||
willSet {
|
||||
if let onClickSubscriber {
|
||||
onClickSubscriber.cancel()
|
||||
}
|
||||
}
|
||||
didSet {
|
||||
enabledHighlight = onClickSubscriber != nil
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -41,12 +38,12 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
|
||||
|
||||
open override var isSelected: Bool { didSet { didChange() } }
|
||||
|
||||
internal var enabledHighlight: Bool = false
|
||||
public var touchUpInsideCount: Int = 0
|
||||
|
||||
var isHighlightAnimating = false
|
||||
open override var isHighlighted: Bool {
|
||||
didSet {
|
||||
if isHighlightAnimating == false && enabledHighlight {
|
||||
if isHighlightAnimating == false && isClickable {
|
||||
isHighlightAnimating = true
|
||||
UIView.animate(withDuration: 0.1, animations: { [weak self] in
|
||||
self?.updateView()
|
||||
|
||||
@ -19,6 +19,7 @@ public protocol Buttonable: UIControl, Surfaceable, Disabling {
|
||||
|
||||
@objc(VDSButtonBase)
|
||||
open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettable, UserInfoable, Clickable {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Configuration Properties
|
||||
//--------------------------------------------------
|
||||
@ -29,15 +30,12 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
|
||||
//--------------------------------------------------
|
||||
public var subject = PassthroughSubject<Void, Never>()
|
||||
public var subscribers = Set<AnyCancellable>()
|
||||
internal var onClickSubscriber: AnyCancellable? {
|
||||
public var onClickSubscriber: AnyCancellable? {
|
||||
willSet {
|
||||
if let onClickSubscriber {
|
||||
onClickSubscriber.cancel()
|
||||
}
|
||||
}
|
||||
didSet {
|
||||
enabledHighlight = onClickSubscriber != nil
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -60,13 +58,13 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
|
||||
|
||||
open var userInfo = [String: Primitive]()
|
||||
|
||||
internal var enabledHighlight: Bool = false
|
||||
public var touchUpInsideCount: Int = 0
|
||||
|
||||
internal var isHighlightAnimating = false
|
||||
|
||||
open override var isHighlighted: Bool {
|
||||
didSet {
|
||||
if isHighlightAnimating == false && enabledHighlight {
|
||||
if isHighlightAnimating == false && isClickable {
|
||||
isHighlightAnimating = true
|
||||
UIView.animate(withDuration: 0.1, animations: { [weak self] in
|
||||
self?.updateView()
|
||||
|
||||
@ -172,7 +172,6 @@ open class EntryField: Control {
|
||||
open override func setup() {
|
||||
super.setup()
|
||||
|
||||
enabledHighlight = false
|
||||
isAccessibilityElement = true
|
||||
accessibilityTraits = .button
|
||||
addSubview(stackView)
|
||||
|
||||
@ -63,7 +63,7 @@ open class Tilelet: TileContainer {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
internal override var onClickSubscriber: AnyCancellable? {
|
||||
public override var onClickSubscriber: AnyCancellable? {
|
||||
didSet {
|
||||
isAccessibilityElement = onClickSubscriber != nil
|
||||
}
|
||||
|
||||
@ -7,8 +7,12 @@
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
import Combine
|
||||
|
||||
public protocol Clickable where Self: UIControl {}
|
||||
public protocol Clickable where Self: UIControl {
|
||||
var touchUpInsideCount: Int { get set }
|
||||
var onClickSubscriber: AnyCancellable? { get set }
|
||||
}
|
||||
|
||||
extension Clickable where Self: Handlerable {
|
||||
public func addEvent(event: UIControl.Event, block: @escaping (Self)->()) {
|
||||
@ -17,25 +21,11 @@ extension Clickable where Self: Handlerable {
|
||||
block(c)
|
||||
}).store(in: &subscribers)
|
||||
}
|
||||
|
||||
internal var isClickable: Bool { return touchUpInsideCount > 0 }
|
||||
}
|
||||
|
||||
extension Clickable where Self: ButtonBase {
|
||||
public var onClick: ((Self) -> ())? {
|
||||
get { return nil }
|
||||
set {
|
||||
if let newValue {
|
||||
onClickSubscriber = publisher(for: .touchUpInside)
|
||||
.sink { c in
|
||||
newValue(c)
|
||||
}
|
||||
} else {
|
||||
onClickSubscriber = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Clickable where Self: Control {
|
||||
extension Clickable {
|
||||
public var onClick: ((Self) -> ())? {
|
||||
get { return nil }
|
||||
set {
|
||||
@ -45,6 +35,7 @@ extension Clickable where Self: Control {
|
||||
newValue(c)
|
||||
}
|
||||
} else {
|
||||
onClickSubscriber?.cancel()
|
||||
onClickSubscriber = nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,10 +21,8 @@ public final class UIControlSubscription<SubscriberType: Subscriber, Control: UI
|
||||
self.event = event
|
||||
|
||||
//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
|
||||
if let c = control as? Clickable, event == .touchUpInside {
|
||||
c.touchUpInsideCount += 1
|
||||
}
|
||||
control.addTarget(self, action: #selector(eventHandler), for: event)
|
||||
}
|
||||
@ -40,10 +38,8 @@ public final class UIControlSubscription<SubscriberType: Subscriber, Control: UI
|
||||
|
||||
deinit {
|
||||
//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
|
||||
if let c = control as? Clickable, event == .touchUpInside, c.touchUpInsideCount > 0 {
|
||||
c.touchUpInsideCount -= 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user