Compare commits

...

3 Commits

Author SHA1 Message Date
Matt Bruce
bcdf4e309e Merge branch 'develop' of https://gitlab.verizon.com/BPHV_MIPS/vds_ios.git into refactor/dispatchQueue 2023-09-13 08:10:28 -05:00
Matt Bruce
e1c6cb6704 enforced dispatchQueue on classes
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-09-08 09:57:13 -05:00
Matt Bruce
4154aeda50 added dispatchQueueWorkItem
removed shouldUpdateView bool

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-09-08 09:24:34 -05:00
20 changed files with 35 additions and 80 deletions

View File

@ -11,7 +11,7 @@ import Combine
/// Base Class use to build Controls. /// Base Class use to build Controls.
@objc(VDSControl) @objc(VDSControl)
open class Control: UIControl, ViewProtocol, UserInfoable, Clickable { open class Control: UIControl, ViewProtocol, DispatchQueueViewProtocol, UserInfoable, Clickable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializers // MARK: - Initializers
//-------------------------------------------------- //--------------------------------------------------
@ -46,13 +46,13 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Properties // MARK: - Private Properties
//-------------------------------------------------- //--------------------------------------------------
internal var updateWorkItem: DispatchWorkItem?
private var initialSetupPerformed = false private var initialSetupPerformed = false
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------
open var shouldUpdateView: Bool = true
open var userInfo = [String: Primitive]() open var userInfo = [String: Primitive]()
open var surface: Surface = .light { didSet { setNeedsUpdate() } } open var surface: Surface = .light { didSet { setNeedsUpdate() } }

View File

@ -205,7 +205,6 @@ open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable,
/// Resets to default settings. /// Resets to default settings.
open override func reset() { open override func reset() {
super.reset() super.reset()
shouldUpdateView = false
label.reset() label.reset()
childLabel.reset() childLabel.reset()
errorLabel.reset() errorLabel.reset()
@ -225,9 +224,6 @@ open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable,
inputId = nil inputId = nil
value = nil value = nil
isSelected = false isSelected = false
shouldUpdateView = true
setNeedsUpdate()
} }
//-------------------------------------------------- //--------------------------------------------------

View File

@ -11,7 +11,7 @@ import Combine
/// Base Class used to build Views. /// Base Class used to build Views.
@objc(VDSView) @objc(VDSView)
open class View: UIView, ViewProtocol, UserInfoable { open class View: UIView, ViewProtocol, DispatchQueueViewProtocol, UserInfoable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializers // MARK: - Initializers
@ -39,13 +39,13 @@ open class View: UIView, ViewProtocol, UserInfoable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Properties // MARK: - Private Properties
//-------------------------------------------------- //--------------------------------------------------
internal var updateWorkItem: DispatchWorkItem?
private var initialSetupPerformed = false private var initialSetupPerformed = false
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------
open var shouldUpdateView: Bool = true
/// Dictionary for keeping information for this Control use only Primitives. /// Dictionary for keeping information for this Control use only Primitives.
open var userInfo = [String: Primitive]() open var userInfo = [String: Primitive]()

View File

@ -150,7 +150,6 @@ open class Badge: View {
/// Resets to default settings. /// Resets to default settings.
open override func reset() { open override func reset() {
super.reset() super.reset()
shouldUpdateView = false
label.reset() label.reset()
label.lineBreakMode = .byTruncatingTail label.lineBreakMode = .byTruncatingTail
label.textStyle = .boldBodySmall label.textStyle = .boldBodySmall
@ -158,8 +157,6 @@ open class Badge: View {
text = "" text = ""
maxWidth = nil maxWidth = nil
numberOfLines = 1 numberOfLines = 1
shouldUpdateView = true
setNeedsUpdate()
} }
/// Used to make changes to the View based off a change events or from local properties. /// Used to make changes to the View based off a change events or from local properties.

View File

@ -296,14 +296,11 @@ open class BadgeIndicator: View {
/// Resets to default settings. /// Resets to default settings.
open override func reset() { open override func reset() {
super.reset() super.reset()
shouldUpdateView = false
label.reset() label.reset()
label.lineBreakMode = .byTruncatingTail label.lineBreakMode = .byTruncatingTail
label.textAlignment = .center label.textAlignment = .center
fillColor = .red fillColor = .red
number = nil number = nil
shouldUpdateView = true
setNeedsUpdate()
} }
/// Used to make changes to the View based off a change events or from local properties. /// Used to make changes to the View based off a change events or from local properties.

View File

@ -155,12 +155,9 @@ open class Button: ButtonBase, Useable, Buttonable {
/// Resets to default settings. /// Resets to default settings.
open override func reset() { open override func reset() {
super.reset() super.reset()
shouldUpdateView = false
use = .primary use = .primary
width = nil width = nil
size = .large size = .large
shouldUpdateView = true
setNeedsUpdate()
} }
/// Used to make changes to the View based off a change events or from local properties. /// Used to make changes to the View based off a change events or from local properties.

View File

@ -25,7 +25,7 @@ public protocol Buttonable: UIControl, Surfaceable, Enabling {
/// Base class used for UIButton type classes. /// Base class used for UIButton type classes.
@objc(VDSButtonBase) @objc(VDSButtonBase)
open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable { open class ButtonBase: UIButton, ViewProtocol, DispatchQueueViewProtocol, UserInfoable, Clickable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializers // MARK: - Initializers
@ -67,14 +67,13 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Properties // MARK: - Private Properties
//-------------------------------------------------- //--------------------------------------------------
internal var updateWorkItem: DispatchWorkItem?
private var initialSetupPerformed = false private var initialSetupPerformed = false
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Properties // MARK: - Properties
//-------------------------------------------------- //--------------------------------------------------
/// Key of whether or not updateView() is called in setNeedsUpdate()
open var shouldUpdateView: Bool = true
/// The ButtonSize available to this type of Buttonable. /// The ButtonSize available to this type of Buttonable.
open var availableSizes: [ButtonSize] { [] } open var availableSizes: [ButtonSize] { [] }
@ -156,13 +155,10 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable {
} }
open func reset() { open func reset() {
shouldUpdateView = false
surface = .light surface = .light
isEnabled = true isEnabled = true
text = nil text = nil
accessibilityCustomActions = [] accessibilityCustomActions = []
shouldUpdateView = true
setNeedsUpdate()
} }
//-------------------------------------------------- //--------------------------------------------------

View File

@ -113,14 +113,11 @@ open class TextLink: ButtonBase, Buttonable {
/// Resets to default settings. /// Resets to default settings.
open override func reset() { open override func reset() {
super.reset() super.reset()
shouldUpdateView = false
text = nil text = nil
size = .large size = .large
accessibilityCustomActions = [] accessibilityCustomActions = []
isAccessibilityElement = true isAccessibilityElement = true
accessibilityTraits = .link accessibilityTraits = .link
shouldUpdateView = true
setNeedsUpdate()
} }
} }

View File

@ -280,7 +280,6 @@ open class ButtonIcon: Control {
/// Resets to default settings. /// Resets to default settings.
open override func reset() { open override func reset() {
super.reset() super.reset()
shouldUpdateView = false
kind = .ghost kind = .ghost
surfaceType = .colorFill surfaceType = .colorFill
size = .large size = .large
@ -288,8 +287,6 @@ open class ButtonIcon: Control {
hideBorder = true hideBorder = true
iconOffset = .init(x: 0, y: 0) iconOffset = .init(x: 0, y: 0)
iconName = nil iconName = nil
shouldUpdateView = true
setNeedsUpdate()
} }
/// Used to make changes to the View based off a change events or from local properties. /// Used to make changes to the View based off a change events or from local properties.

View File

@ -13,7 +13,7 @@ import Combine
/// Label is a standard view used to draw text with applying Typography through ``TextStyle`` as well /// Label is a standard view used to draw text with applying Typography through ``TextStyle`` as well
/// as other attributes using any implemetation of ``LabelAttributeModel``. /// as other attributes using any implemetation of ``LabelAttributeModel``.
@objc(VDSLabel) @objc(VDSLabel)
open class Label: UILabel, ViewProtocol, UserInfoable { open class Label: UILabel, ViewProtocol, DispatchQueueViewProtocol, UserInfoable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializers // MARK: - Initializers
@ -42,6 +42,8 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Properties // MARK: - Private Properties
//-------------------------------------------------- //--------------------------------------------------
internal var updateWorkItem: DispatchWorkItem?
private var initialSetupPerformed = false private var initialSetupPerformed = false
private var edgeInsets: UIEdgeInsets { textStyle.edgeInsets } private var edgeInsets: UIEdgeInsets { textStyle.edgeInsets }
@ -100,9 +102,6 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------
/// Key of whether or not updateView() is called in setNeedsUpdate()
open var shouldUpdateView: Bool = true
/// Determines if the label should use its own attributedText property instead of rendering the attributedText propert /// Determines if the label should use its own attributedText property instead of rendering the attributedText propert
/// based of other local properties, such as textStyle, textColor, surface, etc... The default value is false. /// based of other local properties, such as textStyle, textColor, surface, etc... The default value is false.
open var useAttributedText: Bool = false open var useAttributedText: Bool = false
@ -184,7 +183,6 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
open func setup() {} open func setup() {}
open func reset() { open func reset() {
shouldUpdateView = false
surface = .light surface = .light
isEnabled = true isEnabled = true
attributes = nil attributes = nil
@ -194,8 +192,6 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
attributedText = nil attributedText = nil
numberOfLines = 0 numberOfLines = 0
backgroundColor = .clear backgroundColor = .clear
shouldUpdateView = true
setNeedsUpdate()
} }
open func updateView() { open func updateView() {

View File

@ -255,8 +255,6 @@ open class Notification: View {
open override func reset() { open override func reset() {
super.reset() super.reset()
shouldUpdateView = false
titleLabel.reset() titleLabel.reset()
titleLabel.text = "" titleLabel.text = ""
titleLabel.textStyle = UIDevice.isIPad ? .boldBodyLarge : .boldBodySmall titleLabel.textStyle = UIDevice.isIPad ? .boldBodyLarge : .boldBodySmall
@ -280,9 +278,6 @@ open class Notification: View {
layout = .vertical layout = .vertical
hideCloseButton = false hideCloseButton = false
shouldUpdateView = true
setNeedsUpdate()
} }
/// Used to make changes to the View based off a change events or from local properties. /// Used to make changes to the View based off a change events or from local properties.

View File

@ -206,7 +206,6 @@ open class RadioBoxItem: Control, Changeable, FormFieldable {
/// Resets to default settings. /// Resets to default settings.
open override func reset() { open override func reset() {
super.reset() super.reset()
shouldUpdateView = false
textLabel.reset() textLabel.reset()
subTextLabel.reset() subTextLabel.reset()
subTextRightLabel.reset() subTextRightLabel.reset()
@ -229,9 +228,6 @@ open class RadioBoxItem: Control, Changeable, FormFieldable {
value = nil value = nil
isSelected = false isSelected = false
shouldUpdateView = true
setNeedsUpdate()
} }
/// This will change the state of the Selector and execute the actionBlock if provided. /// This will change the state of the Selector and execute the actionBlock if provided.

View File

@ -234,7 +234,6 @@ open class TileContainer: Control {
/// Resets to default settings. /// Resets to default settings.
open override func reset() { open override func reset() {
super.reset() super.reset()
shouldUpdateView = false
color = .white color = .white
padding = .padding4X padding = .padding4X
aspectRatio = .ratio1x1 aspectRatio = .ratio1x1
@ -243,8 +242,6 @@ open class TileContainer: Control {
height = nil height = nil
showBorder = false showBorder = false
showDropShadows = false showDropShadows = false
shouldUpdateView = true
setNeedsUpdate()
} }
/// Used to make changes to the View based off a change events or from local properties. /// Used to make changes to the View based off a change events or from local properties.

View File

@ -253,7 +253,6 @@ open class Tilelet: TileContainer {
/// Resets to default settings. /// Resets to default settings.
open override func reset() { open override func reset() {
shouldUpdateView = false
aspectRatio = .none aspectRatio = .none
color = .black color = .black
//models //models
@ -262,8 +261,6 @@ open class Tilelet: TileContainer {
subTitleModel = nil subTitleModel = nil
descriptiveIconModel = nil descriptiveIconModel = nil
directionalIconModel = nil directionalIconModel = nil
shouldUpdateView = true
setNeedsUpdate()
} }
/// Used to make changes to the View based off a change events or from local properties. /// Used to make changes to the View based off a change events or from local properties.

View File

@ -274,12 +274,9 @@ open class TitleLockup: View {
/// Resets to default settings. /// Resets to default settings.
open override func reset() { open override func reset() {
super.reset() super.reset()
shouldUpdateView = false
eyebrowModel = nil eyebrowModel = nil
titleModel = nil titleModel = nil
subTitleModel = nil subTitleModel = nil
shouldUpdateView = true
setNeedsUpdate()
} }
var labelViews = [UIView]() var labelViews = [UIView]()

View File

@ -216,7 +216,6 @@ open class Toggle: Control, Changeable, FormFieldable {
/// Resets to default settings. /// Resets to default settings.
open override func reset() { open override func reset() {
super.reset() super.reset()
shouldUpdateView = false
label.reset() label.reset()
isEnabled = true isEnabled = true
isOn = false isOn = false
@ -229,8 +228,6 @@ open class Toggle: Control, Changeable, FormFieldable {
textPosition = .left textPosition = .left
inputId = nil inputId = nil
value = nil value = nil
shouldUpdateView = true
setNeedsUpdate()
} }
/// Used to make changes to the View based off a change events or from local properties. /// Used to make changes to the View based off a change events or from local properties.

View File

@ -155,15 +155,12 @@ open class ToggleView: Control, Changeable, FormFieldable {
/// Resets to default settings. /// Resets to default settings.
open override func reset() { open override func reset() {
super.reset() super.reset()
shouldUpdateView = false
isOn = false isOn = false
isAnimated = true isAnimated = true
inputId = nil inputId = nil
value = nil value = nil
toggleView.backgroundColor = toggleColorConfiguration.getColor(self) toggleView.backgroundColor = toggleColorConfiguration.getColor(self)
knobView.backgroundColor = knobColorConfiguration.getColor(self) knobView.backgroundColor = knobColorConfiguration.getColor(self)
shouldUpdateView = true
setNeedsUpdate()
} }
/// Used to make changes to the View based off a change events or from local properties. /// Used to make changes to the View based off a change events or from local properties.

View File

@ -145,14 +145,11 @@ open class Tooltip: Control, TooltipLaunchable {
/// Resets to default settings. /// Resets to default settings.
open override func reset() { open override func reset() {
super.reset() super.reset()
shouldUpdateView = false
size = .medium size = .medium
title = "" title = ""
content = "" content = ""
fillColor = .primary fillColor = .primary
closeButtonText = "Close" closeButtonText = "Close"
shouldUpdateView = true
setNeedsUpdate()
} }
/// Used to make changes to the View based off a change events or from local properties. /// Used to make changes to the View based off a change events or from local properties.

View File

@ -110,7 +110,6 @@ open class TrailingTooltipLabel: View, TooltipLaunchable {
/// Resets to default settings. /// Resets to default settings.
open override func reset() { open override func reset() {
super.reset() super.reset()
shouldUpdateView = false
labelText = nil labelText = nil
labelAttributes = nil labelAttributes = nil
labelTextStyle = .defaultStyle labelTextStyle = .defaultStyle
@ -118,8 +117,6 @@ open class TrailingTooltipLabel: View, TooltipLaunchable {
tooltipCloseButtonText = "Close" tooltipCloseButtonText = "Close"
tooltipTitle = "" tooltipTitle = ""
tooltipContent = "" tooltipContent = ""
shouldUpdateView = true
setNeedsUpdate()
} }
} }

View File

@ -9,13 +9,14 @@ import Foundation
import UIKit import UIKit
import Combine import Combine
internal protocol DispatchQueueViewProtocol: AnyObject {
var updateWorkItem: DispatchWorkItem? { get set }
}
public protocol ViewProtocol: AnyObject, Initable, Resettable, Enabling, Surfaceable { public protocol ViewProtocol: AnyObject, Initable, Resettable, Enabling, Surfaceable {
/// Set of Subscribers for any Publishers for this Control. /// Set of Subscribers for any Publishers for this Control.
var subscribers: Set<AnyCancellable> { get set } var subscribers: Set<AnyCancellable> { get set }
/// Key of whether or not updateView() is called in setNeedsUpdate()
var shouldUpdateView: Bool { get set }
/// Executed on initialization for this View. /// Executed on initialization for this View.
func initialSetup() func initialSetup()
@ -27,17 +28,28 @@ public protocol ViewProtocol: AnyObject, Initable, Resettable, Enabling, Surface
/// Used to update any Accessibility properties. /// Used to update any Accessibility properties.
func updateAccessibility() func updateAccessibility()
/// Called when there are changes in a View based off a change events or from local properties.
func setNeedsUpdate()
} }
extension ViewProtocol { extension ViewProtocol {
/// Called when there are changes in a View based off a change events or from local properties. private func doUpdate() {
updateView()
updateAccessibility()
}
public func setNeedsUpdate() { public func setNeedsUpdate() {
if shouldUpdateView { guard let dispatchQueueSelf = self as? DispatchQueueViewProtocol else {
shouldUpdateView = false doUpdate()
updateView() return
updateAccessibility()
shouldUpdateView = true
} }
dispatchQueueSelf.updateWorkItem?.cancel()
let workItem = DispatchWorkItem { [weak self] in
self?.doUpdate()
}
DispatchQueue.main.async(execute: workItem)
dispatchQueueSelf.updateWorkItem = workItem
} }
} }