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