refactor to reset onClick/onClick to nil

removed old willSet

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-04-24 14:49:23 -05:00
parent 3497807d1c
commit c22592cdb5
14 changed files with 33 additions and 66 deletions

View File

@ -35,13 +35,7 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable {
//--------------------------------------------------
open var subscribers = Set<AnyCancellable>()
open var onClickSubscriber: AnyCancellable? {
willSet {
if let onClickSubscriber {
onClickSubscriber.cancel()
}
}
}
open var onClickSubscriber: AnyCancellable?
//--------------------------------------------------
// MARK: - Private Properties
@ -118,6 +112,8 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable {
backgroundColor = .clear
surface = .light
isEnabled = true
onClick = nil
userInfo.removeAll()
}
//--------------------------------------------------

View File

@ -47,13 +47,7 @@ open class SelectorBase: Control, SelectorControlable {
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
open var onChangeSubscriber: AnyCancellable? {
willSet {
if let onChangeSubscriber {
onChangeSubscriber.cancel()
}
}
}
open var onChangeSubscriber: AnyCancellable?
open var size = CGSize(width: 20, height: 20) { didSet { setNeedsUpdate() } }
@ -135,4 +129,8 @@ open class SelectorBase: Control, SelectorControlable {
/// This will change the state of the Selector and execute the actionBlock if provided.
open func toggle() { }
open override func reset() {
super.reset()
onChange = nil
}
}

View File

@ -75,13 +75,7 @@ open class SelectorGroupBase<SelectorItemType: Control>: Control, SelectorGroup,
}
}
open var onChangeSubscriber: AnyCancellable? {
willSet {
if let onChangeSubscriber {
onChangeSubscriber.cancel()
}
}
}
open var onChangeSubscriber: AnyCancellable?
/// Whether the Control is enabled or not.
override open var isEnabled: Bool {
@ -130,6 +124,7 @@ open class SelectorGroupBase<SelectorItemType: Control>: Control, SelectorGroup,
/// Resets to default settings.
open override func reset() {
super.reset()
onChange = nil
items.forEach{ $0.reset() }
}
}

View File

@ -61,13 +61,7 @@ open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable,
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
open var onChangeSubscriber: AnyCancellable? {
willSet {
if let onChangeSubscriber {
onChangeSubscriber.cancel()
}
}
}
open var onChangeSubscriber: AnyCancellable?
/// Label used to render labelText.
open var label = Label().with {
@ -223,6 +217,7 @@ open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable,
value = nil
isSelected = false
onChange = nil
shouldUpdateView = true
setNeedsUpdate()
}

View File

@ -38,13 +38,7 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable {
/// Set of Subscribers for any Publishers for this Control.
open var subscribers = Set<AnyCancellable>()
open var onClickSubscriber: AnyCancellable? {
willSet {
if let onClickSubscriber {
onClickSubscriber.cancel()
}
}
}
open var onClickSubscriber: AnyCancellable?
//--------------------------------------------------
// MARK: - Private Properties
@ -140,6 +134,8 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable {
isEnabled = true
text = nil
accessibilityCustomActions = []
onClick = nil
userInfo.removeAll()
shouldUpdateView = true
setNeedsUpdate()
}

View File

@ -172,8 +172,6 @@ open class ButtonIcon: Control, Changeable, FormFieldable {
/// 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 onChangeSubscriber: AnyCancellable?
open var inputId: String? { didSet { setNeedsUpdate() } }
open var value: AnyHashable? { didSet { setNeedsUpdate() } }
@ -436,6 +434,7 @@ open class ButtonIcon: Control, Changeable, FormFieldable {
showBadgeIndicator = false
selectable = false
badgeIndicatorModel = nil
onChange = nil
shouldUpdateView = true
setNeedsUpdate()
}

View File

@ -52,13 +52,7 @@ open class RadioBoxItem: Control, Changeable, FormFieldable {
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
open var onChangeSubscriber: AnyCancellable? {
willSet {
if let onChangeSubscriber {
onChangeSubscriber.cancel()
}
}
}
open var onChangeSubscriber: AnyCancellable?
/// Label used to render the text.
open var textLabel = Label().with {
@ -218,6 +212,7 @@ open class RadioBoxItem: Control, Changeable, FormFieldable {
value = nil
isSelected = false
onChange = nil
shouldUpdateView = true
setNeedsUpdate()

View File

@ -119,13 +119,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
open var onChangeSubscriber: AnyCancellable? {
willSet {
if let onChangeSubscriber {
onChangeSubscriber.cancel()
}
}
}
open var onChangeSubscriber: AnyCancellable?
open var titleLabel = Label().with {
$0.setContentCompressionResistancePriority(.required, for: .vertical)
@ -304,6 +298,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
defaultValue = nil
required = false
readOnly = false
onChange = nil
}
/// Used to make changes to the View based off a change events or from local properties.

View File

@ -8,6 +8,7 @@
import Foundation
import VDSTokens
import UIKit
import Combine
@objc(VDSTileContainer)
open class TileContainer: TileContainerBase<TileContainer.Padding> {
@ -43,7 +44,6 @@ open class TileContainer: TileContainerBase<TileContainer.Padding> {
}
open class TileContainerBase<PaddingType: DefaultValuing>: Control where PaddingType.ValueType == CGFloat {
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
@ -111,6 +111,12 @@ open class TileContainerBase<PaddingType: DefaultValuing>: Control where Padding
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
public override var onClickSubscriber: AnyCancellable? {
didSet {
isAccessibilityElement = onClickSubscriber != nil
}
}
/// This takes an image source url and applies it as a background image.
open var backgroundImage: UIImage? { didSet { setNeedsUpdate() } }

View File

@ -105,12 +105,6 @@ open class Tilelet: TileContainerBase<Tilelet.Padding> {
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
public override var onClickSubscriber: AnyCancellable? {
didSet {
isAccessibilityElement = onClickSubscriber != nil
}
}
/// Title lockup positioned in the contentView.
open var titleLockup = TitleLockup().with {
$0.standardStyleConfiguration = .init(styleConfigurations: [

View File

@ -88,13 +88,7 @@ open class Toggle: Control, Changeable, FormFieldable {
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
open var onChangeSubscriber: AnyCancellable? {
willSet {
if let onChangeSubscriber {
onChangeSubscriber.cancel()
}
}
}
open var onChangeSubscriber: AnyCancellable?
/// Actual toggle used in this component.
open var toggleView = ToggleView().with {
@ -231,6 +225,7 @@ open class Toggle: Control, Changeable, FormFieldable {
textPosition = .left
inputId = nil
value = nil
onChange = nil
shouldUpdateView = true
setNeedsUpdate()
}

View File

@ -166,6 +166,7 @@ open class ToggleView: Control, Changeable, FormFieldable {
value = nil
toggleView.backgroundColor = toggleColorConfiguration.getColor(self)
knobView.backgroundColor = knobColorConfiguration.getColor(self)
onChange = nil
shouldUpdateView = true
setNeedsUpdate()
}

View File

@ -26,6 +26,8 @@ extension Changeable {
.sink { c in
newValue(c)
}
} else {
onChangeSubscriber = nil
}
}
}

View File

@ -20,6 +20,7 @@ extension Clickable {
public var onClick: ((Self) -> ())? {
get { return nil }
set {
onClickSubscriber?.cancel()
if let newValue {
onClickSubscriber = publisher(for: .touchUpInside)
.sink { [weak self] c in
@ -27,7 +28,6 @@ extension Clickable {
newValue(c)
}
} else {
onClickSubscriber?.cancel()
onClickSubscriber = nil
}
}