Compare commits
No commits in common. "e264fbd5ca6dd5526f229a5a75efda30649f2a6b" and "b3b3fa6965115633c1880b066ec6525ece131414" have entirely different histories.
e264fbd5ca
...
b3b3fa6965
@ -8,13 +8,12 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import UIKit
|
import UIKit
|
||||||
import VDSColorTokens
|
import VDSColorTokens
|
||||||
import Combine
|
|
||||||
|
|
||||||
/// A button icon is an interactive element that visually communicates the action it triggers via an icon.
|
/// A button icon is an interactive element that visually communicates the action it triggers via an icon.
|
||||||
/// It usually represents a supplementary or utilitarian action. A button icon can stand alone, but often
|
/// It usually represents a supplementary or utilitarian action. A button icon can stand alone, but often
|
||||||
/// exists in a group when there are several actions that can be performed.
|
/// exists in a group when there are several actions that can be performed.
|
||||||
@objc(VDSButtonIcon)
|
@objc(VDSButtonIcon)
|
||||||
open class ButtonIcon: Control, Changeable, FormFieldable {
|
open class ButtonIcon: Control {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
@ -78,7 +77,7 @@ open class ButtonIcon: Control, Changeable, FormFieldable {
|
|||||||
private var badgeIndicatorCenterXConstraint: NSLayoutConstraint?
|
private var badgeIndicatorCenterXConstraint: NSLayoutConstraint?
|
||||||
private var badgeIndicatorCenterYConstraint: NSLayoutConstraint?
|
private var badgeIndicatorCenterYConstraint: NSLayoutConstraint?
|
||||||
private var currentIconName: Icon.Name? {
|
private var currentIconName: Icon.Name? {
|
||||||
if let selectedIconName, isSelected {
|
if let selectedIconName, selectable {
|
||||||
return selectedIconName
|
return selectedIconName
|
||||||
} else {
|
} else {
|
||||||
return iconName
|
return iconName
|
||||||
@ -145,15 +144,7 @@ open class ButtonIcon: Control, Changeable, FormFieldable {
|
|||||||
open var showBadgeIndicator: Bool = false { didSet { setNeedsUpdate() } }
|
open var showBadgeIndicator: Bool = false { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
/// If true, button will be rendered as selected, when it is selectable.
|
/// If true, button will be rendered as selected, when it is selectable.
|
||||||
open var selectable: Bool = false {
|
open var selectable: Bool = false { didSet { setNeedsUpdate() } }
|
||||||
didSet {
|
|
||||||
//unselect
|
|
||||||
if !selectable && isSelected {
|
|
||||||
isSelected = false
|
|
||||||
}
|
|
||||||
setNeedsUpdate()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Used to move the icon inside the button in both x and y axis.
|
/// Used to move the icon inside the button in both x and y axis.
|
||||||
open var iconOffset: CGPoint = .init(x: 0, y: 0) { didSet { setNeedsUpdate() } }
|
open var iconOffset: CGPoint = .init(x: 0, y: 0) { didSet { setNeedsUpdate() } }
|
||||||
@ -161,12 +152,6 @@ open class ButtonIcon: Control, Changeable, FormFieldable {
|
|||||||
/// Applies expand direction to Badge Indicator if shows badge indicator.
|
/// Applies expand direction to Badge Indicator if shows badge indicator.
|
||||||
open var expandDirection: ExpandDirection = .right { didSet { setNeedsUpdate() } }
|
open var expandDirection: ExpandDirection = .right { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
open var onChangeSubscriber: AnyCancellable?
|
|
||||||
|
|
||||||
open var inputId: String? { didSet { setNeedsUpdate() } }
|
|
||||||
|
|
||||||
open var value: AnyHashable? { didSet { setNeedsUpdate() } }
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Configuration
|
// MARK: - Configuration
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -202,7 +187,6 @@ open class ButtonIcon: Control, Changeable, FormFieldable {
|
|||||||
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .normal)
|
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .normal)
|
||||||
$0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted)
|
$0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted)
|
||||||
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled)
|
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled)
|
||||||
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled])
|
|
||||||
}.eraseToAnyColorable()
|
}.eraseToAnyColorable()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -211,7 +195,6 @@ open class ButtonIcon: Control, Changeable, FormFieldable {
|
|||||||
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .normal)
|
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .normal)
|
||||||
$0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted)
|
$0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted)
|
||||||
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.paletteBlack.withAlphaComponent(0.70), forState: .disabled)
|
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.paletteBlack.withAlphaComponent(0.70), forState: .disabled)
|
||||||
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.paletteBlack.withAlphaComponent(0.70), forState: [.selected, .disabled])
|
|
||||||
}.eraseToAnyColorable()
|
}.eraseToAnyColorable()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -289,7 +272,6 @@ open class ButtonIcon: Control, Changeable, FormFieldable {
|
|||||||
$0.setSurfaceColors(VDSColor.backgroundPrimaryDark, VDSColor.backgroundPrimaryLight, forState: .normal)
|
$0.setSurfaceColors(VDSColor.backgroundPrimaryDark, VDSColor.backgroundPrimaryLight, forState: .normal)
|
||||||
$0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted)
|
$0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted)
|
||||||
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled)
|
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled)
|
||||||
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled])
|
|
||||||
}.eraseToAnyColorable()
|
}.eraseToAnyColorable()
|
||||||
|
|
||||||
}()
|
}()
|
||||||
@ -304,7 +286,6 @@ open class ButtonIcon: Control, Changeable, FormFieldable {
|
|||||||
$0.setSurfaceColors(VDSColor.paletteGray20, VDSColor.paletteWhite, forState: .normal)
|
$0.setSurfaceColors(VDSColor.paletteGray20, VDSColor.paletteWhite, forState: .normal)
|
||||||
$0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted)
|
$0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted)
|
||||||
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled)
|
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled)
|
||||||
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled])
|
|
||||||
}.eraseToAnyColorable()
|
}.eraseToAnyColorable()
|
||||||
}()
|
}()
|
||||||
var shadowColorConfiguration: AnyColorable = {
|
var shadowColorConfiguration: AnyColorable = {
|
||||||
@ -320,17 +301,6 @@ open class ButtonIcon: Control, Changeable, FormFieldable {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// MARK: - Overrides
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
/// Executed on initialization for this View.
|
|
||||||
open override func initialSetup() {
|
|
||||||
super.initialSetup()
|
|
||||||
onClick = { control in
|
|
||||||
guard control.isEnabled else { return }
|
|
||||||
if let selectedIconName = control.selectedIconName, control.selectable {
|
|
||||||
control.toggle()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
||||||
open override func setup() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
@ -465,19 +435,11 @@ open class ButtonIcon: Control, Changeable, FormFieldable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This will change the state of the Selector and execute the actionBlock if provided.
|
|
||||||
open func toggle() {
|
|
||||||
//removed error
|
|
||||||
isSelected.toggle()
|
|
||||||
sendActions(for: .valueChanged)
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Methods
|
// MARK: - Private Methods
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private func updateBadgeIndicator() {
|
private func updateBadgeIndicator() {
|
||||||
if let badgeIndicatorModel {
|
if let badgeIndicatorModel {
|
||||||
badgeIndicator.isEnabled = isEnabled
|
|
||||||
badgeIndicator.kind = badgeIndicatorModel.kind
|
badgeIndicator.kind = badgeIndicatorModel.kind
|
||||||
badgeIndicator.fillColor = badgeIndicatorModel.fillColor
|
badgeIndicator.fillColor = badgeIndicatorModel.fillColor
|
||||||
badgeIndicator.surface = badgeIndicatorModel.surface
|
badgeIndicator.surface = badgeIndicatorModel.surface
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user