refactored to remove combine for local updater, replaced with setNeedsUpdate

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-05-08 11:51:10 -05:00
parent f42d48c5c3
commit e82a94304c
28 changed files with 193 additions and 208 deletions

View File

@ -15,7 +15,6 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Combine Properties // MARK: - Combine Properties
//-------------------------------------------------- //--------------------------------------------------
public var subject = PassthroughSubject<Void, Never>()
public var subscribers = Set<AnyCancellable>() public var subscribers = Set<AnyCancellable>()
public var onClickSubscriber: AnyCancellable? { public var onClickSubscriber: AnyCancellable? {
willSet { willSet {
@ -30,13 +29,15 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
//-------------------------------------------------- //--------------------------------------------------
private var initialSetupPerformed = false private var initialSetupPerformed = false
open var shouldUpdateView: Bool = true
open var userInfo = [String: Primitive]() open var userInfo = [String: Primitive]()
open var surface: Surface = .light { didSet { didChange() } } open var surface: Surface = .light { didSet { setNeedsUpdate() } }
open var disabled: Bool = false { didSet { isEnabled = !disabled } } open var disabled: Bool = false { didSet { isEnabled = !disabled } }
open override var isSelected: Bool { didSet { didChange() } } open override var isSelected: Bool { didSet { setNeedsUpdate() } }
public var touchUpInsideCount: Int = 0 public var touchUpInsideCount: Int = 0
@ -65,7 +66,7 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
disabled = !newValue disabled = !newValue
} }
isUserInteractionEnabled = isEnabled isUserInteractionEnabled = isEnabled
didChange() setNeedsUpdate()
} }
} }
@ -95,8 +96,7 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
if !initialSetupPerformed { if !initialSetupPerformed {
initialSetupPerformed = true initialSetupPerformed = true
setup() setup()
setupDidChangeEvent() setNeedsUpdate()
updateView()
} }
} }

View File

@ -48,7 +48,7 @@ open class SelectorGroupHandlerBase<HandlerType: Control>: Control, Changeable {
} }
public func valueChanged() { public func valueChanged() {
DispatchQueue.main.asyncAfter(deadline: .now() + Constants.StateDebounce) { [weak self] in DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) { [weak self] in
self?.sendActions(for: .valueChanged) self?.sendActions(for: .valueChanged)
} }
} }

View File

@ -16,7 +16,6 @@ open class View: UIView, Handlerable, ViewProtocol, Resettable, UserInfoable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Combine Properties // MARK: - Combine Properties
//-------------------------------------------------- //--------------------------------------------------
public var subject = PassthroughSubject<Void, Never>()
public var subscribers = Set<AnyCancellable>() public var subscribers = Set<AnyCancellable>()
//-------------------------------------------------- //--------------------------------------------------
@ -24,9 +23,11 @@ open class View: UIView, Handlerable, ViewProtocol, Resettable, UserInfoable {
//-------------------------------------------------- //--------------------------------------------------
private var initialSetupPerformed = false private var initialSetupPerformed = false
open var shouldUpdateView: Bool = true
open var userInfo = [String: Primitive]() open var userInfo = [String: Primitive]()
open var surface: Surface = .light { didSet { didChange() }} open var surface: Surface = .light { didSet { setNeedsUpdate() }}
open var disabled: Bool = false { didSet { isEnabled = !disabled } } open var disabled: Bool = false { didSet { isEnabled = !disabled } }
@ -37,7 +38,7 @@ open class View: UIView, Handlerable, ViewProtocol, Resettable, UserInfoable {
disabled = !newValue disabled = !newValue
} }
isUserInteractionEnabled = isEnabled isUserInteractionEnabled = isEnabled
didChange() setNeedsUpdate()
} }
} }
@ -67,8 +68,7 @@ open class View: UIView, Handlerable, ViewProtocol, Resettable, UserInfoable {
if !initialSetupPerformed { if !initialSetupPerformed {
initialSetupPerformed = true initialSetupPerformed = true
setup() setup()
setupDidChangeEvent() setNeedsUpdate()
updateView()
} }
} }

View File

@ -32,13 +32,13 @@ open class Badge: View {
$0.textStyle = .boldBodySmall $0.textStyle = .boldBodySmall
} }
open var fillColor: FillColor = .red { didSet { didChange() }} open var fillColor: FillColor = .red { didSet { setNeedsUpdate() }}
open var text: String = "" { didSet { didChange() }} open var text: String = "" { didSet { setNeedsUpdate() }}
open var maxWidth: CGFloat? { didSet { didChange() }} open var maxWidth: CGFloat? { didSet { setNeedsUpdate() }}
open var numberOfLines: Int = 1 { didSet { didChange() }} open var numberOfLines: Int = 1 { didSet { setNeedsUpdate() }}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Constraints // MARK: - Constraints

View File

@ -32,11 +32,11 @@ open class Button: ButtonBase, Useable {
//-------------------------------------------------- //--------------------------------------------------
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 { setNeedsUpdate() }}
open var size: ButtonSize = .large { didSet { didChange() }} open var size: ButtonSize = .large { didSet { setNeedsUpdate() }}
open var width: CGFloat? { didSet { didChange() }} open var width: CGFloat? { didSet { setNeedsUpdate() }}
open override var textColor: UIColor { open override var textColor: UIColor {
textColorConfiguration.getColor(self) textColorConfiguration.getColor(self)

View File

@ -28,7 +28,6 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Combine Properties // MARK: - Combine Properties
//-------------------------------------------------- //--------------------------------------------------
public var subject = PassthroughSubject<Void, Never>()
public var subscribers = Set<AnyCancellable>() public var subscribers = Set<AnyCancellable>()
public var onClickSubscriber: AnyCancellable? { public var onClickSubscriber: AnyCancellable? {
willSet { willSet {
@ -46,13 +45,15 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Properties // MARK: - Properties
//-------------------------------------------------- //--------------------------------------------------
open var shouldUpdateView: Bool = true
open var availableSizes: [ButtonSize] { [] } open var availableSizes: [ButtonSize] { [] }
open var text: String? { didSet { didChange() } } open var text: String? { didSet { setNeedsUpdate() } }
open var attributes: [any LabelAttributeModel]? { nil } open var attributes: [any LabelAttributeModel]? { nil }
open var surface: Surface = .light { didSet { didChange() }} open var surface: Surface = .light { didSet { setNeedsUpdate() }}
open var disabled: Bool = false { didSet { isEnabled = !disabled } } open var disabled: Bool = false { didSet { isEnabled = !disabled } }
@ -90,7 +91,7 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
disabled = !newValue disabled = !newValue
} }
isUserInteractionEnabled = isEnabled isUserInteractionEnabled = isEnabled
didChange() setNeedsUpdate()
} }
} }
@ -121,8 +122,7 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
translatesAutoresizingMaskIntoConstraints = false translatesAutoresizingMaskIntoConstraints = false
accessibilityCustomActions = [] accessibilityCustomActions = []
setup() setup()
setupDidChangeEvent(true) setNeedsUpdate()
updateView()
} }
} }

View File

@ -25,16 +25,16 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------
//An object containing number of Button components per row, in each viewport //An object containing number of Button components per row, in each viewport
open var rowQuantityPhone: Int = 0 { didSet { didChange() } } open var rowQuantityPhone: Int = 0 { didSet { setNeedsUpdate() } }
open var rowQuantityTablet: Int = 0 { didSet { didChange() } } open var rowQuantityTablet: Int = 0 { didSet { setNeedsUpdate() } }
public var rowQuantity: Int { UIDevice.isIPad ? rowQuantityTablet : rowQuantityPhone } public var rowQuantity: Int { UIDevice.isIPad ? rowQuantityTablet : rowQuantityPhone }
//If provided, aligns TextLink/TextLinkCaret alignment when rowQuantity is set one. //If provided, aligns TextLink/TextLinkCaret alignment when rowQuantity is set one.
open var buttonPosition: ButtonPosition = .center { didSet { didChange() }} open var buttonPosition: ButtonPosition = .center { didSet { setNeedsUpdate() }}
open var buttons: [Buttonable] = [] { didSet { didChange() }} open var buttons: [Buttonable] = [] { didSet { setNeedsUpdate() }}
//If provided, width of Button components will be rendered based on this value. If omitted, default button widths are rendered. //If provided, width of Button components will be rendered based on this value. If omitted, default button widths are rendered.
open var buttonWidth: CGFloat? { open var buttonWidth: CGFloat? {
@ -47,7 +47,7 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega
button.width = buttonWidth button.width = buttonWidth
} }
} }
didChange() setNeedsUpdate()
} }
} }
@ -64,7 +64,7 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega
self.buttonWidth = nil self.buttonWidth = nil
} }
positionLayout.buttonPercentage = buttonPercentage positionLayout.buttonPercentage = buttonPercentage
didChange() setNeedsUpdate()
} }
} }

View File

@ -22,7 +22,7 @@ open class TextLink: ButtonBase {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Properties // MARK: - Properties
//-------------------------------------------------- //--------------------------------------------------
open var size: ButtonSize = .large { didSet { didChange() }} open var size: ButtonSize = .large { didSet { setNeedsUpdate() }}
open override var availableSizes: [ButtonSize] { [.large, .small] } open override var availableSizes: [ButtonSize] { [.large, .small] }

View File

@ -44,7 +44,7 @@ open class TextLinkCaret: ButtonBase {
//-------------------------------------------------- //--------------------------------------------------
public override var availableSizes: [ButtonSize] { [.large] } public override var availableSizes: [ButtonSize] { [.large] }
open var iconPosition: IconPosition = .right { didSet { didChange() } } open var iconPosition: IconPosition = .right { didSet { setNeedsUpdate() } }
private var height: CGFloat { private var height: CGFloat {
44 44
@ -58,7 +58,7 @@ open class TextLinkCaret: ButtonBase {
var updatedText = newValue ?? "" var updatedText = newValue ?? ""
updatedText = iconPosition == .right ? "\(updatedText) " : " \(updatedText)" updatedText = iconPosition == .right ? "\(updatedText) " : " \(updatedText)"
_text = updatedText _text = updatedText
didChange() setNeedsUpdate()
} }
} }
@ -152,11 +152,11 @@ internal class CaretView: View {
//------------------------------------------------------ //------------------------------------------------------
private var caretPath: UIBezierPath = UIBezierPath() private var caretPath: UIBezierPath = UIBezierPath()
public var lineWidth: CGFloat = 1 { didSet{ didChange() } } public var lineWidth: CGFloat = 1 { didSet{ setNeedsUpdate() } }
public var direction: Direction = .right { didSet{ didChange() } } public var direction: Direction = .right { didSet{ setNeedsUpdate() } }
public var size: Size? { didSet{ didChange() } } public var size: Size? { didSet{ setNeedsUpdate() } }
public var colorConfiguration: AnyColorable = ViewColorConfiguration().with { public var colorConfiguration: AnyColorable = ViewColorConfiguration().with {
$0.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark, forDisabled: true) $0.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark, forDisabled: true)

View File

@ -93,31 +93,31 @@ open class Checkbox: Control, Errorable, Changeable {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
} }
open var isAnimated: Bool = true { didSet { didChange() }} open var isAnimated: Bool = true { didSet { setNeedsUpdate() }}
open override var isSelected: Bool { didSet { didChange() }} open override var isSelected: Bool { didSet { setNeedsUpdate() }}
open var labelText: String? { didSet { didChange() }} open var labelText: String? { didSet { setNeedsUpdate() }}
open var labelTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} open var labelTextAttributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }}
open var labelAttributedText: NSAttributedString? { open var labelAttributedText: NSAttributedString? {
didSet { didSet {
label.useAttributedText = !(labelAttributedText?.string.isEmpty ?? true) label.useAttributedText = !(labelAttributedText?.string.isEmpty ?? true)
label.attributedText = labelAttributedText label.attributedText = labelAttributedText
didChange() setNeedsUpdate()
} }
} }
open var childText: String? { didSet { didChange() }} open var childText: String? { didSet { setNeedsUpdate() }}
open var childTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} open var childTextAttributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }}
open var childAttributedText: NSAttributedString? { open var childAttributedText: NSAttributedString? {
didSet { didSet {
childLabel.useAttributedText = !(childAttributedText?.string.isEmpty ?? true) childLabel.useAttributedText = !(childAttributedText?.string.isEmpty ?? true)
childLabel.attributedText = childAttributedText childLabel.attributedText = childAttributedText
didChange() setNeedsUpdate()
} }
} }
@ -127,7 +127,7 @@ open class Checkbox: Control, Errorable, Changeable {
set { set {
if !isSelected && _showError != newValue { if !isSelected && _showError != newValue {
_showError = newValue _showError = newValue
didChange() setNeedsUpdate()
} }
} }
} }
@ -142,11 +142,11 @@ open class Checkbox: Control, Errorable, Changeable {
} }
} }
open var errorText: String? { didSet { didChange() }} open var errorText: String? { didSet { setNeedsUpdate() }}
open var inputId: String? { didSet { didChange() }} open var inputId: String? { didSet { setNeedsUpdate() }}
open var value: AnyHashable? { didSet { didChange() }} open var value: AnyHashable? { didSet { setNeedsUpdate() }}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Constraints // MARK: - Constraints

View File

@ -28,10 +28,10 @@ open class Icon: View {
$0.clipsToBounds = true $0.clipsToBounds = true
} }
open var color: Color = .black { didSet { didChange() }} open var color: Color = .black { didSet { setNeedsUpdate() }}
open var size: Size = .medium { didSet { didChange() }} open var size: Size = .medium { didSet { setNeedsUpdate() }}
open var name: Name? { didSet { didChange() }} open var name: Name? { didSet { setNeedsUpdate() }}
open var customSize: Int? { didSet { didChange() }} open var customSize: Int? { didSet { setNeedsUpdate() }}
//functions //functions
//-------------------------------------------------- //--------------------------------------------------

View File

@ -72,7 +72,7 @@ public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable
addHandler(on: attributedString) addHandler(on: attributedString)
} }
public init(id: UUID = UUID(), action: PassthroughSubject<Void, Never> = PassthroughSubject<Void, Never>(), subscriber: AnyCancellable? = nil, surface: Surface, accessibleText: String? = nil, closeButtonText: String, title: String, content: String) { public init(id: UUID = UUID(), action: PassthroughSubject<Void, Never> = PassthroughSubject<Void, Never>(), subscriber: AnyCancellable? = nil, surface: Surface, accessibleText: String? = nil, closeButtonText: String = "Close", title: String, content: String) {
self.id = id self.id = id
self.action = action self.action = action
self.subscriber = subscriber self.subscriber = subscriber

View File

@ -16,26 +16,26 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Combine Properties // MARK: - Combine Properties
//-------------------------------------------------- //--------------------------------------------------
public var subject = PassthroughSubject<Void, Never>()
public var subscribers = Set<AnyCancellable>() public var subscribers = Set<AnyCancellable>()
public var hasChanged: Bool = false
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Properties // MARK: - Properties
//-------------------------------------------------- //--------------------------------------------------
private var initialSetupPerformed = false private var initialSetupPerformed = false
open var shouldUpdateView: Bool = true
open var useAttributedText: Bool = false open var useAttributedText: Bool = false
open var surface: Surface = .light { didSet { didChange() }} open var surface: Surface = .light { didSet { setNeedsUpdate() }}
open var disabled: Bool = false { didSet { isEnabled = !disabled } } open var disabled: Bool = false { didSet { isEnabled = !disabled } }
open var attributes: [any LabelAttributeModel]? { didSet { didChange() }} open var attributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }}
open var textStyle: TextStyle = .defaultStyle { didSet { didChange() }} open var textStyle: TextStyle = .defaultStyle { didSet { setNeedsUpdate() }}
open var textPosition: TextPosition = .left { didSet { didChange() }} open var textPosition: TextPosition = .left { didSet { setNeedsUpdate() }}
open var userInfo = [String: Primitive]() open var userInfo = [String: Primitive]()
@ -46,14 +46,14 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable {
disabled = !newValue disabled = !newValue
} }
isUserInteractionEnabled = isEnabled isUserInteractionEnabled = isEnabled
didChange() setNeedsUpdate()
} }
} }
override open var text: String? { override open var text: String? {
didSet { didSet {
attributes = nil attributes = nil
didChange() setNeedsUpdate()
} }
} }
@ -95,8 +95,7 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable {
accessibilityCustomActions = [] accessibilityCustomActions = []
accessibilityTraits = .staticText accessibilityTraits = .staticText
setup() setup()
setupDidChangeEvent(true) setNeedsUpdate()
updateView()
} }
} }

View File

@ -26,7 +26,7 @@ open class Line: View {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
} }
open var style: Style = .primary { didSet { didChange() } } open var style: Style = .primary { didSet { setNeedsUpdate() } }
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Lifecycle // MARK: - Lifecycle

View File

@ -117,18 +117,18 @@ open class Notification: View {
} }
//Text //Text
open var title: String = "" { didSet{didChange()}} open var title: String = "" { didSet{setNeedsUpdate()}}
open var subTitle: String? { didSet{didChange()}} open var subTitle: String? { didSet{setNeedsUpdate()}}
//Buttons //Buttons
open var primaryButtonModel: ButtonModel? { didSet{didChange()}} open var primaryButtonModel: ButtonModel? { didSet{setNeedsUpdate()}}
open var primaryButton = Button().with { open var primaryButton = Button().with {
$0.size = .small $0.size = .small
$0.use = .secondary $0.use = .secondary
} }
open var secondaryButtonModel: ButtonModel? { didSet{didChange()}} open var secondaryButtonModel: ButtonModel? { didSet{setNeedsUpdate()}}
open var secondaryButton = Button().with { open var secondaryButton = Button().with {
$0.size = .small $0.size = .small
$0.use = .secondary $0.use = .secondary
@ -152,11 +152,11 @@ open class Notification: View {
// MARK: - Properties // MARK: - Properties
//-------------------------------------------------- //--------------------------------------------------
open var hideCloseButton: Bool = false { didSet{didChange()}} open var hideCloseButton: Bool = false { didSet{setNeedsUpdate()}}
open var type: Style = .info { didSet{didChange()}} open var type: Style = .info { didSet{setNeedsUpdate()}}
open var fullBleed: Bool = false { didSet {didChange()}} open var fullBleed: Bool = false { didSet {setNeedsUpdate()}}
var _layout: Layout = .vertical var _layout: Layout = .vertical
open var layout: Layout { open var layout: Layout {
@ -164,7 +164,7 @@ open class Notification: View {
if !UIDevice.isIPad, newValue == .horizontal { return } if !UIDevice.isIPad, newValue == .horizontal { return }
_layout = newValue _layout = newValue
buttonsView.buttonPosition = _layout == .horizontal ? .center : .left buttonsView.buttonPosition = _layout == .horizontal ? .center : .left
didChange() setNeedsUpdate()
} }
get { _layout } get { _layout }
} }

View File

@ -86,47 +86,47 @@ open class RadioBox: Control, Changeable {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
} }
open var text: String = "Default Text" { didSet { didChange() }} open var text: String = "Default Text" { didSet { setNeedsUpdate() }}
open var textAttributes: [any LabelAttributeModel]? { didSet { didChange() }} open var textAttributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }}
open var textAttributedText: NSAttributedString? { open var textAttributedText: NSAttributedString? {
didSet { didSet {
textLabel.useAttributedText = !(textAttributedText?.string.isEmpty ?? true) textLabel.useAttributedText = !(textAttributedText?.string.isEmpty ?? true)
textLabel.attributedText = textAttributedText textLabel.attributedText = textAttributedText
didChange() setNeedsUpdate()
} }
} }
open var subText: String? { didSet { didChange() }} open var subText: String? { didSet { setNeedsUpdate() }}
open var subTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} open var subTextAttributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }}
open var subTextAttributedText: NSAttributedString? { open var subTextAttributedText: NSAttributedString? {
didSet { didSet {
subTextLabel.useAttributedText = !(subTextAttributedText?.string.isEmpty ?? true) subTextLabel.useAttributedText = !(subTextAttributedText?.string.isEmpty ?? true)
subTextLabel.attributedText = subTextAttributedText subTextLabel.attributedText = subTextAttributedText
didChange() setNeedsUpdate()
} }
} }
open var subTextRight: String? { didSet { didChange() }} open var subTextRight: String? { didSet { setNeedsUpdate() }}
open var subTextRightAttributes: [any LabelAttributeModel]? { didSet { didChange() }} open var subTextRightAttributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }}
open var subTextRightAttributedText: NSAttributedString? { open var subTextRightAttributedText: NSAttributedString? {
didSet { didSet {
subTextRightLabel.useAttributedText = !(subTextRightAttributedText?.string.isEmpty ?? true) subTextRightLabel.useAttributedText = !(subTextRightAttributedText?.string.isEmpty ?? true)
subTextRightLabel.attributedText = subTextRightAttributedText subTextRightLabel.attributedText = subTextRightAttributedText
didChange() setNeedsUpdate()
} }
} }
open var strikethrough: Bool = false { didSet { didChange() }} open var strikethrough: Bool = false { didSet { setNeedsUpdate() }}
open var inputId: String? { didSet { didChange() }} open var inputId: String? { didSet { setNeedsUpdate() }}
open var value: AnyHashable? { didSet { didChange() }} open var value: AnyHashable? { didSet { setNeedsUpdate() }}
//functions //functions
//-------------------------------------------------- //--------------------------------------------------

View File

@ -92,31 +92,31 @@ open class RadioButton: Control, Errorable, Changeable {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
} }
open var labelText: String? { didSet { didChange() }} open var labelText: String? { didSet { setNeedsUpdate() }}
open var labelTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} open var labelTextAttributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }}
open var labelAttributedText: NSAttributedString? { open var labelAttributedText: NSAttributedString? {
didSet { didSet {
label.useAttributedText = !(labelAttributedText?.string.isEmpty ?? true) label.useAttributedText = !(labelAttributedText?.string.isEmpty ?? true)
label.attributedText = labelAttributedText label.attributedText = labelAttributedText
didChange() setNeedsUpdate()
} }
} }
open var childText: String? { didSet { didChange() }} open var childText: String? { didSet { setNeedsUpdate() }}
open var childTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} open var childTextAttributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }}
open var childAttributedText: NSAttributedString? { open var childAttributedText: NSAttributedString? {
didSet { didSet {
childLabel.useAttributedText = !(childAttributedText?.string.isEmpty ?? true) childLabel.useAttributedText = !(childAttributedText?.string.isEmpty ?? true)
childLabel.attributedText = childAttributedText childLabel.attributedText = childAttributedText
didChange() setNeedsUpdate()
} }
} }
open var showError: Bool = false { didSet { didChange() }} open var showError: Bool = false { didSet { setNeedsUpdate() }}
open override var state: UIControl.State { open override var state: UIControl.State {
get { get {
@ -128,11 +128,11 @@ open class RadioButton: Control, Errorable, Changeable {
} }
} }
open var errorText: String? { didSet { didChange() }} open var errorText: String? { didSet { setNeedsUpdate() }}
open var inputId: String? { didSet { didChange() }} open var inputId: String? { didSet { setNeedsUpdate() }}
open var value: AnyHashable? { didSet { didChange() }} open var value: AnyHashable? { didSet { setNeedsUpdate() }}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Constraints // MARK: - Constraints

View File

@ -41,19 +41,19 @@ open class RadioSwatch: Control {
$0.contentMode = .scaleAspectFit $0.contentMode = .scaleAspectFit
} }
open var fillImage: UIImage? { didSet { didChange() }} open var fillImage: UIImage? { didSet { setNeedsUpdate() }}
open var text: String = "" { didSet { didChange() }} open var text: String = "" { didSet { setNeedsUpdate() }}
open var primaryColor: UIColor? { didSet { didChange() }} open var primaryColor: UIColor? { didSet { setNeedsUpdate() }}
open var secondaryColor: UIColor? { didSet { didChange() }} open var secondaryColor: UIColor? { didSet { setNeedsUpdate() }}
open var strikethrough: Bool = false { didSet { didChange() }} open var strikethrough: Bool = false { didSet { setNeedsUpdate() }}
open var inputId: String? { didSet { didChange() }} open var inputId: String? { didSet { setNeedsUpdate() }}
open var value: AnyHashable? { didSet { didChange() }} open var value: AnyHashable? { didSet { setNeedsUpdate() }}
//functions //functions
//-------------------------------------------------- //--------------------------------------------------

View File

@ -183,7 +183,7 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase<RadioSwatch>, UICo
selectedHandler?.toggle() selectedHandler?.toggle()
selector.toggle() selector.toggle()
label.text = selector.text label.text = selector.text
didChange() setNeedsUpdate()
valueChanged() valueChanged()
} }
} }

View File

@ -106,11 +106,10 @@ open class EntryField: Control, Changeable {
} }
} }
open var titleLabel = TrailingTooltipLabel().with { open var titleLabel = Label().with {
$0.setContentCompressionResistancePriority(.required, for: .vertical) $0.setContentCompressionResistancePriority(.required, for: .vertical)
$0.labelTextPosition = .left $0.textPosition = .left
$0.labelTextStyle = .bodySmall $0.textStyle = .bodySmall
$0.tooltipYOffset = -2
} }
open var errorLabel = Label().with { open var errorLabel = Label().with {
@ -130,11 +129,11 @@ open class EntryField: Control, Changeable {
$0.size = .small $0.size = .small
} }
open var labelText: String? { didSet { didChange() }} open var labelText: String? { didSet { setNeedsUpdate() }}
open var helperText: String? { didSet { didChange() }} open var helperText: String? { didSet { setNeedsUpdate() }}
open var showError: Bool = false { didSet { didChange() }} open var showError: Bool = false { didSet { setNeedsUpdate() }}
open override var state: UIControl.State { open override var state: UIControl.State {
get { get {
@ -146,27 +145,27 @@ open class EntryField: Control, Changeable {
} }
} }
open var errorText: String? { didSet { didChange() }} open var errorText: String? { didSet { setNeedsUpdate() }}
open var tooltipTitle: String? { didSet { didChange() }} open var tooltipTitle: String? { didSet { setNeedsUpdate() }}
open var tooltipContent: String? { didSet { didChange() }} open var tooltipContent: String? { didSet { setNeedsUpdate() }}
open var transparentBackground: Bool = false { didSet { didChange() }} open var transparentBackground: Bool = false { didSet { setNeedsUpdate() }}
open var width: CGFloat? { didSet { didChange() }} open var width: CGFloat? { didSet { setNeedsUpdate() }}
open var maxLength: Int? { didSet { didChange() }} open var maxLength: Int? { didSet { setNeedsUpdate() }}
open var inputId: String? { didSet { didChange() }} open var inputId: String? { didSet { setNeedsUpdate() }}
open var value: AnyHashable? { didSet { didChange() }} open var value: AnyHashable? { didSet { setNeedsUpdate() }}
open var defaultValue: AnyHashable? { didSet { didChange() }} open var defaultValue: AnyHashable? { didSet { setNeedsUpdate() }}
open var required: Bool = false { didSet { didChange() }} open var required: Bool = false { didSet { setNeedsUpdate() }}
open var readOnly: Bool = false { didSet { didChange() }} open var readOnly: Bool = false { didSet { setNeedsUpdate() }}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Constraints // MARK: - Constraints
@ -234,8 +233,8 @@ open class EntryField: Control, Changeable {
errorLabel.reset() errorLabel.reset()
helperLabel.reset() helperLabel.reset()
titleLabel.labelTextPosition = .left titleLabel.textPosition = .left
titleLabel.labelTextStyle = .bodySmall titleLabel.textStyle = .bodySmall
errorLabel.textPosition = .left errorLabel.textPosition = .left
errorLabel.textStyle = .bodySmall errorLabel.textStyle = .bodySmall
helperLabel.textPosition = .left helperLabel.textPosition = .left
@ -283,19 +282,23 @@ open class EntryField: Control, Changeable {
//dealing with the "Optional" addition to the text //dealing with the "Optional" addition to the text
if let oldText = updatedLabelText, !required, !oldText.hasSuffix("Optional") { if let oldText = updatedLabelText, !required, !oldText.hasSuffix("Optional") {
if !disabled {
let optionColorAttr = ColorLabelAttribute(location: oldText.count + 2, let optionColorAttr = ColorLabelAttribute(location: oldText.count + 2,
length: 8, length: 8,
color: .red) color: VDSColor.elementsSecondaryOnlight)
updatedLabelText = "\(oldText) Optional"
attributes.append(optionColorAttr) attributes.append(optionColorAttr)
} }
updatedLabelText = "\(oldText) Optional"
}
if let tooltipTitle, let tooltipContent {
attributes.append(TooltipLabelAttribute(surface: surface, title: tooltipTitle, content: tooltipContent))
}
//set the titleLabel //set the titleLabel
titleLabel.labelText = updatedLabelText titleLabel.text = updatedLabelText
titleLabel.labelAttributes = attributes titleLabel.attributes = attributes
titleLabel.tooltipTitle = tooltipTitle ?? ""
titleLabel.tooltipContent = tooltipContent ?? ""
titleLabel.surface = surface titleLabel.surface = surface
titleLabel.disabled = disabled titleLabel.disabled = disabled

View File

@ -51,7 +51,7 @@ open class InputField: EntryField, UITextFieldDelegate {
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------
open var type: FieldType = .text { didSet { didChange() }} open var type: FieldType = .text { didSet { setNeedsUpdate() }}
var _showError: Bool = false var _showError: Bool = false
open override var showError: Bool { open override var showError: Bool {
@ -59,7 +59,7 @@ open class InputField: EntryField, UITextFieldDelegate {
set { set {
if !showSuccess && _showError != newValue { if !showSuccess && _showError != newValue {
_showError = newValue _showError = newValue
didChange() setNeedsUpdate()
} }
} }
} }
@ -70,7 +70,7 @@ open class InputField: EntryField, UITextFieldDelegate {
set { set {
if !showError && _showSuccess != newValue { if !showError && _showSuccess != newValue {
_showSuccess = newValue _showSuccess = newValue
didChange() setNeedsUpdate()
} }
} }
} }
@ -85,9 +85,9 @@ open class InputField: EntryField, UITextFieldDelegate {
} }
} }
open var successText: String? { didSet { didChange() }} open var successText: String? { didSet { setNeedsUpdate() }}
open var helperTextPlacement: HelperTextPlacement = .bottom { didSet { didChange() }} open var helperTextPlacement: HelperTextPlacement = .bottom { didSet { setNeedsUpdate() }}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Properties // MARK: - Private Properties

View File

@ -77,7 +77,7 @@ open class TileContainer: Control {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------
public var backgroundImage: UIImage? { didSet{ didChange() } } public var backgroundImage: UIImage? { didSet{ setNeedsUpdate() } }
public var containerView = View().with { public var containerView = View().with {
$0.isUserInteractionEnabled = false $0.isUserInteractionEnabled = false
@ -87,13 +87,13 @@ open class TileContainer: Control {
$0.isUserInteractionEnabled = false $0.isUserInteractionEnabled = false
} }
public var color: BackgroundColor = .white { didSet{ didChange() } } public var color: BackgroundColor = .white { didSet{ setNeedsUpdate() } }
public var padding: Padding = .padding4X { didSet{ didChange() } } public var padding: Padding = .padding4X { didSet{ setNeedsUpdate() } }
public var aspectRatio: AspectRatio = .ratio1x1 { didSet{ didChange() } } public var aspectRatio: AspectRatio = .ratio1x1 { didSet{ setNeedsUpdate() } }
public var imageFallbackColor: Surface = .light { didSet{ didChange() } } public var imageFallbackColor: Surface = .light { didSet{ setNeedsUpdate() } }
private var _width: CGFloat? private var _width: CGFloat?
public var width: CGFloat? { public var width: CGFloat? {
@ -104,7 +104,7 @@ open class TileContainer: Control {
} else { } else {
_width = nil _width = nil
} }
didChange() setNeedsUpdate()
} }
} }
@ -117,13 +117,13 @@ open class TileContainer: Control {
} else { } else {
_height = nil _height = nil
} }
didChange() setNeedsUpdate()
} }
} }
public var showBorder: Bool = false { didSet{ didChange() } } public var showBorder: Bool = false { didSet{ setNeedsUpdate() } }
public var showDropShadows: Bool = false { didSet{ didChange() } } public var showDropShadows: Bool = false { didSet{ setNeedsUpdate() } }
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Properties // MARK: - Private Properties

View File

@ -153,7 +153,7 @@ open class Tilelet: TileContainer {
} else { } else {
_textWidth = nil _textWidth = nil
} }
didChange() setNeedsUpdate()
} }
} }
@ -170,16 +170,16 @@ open class Tilelet: TileContainer {
} else { } else {
_textPercentage = nil _textPercentage = nil
} }
didChange() setNeedsUpdate()
} }
} }
open var textPostion: TextPosition = .top { didSet { didChange() }} open var textPostion: TextPosition = .top { didSet { setNeedsUpdate() }}
//models //models
public var badgeModel: BadgeModel? { didSet { didChange() }} public var badgeModel: BadgeModel? { didSet { setNeedsUpdate() }}
public var titleModel: TitleModel? { didSet { didChange() }} public var titleModel: TitleModel? { didSet { setNeedsUpdate() }}
public var subTitleModel: SubTitleModel? { didSet { didChange() }} public var subTitleModel: SubTitleModel? { didSet { setNeedsUpdate() }}
//only 1 Icon can be active //only 1 Icon can be active
private var _descriptiveIconModel: DescriptiveIcon? private var _descriptiveIconModel: DescriptiveIcon?
@ -188,7 +188,7 @@ open class Tilelet: TileContainer {
set { set {
_descriptiveIconModel = newValue; _descriptiveIconModel = newValue;
_directionalIconModel = nil _directionalIconModel = nil
didChange() setNeedsUpdate()
} }
} }
@ -198,7 +198,7 @@ open class Tilelet: TileContainer {
set { set {
_directionalIconModel = newValue; _directionalIconModel = newValue;
_descriptiveIconModel = nil _descriptiveIconModel = nil
didChange() setNeedsUpdate()
} }
} }
//icons //icons

View File

@ -173,28 +173,28 @@ open class TitleLockup: View {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------
open var textPosition: TextPosition = .left { didSet { didChange() }} open var textPosition: TextPosition = .left { didSet { setNeedsUpdate() }}
//style //style
open var otherTextStyle: OtherTextStyle = UIDevice.isIPad ? .bodyLarge : .bodyMedium { didSet { didChange() }} open var otherTextStyle: OtherTextStyle = UIDevice.isIPad ? .bodyLarge : .bodyMedium { didSet { setNeedsUpdate() }}
//first row //first row
open var eyebrowLabel = Label().with { open var eyebrowLabel = Label().with {
$0.setContentCompressionResistancePriority(.required, for: .vertical) $0.setContentCompressionResistancePriority(.required, for: .vertical)
} }
open var eyebrowModel: EyebrowModel? { didSet { didChange() }} open var eyebrowModel: EyebrowModel? { didSet { setNeedsUpdate() }}
//second row //second row
open var titleLabel = Label().with { open var titleLabel = Label().with {
$0.setContentCompressionResistancePriority(.required, for: .vertical) $0.setContentCompressionResistancePriority(.required, for: .vertical)
} }
open var titleModel: TitleModel? { didSet { didChange() }} open var titleModel: TitleModel? { didSet { setNeedsUpdate() }}
//third row //third row
open var subTitleLabel = Label().with { open var subTitleLabel = Label().with {
$0.setContentCompressionResistancePriority(.required, for: .vertical) $0.setContentCompressionResistancePriority(.required, for: .vertical)
} }
open var subTitleModel: SubTitleModel? { didSet { didChange() }} open var subTitleModel: SubTitleModel? { didSet { setNeedsUpdate() }}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Lifecycle // MARK: - Lifecycle

View File

@ -125,27 +125,27 @@ open class Toggle: Control, Changeable {
if isSelected != newValue { if isSelected != newValue {
isSelected = newValue isSelected = newValue
} }
didChange() setNeedsUpdate()
} }
} }
open var isAnimated: Bool = true { didSet { didChange() }} open var isAnimated: Bool = true { didSet { setNeedsUpdate() }}
open var showText: Bool = false { didSet { didChange() }} open var showText: Bool = false { didSet { setNeedsUpdate() }}
open var onText: String = "On" { didSet { didChange() }} open var onText: String = "On" { didSet { setNeedsUpdate() }}
open var offText: String = "Off" { didSet { didChange() }} open var offText: String = "Off" { didSet { setNeedsUpdate() }}
open var textSize: TextSize = .small { didSet { didChange() }} open var textSize: TextSize = .small { didSet { setNeedsUpdate() }}
open var textWeight: TextWeight = .regular { didSet { didChange() }} open var textWeight: TextWeight = .regular { didSet { setNeedsUpdate() }}
open var textPosition: TextPosition = .left { didSet { didChange() }} open var textPosition: TextPosition = .left { didSet { setNeedsUpdate() }}
open var inputId: String? { didSet { didChange() }} open var inputId: String? { didSet { setNeedsUpdate() }}
open var value: AnyHashable? { didSet { didChange() }} open var value: AnyHashable? { didSet { setNeedsUpdate() }}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Constraints // MARK: - Constraints

View File

@ -44,15 +44,15 @@ open class Tooltip: Control, TooltipLaunchable {
$0.clipsToBounds = true $0.clipsToBounds = true
} }
open var closeButtonText: String = "Close" { didSet { didChange() }} open var closeButtonText: String = "Close" { didSet { setNeedsUpdate() }}
open var fillColor: FillColor = .primary { didSet { didChange() }} open var fillColor: FillColor = .primary { didSet { setNeedsUpdate() }}
open var size: Size = .medium { didSet { didChange() }} open var size: Size = .medium { didSet { setNeedsUpdate() }}
open var title: String = "" { didSet { didChange() }} open var title: String = "" { didSet { setNeedsUpdate() }}
open var content: String = "" { didSet { didChange() }} open var content: String = "" { didSet { setNeedsUpdate() }}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Configuration // MARK: - Configuration

View File

@ -22,25 +22,25 @@ open class TrailingTooltipLabel: View, TooltipLaunchable {
//-------------------------------------------------- //--------------------------------------------------
open var label = Label() open var label = Label()
open var labelText: String? { didSet { didChange() }} open var labelText: String? { didSet { setNeedsUpdate() }}
open var labelAttributes: [any LabelAttributeModel]? { didSet { didChange() } } open var labelAttributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() } }
open var labelTextStyle: TextStyle = .defaultStyle { didSet { didChange() } } open var labelTextStyle: TextStyle = .defaultStyle { didSet { setNeedsUpdate() } }
open var labelTextPosition: TextPosition = .left { didSet { didChange() } } open var labelTextPosition: TextPosition = .left { didSet { setNeedsUpdate() } }
public lazy var textColorConfiguration: AnyColorable = { public lazy var textColorConfiguration: AnyColorable = {
label.textColorConfiguration label.textColorConfiguration
}() { didSet { didChange() }} }() { didSet { setNeedsUpdate() }}
open var tooltipCloseButtonText: String = "Close" { didSet { didChange() } } open var tooltipCloseButtonText: String = "Close" { didSet { setNeedsUpdate() } }
open var tooltipTitle: String = "" { didSet { didChange() } } open var tooltipTitle: String = "" { didSet { setNeedsUpdate() } }
open var tooltipContent: String = "" { didSet { didChange() } } open var tooltipContent: String = "" { didSet { setNeedsUpdate() } }
open var tooltipYOffset: CGFloat = 0 { didSet { didChange() } } open var tooltipYOffset: CGFloat = 0 { didSet { setNeedsUpdate() } }
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Overrides // MARK: - Overrides
//-------------------------------------------------- //--------------------------------------------------

View File

@ -10,35 +10,18 @@ import Combine
import UIKit import UIKit
public protocol Handlerable: AnyObject, Initable, Disabling, Surfaceable { public protocol Handlerable: AnyObject, Initable, Disabling, Surfaceable {
var subject: PassthroughSubject<Void, Never> { get set }
var subscribers: Set<AnyCancellable> { get set } var subscribers: Set<AnyCancellable> { get set }
var shouldUpdateView: Bool { get set }
func updateView() func updateView()
} }
extension Handlerable { extension Handlerable {
public func setNeedsUpdate() {
public func setupDidChangeEvent(_ debounce: Bool = false) { if shouldUpdateView {
handlerPublisher(debounce) shouldUpdateView = false
.sink { [weak self] _ in updateView()
self?.updateView() shouldUpdateView = true
}.store(in: &subscribers)
} }
public func handlerPublisher(_ debounce: Bool = false) -> AnyPublisher<Void, Never> {
if debounce {
return subject
.debounce(for: .seconds(Constants.StateDebounce), scheduler: RunLoop.main)
.eraseToAnyPublisher()
} else {
return subject
.eraseToAnyPublisher()
}
}
}
extension Handlerable where Self: UIView {
public func didChange() {
subject.send()
} }
} }