removed RadioSwatch since this is no longer in Figma.

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-08-28 18:40:29 -05:00
parent 5f3c872092
commit 63a0014196
3 changed files with 0 additions and 502 deletions

View File

@ -22,8 +22,6 @@
EA0D1C452A6AD73000E5C127 /* RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0D1C442A6AD73000E5C127 /* RawRepresentable.swift */; };
EA0FC2C62914222900DF80B4 /* ButtonGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0FC2C52914222900DF80B4 /* ButtonGroup.swift */; };
EA1DA1CB2A2E36DC001C51D2 /* SelectorBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA1DA1CA2A2E36DC001C51D2 /* SelectorBase.swift */; };
EA1F266528B945070033E859 /* RadioSwatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA1F266128B945070033E859 /* RadioSwatch.swift */; };
EA1F266628B945070033E859 /* RadioSwatchGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA1F266228B945070033E859 /* RadioSwatchGroup.swift */; };
EA297A5529FB07760031ED56 /* TooltipLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA297A5429FB07760031ED56 /* TooltipLabelAttribute.swift */; };
EA297A5729FB0A360031ED56 /* AppleGuidlinesTouchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA297A5629FB0A360031ED56 /* AppleGuidlinesTouchable.swift */; };
EA336171288B19200071C351 /* VDS.docc in Sources */ = {isa = PBXBuildFile; fileRef = EA336170288B19200071C351 /* VDS.docc */; };
@ -169,8 +167,6 @@
EA0D1C442A6AD73000E5C127 /* RawRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RawRepresentable.swift; sourceTree = "<group>"; };
EA0FC2C52914222900DF80B4 /* ButtonGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonGroup.swift; sourceTree = "<group>"; };
EA1DA1CA2A2E36DC001C51D2 /* SelectorBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectorBase.swift; sourceTree = "<group>"; };
EA1F266128B945070033E859 /* RadioSwatch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RadioSwatch.swift; sourceTree = "<group>"; };
EA1F266228B945070033E859 /* RadioSwatchGroup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RadioSwatchGroup.swift; sourceTree = "<group>"; };
EA297A5429FB07760031ED56 /* TooltipLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TooltipLabelAttribute.swift; sourceTree = "<group>"; };
EA297A5629FB0A360031ED56 /* AppleGuidlinesTouchable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleGuidlinesTouchable.swift; sourceTree = "<group>"; };
EA33616C288B19200071C351 /* VDS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = VDS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@ -361,15 +357,6 @@
path = ButtonGroup;
sourceTree = "<group>";
};
EA1F265F28B945070033E859 /* RadioSwatch */ = {
isa = PBXGroup;
children = (
EA1F266128B945070033E859 /* RadioSwatch.swift */,
EA1F266228B945070033E859 /* RadioSwatchGroup.swift */,
);
path = RadioSwatch;
sourceTree = "<group>";
};
EA336162288B19200071C351 = {
isa = PBXGroup;
children = (
@ -439,7 +426,6 @@
445BA07629C07ABA0036A7C5 /* Notification */,
EA89200B28B530F0006B9984 /* RadioBox */,
EAF7F11428A1470D00B287F5 /* RadioButton */,
EA1F265F28B945070033E859 /* RadioSwatch */,
EA596ABB2A16B4D500300C4B /* Tabs */,
EAC925852911C9DE00091998 /* TextFields */,
EA5E304A294CBDBB0082B959 /* TileContainer */,
@ -989,7 +975,6 @@
EA89201528B56CF4006B9984 /* RadioBoxGroup.swift in Sources */,
EA985C1D296CD13600F2FF2E /* BundleManager.swift in Sources */,
EAC71A1D2A2E155A00E47A9F /* Checkbox.swift in Sources */,
EA1F266528B945070033E859 /* RadioSwatch.swift in Sources */,
EA4DB18528CA967F00103EE3 /* SelectorGroupHandlerBase.swift in Sources */,
EAF7F0AB289B13FD00B287F5 /* TextStyleLabelAttribute.swift in Sources */,
EAB1D29C28A5618900DAE764 /* RadioButtonGroup.swift in Sources */,
@ -1020,7 +1005,6 @@
EA3361A8288B23300071C351 /* UIColor.swift in Sources */,
EA1DA1CB2A2E36DC001C51D2 /* SelectorBase.swift in Sources */,
EAC9257D29119B5400091998 /* TextLink.swift in Sources */,
EA1F266628B945070033E859 /* RadioSwatchGroup.swift in Sources */,
EA596ABF2A16B4F500300C4B /* Tabs.swift in Sources */,
EAC71A212A2E1DC000E47A9F /* SelectorItemBase.swift in Sources */,
EAD062A72A3B67770015965D /* UIView+CALayer.swift in Sources */,

View File

@ -1,238 +0,0 @@
//
// RadioSwatch.swift
// VDS
//
// Created by Matt Bruce on 8/25/22.
//
import Foundation
import UIKit
import VDSColorTokens
import VDSFormControlsTokens
import Combine
@objc(VDSRadioSwatch)
open class RadioSwatch: Control {
//--------------------------------------------------
// 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
//--------------------------------------------------
open var selectorView = UIView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
}
open var fillView = UIImageView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.contentMode = .scaleAspectFit
}
open var fillImage: UIImage? { didSet { setNeedsUpdate() }}
open var text: String = "" { didSet { setNeedsUpdate() }}
open var primaryColor: UIColor? { didSet { setNeedsUpdate() }}
open var secondaryColor: UIColor? { didSet { setNeedsUpdate() }}
open var strikethrough: Bool = false { didSet { setNeedsUpdate() }}
open var inputId: String? { didSet { setNeedsUpdate() }}
open var value: AnyHashable? { didSet { setNeedsUpdate() }}
//--------------------------------------------------
// MARK: - Configuration Properties
//--------------------------------------------------
private var strikeThroughLineThickness: CGFloat = VDSFormControls.widthBorder
private var selectorBorderWidth: CGFloat = VDSFormControls.widthBorder
public let swatchSize = CGSize(width: 48, height: 48)
public let fillSize = CGSize(width: 36, height: 36)
public let disabledAlpha = 0.5
private var borderColorConfiguration = ControlColorConfiguration().with {
$0.setSurfaceColors(VDSFormControlsColor.borderOnlight, VDSFormControlsColor.borderOndark, forState: .normal)
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled)
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .highlighted)
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .selected)
}
//--------------------------------------------------
// MARK: - Overrides
//--------------------------------------------------
/// Executed on initialization for this View.
open override func initialSetup() {
super.initialSetup()
onClick = { control in
control.toggle()
}
}
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
open override func setup() {
super.setup()
isAccessibilityElement = true
accessibilityTraits = .button
addSubview(selectorView)
selectorView.isUserInteractionEnabled = false
selectorView.addSubview(fillView)
selectorView.pinToSuperView()
let selectorSize = getSelectorSize()
selectorView.height(selectorSize.height)
selectorView.width(selectorSize.width)
fillView.centerXAnchor.constraint(equalTo: selectorView.centerXAnchor).isActive = true
fillView.centerYAnchor.constraint(equalTo: selectorView.centerYAnchor).isActive = true
fillView.height(fillSize.height)
fillView.width(fillSize.width)
}
/// Resets to default settings.
open override func reset() {
super.reset()
shouldUpdateView = false
fillImage = nil
text = ""
primaryColor = nil
secondaryColor = nil
strikethrough = false
inputId = nil
value = nil
shouldUpdateView = true
setNeedsUpdate()
setNeedsDisplay()
}
open func toggle() {
isSelected.toggle()
sendActions(for: .valueChanged)
}
/// Used to make changes to the View based off a change events or from local properties.
open override func updateView() {
super.updateView()
layer.setNeedsDisplay()
}
public override func updateAccessibility() {
super.updateAccessibility()
accessibilityLabel = text
}
open override func layoutSubviews() {
super.layoutSubviews()
// Accounts for any size changes
layer.setNeedsDisplay()
}
open override func draw(_ layer: CALayer, in ctx: CGContext) {
let drawOuterBorder = isSelected || isHighlighted
let backgroundColor = UIColor.clear
let borderColor = isSelected ? borderColorConfiguration.getColor(self) : .clear
let fillBorderColor = borderColorConfiguration.getColor(self)
selectorView.backgroundColor = backgroundColor
selectorView.layer.borderColor = borderColor.cgColor
selectorView.layer.cornerRadius = selectorView.bounds.width * 0.5
selectorView.layer.borderWidth = drawOuterBorder ? selectorBorderWidth : 0
selectorView.layer.masksToBounds = true
gradientLayer?.removeFromSuperlayer()
gradientLayer = nil
var fillColorBackground: UIColor = .clear
if let fillImage {
fillView.image = !isEnabled ? fillImage.image(alpha: disabledAlpha) : fillImage
} else {
fillView.image = nil
if let primary = primaryColor, let secondary = secondaryColor {
let firstColor = !isEnabled ? primary.withAlphaComponent(disabledAlpha) : primary
let secondColor = !isEnabled ? secondary.withAlphaComponent(disabledAlpha) : secondary
let gradient = CAGradientLayer()
gradientLayer = gradient
gradient.frame = fillView.bounds
gradient.colors = [secondColor.cgColor, secondColor.cgColor, firstColor.cgColor, firstColor.cgColor]
gradient.locations = [NSNumber(value: 0.0), NSNumber(value: 0.5), NSNumber(value: 0.5), NSNumber(value: 1.0)]
gradient.transform = CATransform3DMakeRotation(135.0 / 180.0 * .pi, 0.0, 0.0, 1.0)
fillView.layer.addSublayer(gradient)
} else {
fillColorBackground = primaryColor ?? .white
}
}
fillView.backgroundColor = !isEnabled ? fillColorBackground.withAlphaComponent(disabledAlpha) : fillColorBackground
fillView.layer.borderColor = fillBorderColor.cgColor
fillView.layer.cornerRadius = fillView.bounds.width * 0.5
fillView.layer.borderWidth = selectorBorderWidth
fillView.layer.masksToBounds = true
shapeLayer?.removeFromSuperlayer()
shapeLayer = nil
if strikethrough {
let strikeThroughBorderColor = borderColorConfiguration.getColor(self)
let bounds = selectorView.bounds
let length = max(bounds.size.height, bounds.size.width)
guard length > 0.0, shapeLayer == nil else { return }
let strikeThrough = CAShapeLayer()
strikeThrough.name = "strikethrough"
strikeThrough.fillColor = nil
strikeThrough.opacity = 1.0
strikeThrough.lineWidth = strikeThroughLineThickness
strikeThrough.strokeColor = strikeThroughBorderColor.cgColor
let linePath = UIBezierPath()
linePath.move(to: CGPoint(x: 0, y: bounds.height))
linePath.addLine(to: CGPoint(x: bounds.width, y: 0))
linePath.addClip()
strikeThrough.path = linePath.cgPath
shapeLayer = strikeThrough
selectorView.layer.addSublayer(strikeThrough)
}
}
//--------------------------------------------------
// MARK: - RadioBox View Updates
//--------------------------------------------------
/// Manages the appearance of the radioSwatch.
private var shapeLayer: CAShapeLayer?
private var gradientLayer: CAGradientLayer?
open func getSelectorSize() -> CGSize {
return swatchSize
}
}
extension UIImage {
func image(alpha: CGFloat) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, scale)
draw(at: .zero, blendMode: .normal, alpha: alpha)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}
}

View File

@ -1,248 +0,0 @@
//
// RadioSwatchGroup.swift
// VDS
//
// Created by Matt Bruce on 8/25/22.
//
import Foundation
import UIKit
import Combine
@objc(VDSRadioSwatchGroup)
open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase<RadioSwatch>, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate {
//--------------------------------------------------
// 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: - Private Properties
//--------------------------------------------------
open var label = Label()
private let cellSize: CGFloat = 48.0
private let labelSpacing: CGFloat = 24.0
private let labelHeight: CGFloat = 16.0
private let lineSpacing: CGFloat = 12.0
private let itemSpacing: CGFloat = 16.0
fileprivate lazy var collectionView: SelfSizingCollectionView = {
let layout = UICollectionViewFlowLayout().with {
$0.minimumLineSpacing = lineSpacing
$0.minimumInteritemSpacing = itemSpacing
}
return SelfSizingCollectionView(frame: .zero, collectionViewLayout: layout).with {
$0.backgroundColor = .clear
$0.showsHorizontalScrollIndicator = false
$0.showsVerticalScrollIndicator = false
$0.isScrollEnabled = false
$0.translatesAutoresizingMaskIntoConstraints = false
$0.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "collectionViewCell")
}
}()
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
public override var selectorViews: [RadioSwatch] {
didSet {
collectionView.reloadData()
}
}
open var selectorModels: [RadioSwatchModel]? {
didSet {
if let selectorModels {
selectorViews = selectorModels.map { model in
return RadioSwatch().with {
$0.accessibilityLabel = model.accessibileText
$0.text = model.text
$0.fillImage = model.fillImage
$0.primaryColor = model.primaryColor
$0.secondaryColor = model.secondaryColor
$0.strikethrough = model.strikethrough
$0.isEnabled = !model.disabled
$0.surface = model.surface
$0.inputId = model.inputId
$0.value = model.value
$0.isSelected = model.selected
}
}
}
}
}
//--------------------------------------------------
// MARK: - Overrides
//--------------------------------------------------
/// Whether this object is disabled or not
override public var isEnabled: Bool {
didSet {
selectorViews.forEach { $0.isEnabled = isEnabled }
collectionView.reloadData()
}
}
/// Current Surface and this is used to pass down to child objects that implement Surfacable
override public var surface: Surface {
didSet {
for selector in selectorViews {
selector.surface = surface
}
collectionView.reloadData()
}
}
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
open override func setup() {
super.setup()
addSubview(label)
addSubview(collectionView)
label
.pinTop()
.pinLeading()
.pinTrailing()
.height(labelHeight)
collectionView
.pinTop(label.bottomAnchor, labelSpacing)
.pinLeading()
.pinTrailing()
.pinBottom()
}
open override func layoutSubviews() {
super.layoutSubviews()
// Accounts for any collection size changes
DispatchQueue.main.async {
self.collectionView.collectionViewLayout.invalidateLayout()
}
}
public override func initialSetup() {
super.initialSetup()
collectionView.delegate = self
collectionView.dataSource = self
}
/// Used to make changes to the View based off a change events or from local properties.
open override func updateView() {
super.updateView()
label.textPosition = .left
label.textStyle = .bodySmall
label.text = selectedHandler?.text ?? " "
label.surface = surface
label.isEnabled = isEnabled
collectionView.reloadData()
}
public func reload() {
collectionView.reloadData()
}
//--------------------------------------------------
// MARK: - UICollectionViewDelegateFlowLayout
//--------------------------------------------------
open func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: cellSize, height: cellSize)
}
//--------------------------------------------------
// MARK: - UICollectionViewDelegate
//--------------------------------------------------
open func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
return selectorViews[indexPath.row].isEnabled
}
open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
didSelect(selector: selectorViews[indexPath.row])
}
//--------------------------------------------------
// MARK: - UICollectionViewDataSource
//--------------------------------------------------
public func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return selectorViews.count
}
var cellsubs: [Int: AnyCancellable] = [:]
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath)
let handler = selectorViews[indexPath.row]
handler.onClick = { [weak self] handler in
self?.didSelect(selector: handler)
}
cell.subviews.forEach { $0.removeFromSuperview() }
cell.addSubview(handler)
handler.pinToSuperView()
return cell
}
public func didSelect(selector: RadioSwatch) {
selectedHandler?.toggle()
selector.toggle()
label.text = selector.text
setNeedsUpdate()
valueChanged()
}
}
extension RadioSwatchGroup {
public struct RadioSwatchModel: Surfaceable, Initable {
/// Whether this object is disabled or not
public var disabled: Bool = false
/// Current Surface and this is used to pass down to child objects that implement Surfacable
public var surface: Surface
public var inputId: String?
public var value: AnyHashable?
public var selected: Bool = false
public var text: String
public var fillImage: UIImage?
public var primaryColor: UIColor?
public var secondaryColor: UIColor?
public var strikethrough: Bool = false
public var accessibileText: String?
public init(disabled: Bool, surface: Surface = .light, inputId: String? = nil, value: AnyHashable? = nil, selected: Bool = false,
text: String = "", fillImage: UIImage? = nil, primaryColor: UIColor? = nil, secondaryColor: UIColor? = nil,
strikethrough: Bool = false, accessibileText: String? = nil) {
self.disabled = disabled
self.surface = surface
self.inputId = inputId
self.value = value
self.selected = selected
self.text = text
self.fillImage = fillImage
self.primaryColor = primaryColor
self.secondaryColor = secondaryColor
self.strikethrough = strikethrough
self.accessibileText = accessibileText
}
public init() {
self.init(disabled: false)
}
}
}