refactored clickable
removed old clickable code Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
ac8d4e707b
commit
94d44c5d54
@ -10,7 +10,7 @@ import UIKit
|
||||
import Combine
|
||||
|
||||
@objc(VDSControl)
|
||||
open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoable {
|
||||
open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoable, Clickable {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Combine Properties
|
||||
|
||||
@ -17,7 +17,7 @@ public enum ButtonSize: String, CaseIterable {
|
||||
}
|
||||
|
||||
@objc(VDSButton)
|
||||
open class Button: ButtonBase, Useable, Clickable {
|
||||
open class Button: ButtonBase, Useable {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Private Properties
|
||||
@ -30,8 +30,6 @@ open class Button: ButtonBase, Useable, Clickable {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
open var onClick: ((Button) -> ())? { didSet { setupOnClick() } }
|
||||
|
||||
open override var availableSizes: [ButtonSize] { [.large, .small] }
|
||||
|
||||
open var use: Use = .primary { didSet { didChange() }}
|
||||
|
||||
@ -18,7 +18,7 @@ public protocol Buttonable: UIControl, Surfaceable, Disabling {
|
||||
}
|
||||
|
||||
@objc(VDSButtonBase)
|
||||
open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettable, UserInfoable {
|
||||
open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettable, UserInfoable, Clickable {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Configuration Properties
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -12,7 +12,7 @@ import VDSFormControlsTokens
|
||||
import Combine
|
||||
|
||||
@objc(VDSTextLink)
|
||||
open class TextLink: ButtonBase, Clickable {
|
||||
open class TextLink: ButtonBase {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Private Properties
|
||||
@ -22,8 +22,6 @@ open class TextLink: ButtonBase, Clickable {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
open var onClick: ((TextLink) -> ())? { didSet { setupOnClick() } }
|
||||
|
||||
open var size: ButtonSize = .large { didSet { didChange() }}
|
||||
|
||||
open override var availableSizes: [ButtonSize] { [.large, .small] }
|
||||
|
||||
@ -12,7 +12,7 @@ import VDSFormControlsTokens
|
||||
import Combine
|
||||
|
||||
@objc(VDSTextLinkCaret)
|
||||
open class TextLinkCaret: ButtonBase, Clickable {
|
||||
open class TextLinkCaret: ButtonBase {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Enums
|
||||
@ -24,8 +24,6 @@ open class TextLinkCaret: ButtonBase, Clickable {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Private Properties
|
||||
//--------------------------------------------------
|
||||
open var onClick: ((TextLinkCaret) -> ())? { didSet { setupOnClick() } }
|
||||
|
||||
open override var textStyle: TextStyle {
|
||||
TextStyle.boldBodyLarge
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ import Combine
|
||||
|
||||
/// Checkboxes are a multi-select component through which a customer indicates a choice. If a binary choice, the component is a checkbox. If the choice has multiple options, the component is a ``CheckboxGroup``.
|
||||
@objc(VDSCheckboxBase)
|
||||
open class Checkbox: Control, Errorable, Clickable {
|
||||
open class Checkbox: Control, Errorable {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
@ -63,8 +63,6 @@ open class Checkbox: Control, Errorable, Clickable {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
open var onClick: ((Checkbox) -> ())? { didSet { setupOnClick() }}
|
||||
|
||||
open var label = Label().with {
|
||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
$0.textPosition = .left
|
||||
|
||||
@ -12,7 +12,7 @@ import VDSFormControlsTokens
|
||||
import Combine
|
||||
|
||||
@objc(VDSRadioBox)
|
||||
open class RadioBox: Control, Clickable {
|
||||
open class RadioBox: Control {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
@ -56,8 +56,6 @@ open class RadioBox: Control, Clickable {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
open var onClick: ((RadioBox) -> ())? { didSet { setupOnClick() }}
|
||||
|
||||
open var textLabel = Label().with {
|
||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
$0.textPosition = .left
|
||||
|
||||
@ -11,7 +11,7 @@ import VDSColorTokens
|
||||
import VDSFormControlsTokens
|
||||
|
||||
@objc(VDSRadioButton)
|
||||
open class RadioButton: Control, Errorable, Clickable {
|
||||
open class RadioButton: Control, Errorable {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
@ -61,8 +61,6 @@ open class RadioButton: Control, Errorable, Clickable {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
open var onClick: ((RadioButton) -> ())? { didSet { setupOnClick() } }
|
||||
|
||||
open var label = Label().with {
|
||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||
$0.textPosition = .left
|
||||
|
||||
@ -12,7 +12,7 @@ import VDSFormControlsTokens
|
||||
import Combine
|
||||
|
||||
@objc(VDSRadioSwatch)
|
||||
open class RadioSwatch: Control, Clickable {
|
||||
open class RadioSwatch: Control {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
@ -31,9 +31,7 @@ open class RadioSwatch: Control, Clickable {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
open var onClick: ((RadioSwatch) -> ())? { didSet { setupOnClick() } }
|
||||
|
||||
//--------------------------------------------------
|
||||
public var selectorView = UIView().with {
|
||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||
}
|
||||
|
||||
@ -11,12 +11,7 @@ import VDSFormControlsTokens
|
||||
import UIKit
|
||||
|
||||
@objc(VDSTileContainer)
|
||||
open class TileContainer: TileContainerBase, Clickable {
|
||||
public var onClick: ((TileContainer) -> ())? { didSet { setupOnClick() } }
|
||||
}
|
||||
|
||||
@objc(VDSTileContainerBase)
|
||||
open class TileContainerBase: Control {
|
||||
open class TileContainer: Control {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
@ -315,13 +310,13 @@ open class TileContainerBase: Control {
|
||||
}
|
||||
}
|
||||
|
||||
extension TileContainerBase {
|
||||
extension TileContainer {
|
||||
class BackgroundColorConfiguration: ObjectColorable {
|
||||
typealias ObjectType = TileContainerBase
|
||||
typealias ObjectType = TileContainer
|
||||
|
||||
required init() { }
|
||||
|
||||
func getColor(_ object: TileContainerBase) -> UIColor {
|
||||
func getColor(_ object: TileContainer) -> UIColor {
|
||||
switch object.color {
|
||||
|
||||
case .white:
|
||||
|
||||
@ -12,7 +12,7 @@ import UIKit
|
||||
import Combine
|
||||
|
||||
@objc(VDSTilelet)
|
||||
open class Tilelet: TileContainerBase, Clickable {
|
||||
open class Tilelet: TileContainer {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Enums
|
||||
@ -62,9 +62,7 @@ open class Tilelet: TileContainerBase, Clickable {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Properties
|
||||
//--------------------------------------------------
|
||||
open var onClick: ((Tilelet) -> ())? { didSet { setupOnClick() } }
|
||||
|
||||
//--------------------------------------------------
|
||||
internal override var onClickSubscriber: AnyCancellable? {
|
||||
didSet {
|
||||
isAccessibilityElement = onClickSubscriber != nil
|
||||
|
||||
@ -18,7 +18,7 @@ import Combine
|
||||
Knob: The circular indicator that slides on the container.
|
||||
*/
|
||||
@objc(VDSToggle)
|
||||
open class Toggle: Control, Clickable {
|
||||
open class Toggle: Control {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Enums
|
||||
//--------------------------------------------------
|
||||
@ -70,9 +70,7 @@ open class Toggle: Control, Clickable {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Configuration Properties
|
||||
//--------------------------------------------------
|
||||
open var onClick: ((Toggle) -> ())? { didSet { setupOnClick() } }
|
||||
|
||||
//--------------------------------------------------
|
||||
// Sizes are from InVision design specs.
|
||||
public let toggleSize = CGSize(width: 52, height: 24)
|
||||
public let toggleContainerSize = CGSize(width: 52, height: 44)
|
||||
|
||||
@ -8,10 +8,7 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
public protocol Clickable where Self: UIControl {
|
||||
var onClick: ((Self) -> ())? { get set }
|
||||
func setupOnClick()
|
||||
}
|
||||
public protocol Clickable where Self: UIControl {}
|
||||
|
||||
extension Clickable where Self: Handlerable {
|
||||
public func addEvent(event: UIControl.Event, block: @escaping (Self)->()) {
|
||||
@ -22,28 +19,34 @@ extension Clickable where Self: Handlerable {
|
||||
}
|
||||
}
|
||||
|
||||
extension Clickable where Self: Control {
|
||||
public func setupOnClick() {
|
||||
if let onClick {
|
||||
onClickSubscriber = publisher(for: .touchUpInside)
|
||||
.sink(receiveValue: { c in
|
||||
onClick(c)
|
||||
})
|
||||
} else {
|
||||
onClickSubscriber = nil
|
||||
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: ButtonBase {
|
||||
public func setupOnClick() {
|
||||
if let onClick {
|
||||
onClickSubscriber = publisher(for: .touchUpInside)
|
||||
.sink(receiveValue: { c in
|
||||
onClick(c)
|
||||
})
|
||||
} else {
|
||||
onClickSubscriber = nil
|
||||
extension Clickable where Self: Control {
|
||||
public var onClick: ((Self) -> ())? {
|
||||
get { return nil }
|
||||
set {
|
||||
if let newValue {
|
||||
onClickSubscriber = publisher(for: .touchUpInside)
|
||||
.sink { c in
|
||||
newValue(c)
|
||||
}
|
||||
} else {
|
||||
onClickSubscriber = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user