86 lines
2.3 KiB
Swift
86 lines
2.3 KiB
Swift
//
|
|
// Checkbox.swift
|
|
// VDS
|
|
//
|
|
// Created by Matt Bruce on 7/22/22.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
|
|
/// 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``.
|
|
@objcMembers
|
|
@objc(VDSCheckboxItem)
|
|
open class CheckboxItem: SelectorItemBase<Checkbox> {
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Initializers
|
|
//--------------------------------------------------
|
|
required public init() {
|
|
super.init(frame: .zero)
|
|
}
|
|
|
|
public override init(frame: CGRect) {
|
|
super.init(frame: .zero)
|
|
}
|
|
|
|
public required init?(coder: NSCoder) {
|
|
super.init(coder: coder)
|
|
}
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Public Properties
|
|
//--------------------------------------------------
|
|
/// Whether or not there is animation when the checkbox changes state from non-selected to a selected state.
|
|
open var isAnimated: Bool = false { didSet { setNeedsUpdate() } }
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Overrides
|
|
//--------------------------------------------------
|
|
/// This will change the state of the Selector and execute the actionBlock if provided.
|
|
open override func toggle() {
|
|
guard isEnabled else { return }
|
|
|
|
//removed error
|
|
if showError && isSelected == false {
|
|
showError.toggle()
|
|
}
|
|
isSelected.toggle()
|
|
sendActions(for: .valueChanged)
|
|
}
|
|
|
|
open override func setup() {
|
|
super.setup()
|
|
let foo = ConcreteClass(customView: Checkbox())
|
|
|
|
print(foo.customView.isAnimated)
|
|
}
|
|
|
|
/// Used to make changes to the View based off a change events or from local properties.
|
|
open override func updateView() {
|
|
selectorView.isAnimated = isAnimated
|
|
super.updateView()
|
|
}
|
|
}
|
|
|
|
|
|
@objcMembers
|
|
open class GenericClass<T: UIView>: NSObject {
|
|
public var customView: T
|
|
|
|
public init(customView: T = T()) {
|
|
self.customView = customView
|
|
}
|
|
}
|
|
|
|
@objcMembers
|
|
@objc(VDSConcreteClass)
|
|
open class ConcreteClass: GenericClass<Checkbox> {
|
|
|
|
}
|
|
|
|
@objcMembers
|
|
@objc(VDSConcreteCheckboxClass)
|
|
open class ConcreteCheckboxClass: ConcreteClass {}
|
|
|