added setDefaults() into protocol and implemented

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-08-09 14:35:51 -05:00
parent 0decdb5a16
commit 09886ffe26
7 changed files with 77 additions and 35 deletions

View File

@ -83,17 +83,25 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable {
initialSetupPerformed = true initialSetupPerformed = true
shouldUpdateView = false shouldUpdateView = false
setup() setup()
setDefaults()
shouldUpdateView = true shouldUpdateView = true
setNeedsUpdate() setNeedsUpdate()
} }
} }
open func setup() { open func setup() {
backgroundColor = .clear
translatesAutoresizingMaskIntoConstraints = false translatesAutoresizingMaskIntoConstraints = false
insetsLayoutMarginsFromSafeArea = false insetsLayoutMarginsFromSafeArea = false
} }
open func setDefaults() {
backgroundColor = .clear
surface = .light
isEnabled = true
onClick = nil
userInfo.removeAll()
}
open func updateView() { } open func updateView() { }
open func updateAccessibility() { open func updateAccessibility() {
@ -112,11 +120,10 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable {
} }
open func reset() { open func reset() {
backgroundColor = .clear shouldUpdateView = false
surface = .light setDefaults()
isEnabled = true shouldUpdateView = true
onClick = nil setNeedsUpdate()
userInfo.removeAll()
} }
//-------------------------------------------------- //--------------------------------------------------

View File

@ -62,17 +62,24 @@ open class View: UIView, ViewProtocol, UserInfoable {
initialSetupPerformed = true initialSetupPerformed = true
shouldUpdateView = false shouldUpdateView = false
setup() setup()
setDefaults()
shouldUpdateView = true shouldUpdateView = true
setNeedsUpdate() setNeedsUpdate()
} }
} }
open func setup() { open func setup() {
backgroundColor = .clear
translatesAutoresizingMaskIntoConstraints = false translatesAutoresizingMaskIntoConstraints = false
insetsLayoutMarginsFromSafeArea = false insetsLayoutMarginsFromSafeArea = false
} }
open func setDefaults() {
backgroundColor = .clear
surface = .light
isEnabled = true
userInfo.removeAll()
}
open func updateView() { } open func updateView() { }
open func updateAccessibility() { open func updateAccessibility() {
@ -84,9 +91,10 @@ open class View: UIView, ViewProtocol, UserInfoable {
} }
open func reset() { open func reset() {
backgroundColor = .clear shouldUpdateView = false
surface = .light setDefaults()
isEnabled = true shouldUpdateView = true
setNeedsUpdate()
} }
open override func layoutSubviews() { open override func layoutSubviews() {

View File

@ -102,6 +102,7 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable {
initialSetupPerformed = true initialSetupPerformed = true
shouldUpdateView = false shouldUpdateView = false
setup() setup()
setDefaults()
shouldUpdateView = true shouldUpdateView = true
setNeedsUpdate() setNeedsUpdate()
} }
@ -109,12 +110,20 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable {
open func setup() { open func setup() {
backgroundColor = .clear
translatesAutoresizingMaskIntoConstraints = false translatesAutoresizingMaskIntoConstraints = false
}
open func setDefaults() {
backgroundColor = .clear
accessibilityCustomActions = [] accessibilityCustomActions = []
titleLabel?.adjustsFontSizeToFitWidth = false titleLabel?.adjustsFontSizeToFitWidth = false
titleLabel?.lineBreakMode = .byTruncatingTail titleLabel?.lineBreakMode = .byTruncatingTail
titleLabel?.numberOfLines = 1 titleLabel?.numberOfLines = 1
surface = .light
isEnabled = true
text = nil
onClick = nil
userInfo.removeAll()
} }
open func updateView() { open func updateView() {
@ -131,12 +140,7 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable {
open func reset() { open func reset() {
shouldUpdateView = false shouldUpdateView = false
surface = .light setDefaults()
isEnabled = true
text = nil
accessibilityCustomActions = []
onClick = nil
userInfo.removeAll()
shouldUpdateView = true shouldUpdateView = true
setNeedsUpdate() setNeedsUpdate()
} }

View File

@ -197,6 +197,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
initialSetupPerformed = true initialSetupPerformed = true
shouldUpdateView = false shouldUpdateView = false
setup() setup()
setDefaults()
shouldUpdateView = true shouldUpdateView = true
setNeedsUpdate() setNeedsUpdate()
} }
@ -209,27 +210,28 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
.sink { [weak self] notification in .sink { [weak self] notification in
self?.setNeedsUpdate() self?.setNeedsUpdate()
}.store(in: &subscribers) }.store(in: &subscribers)
backgroundColor = .clear
numberOfLines = 0
lineBreakMode = .byTruncatingTail
translatesAutoresizingMaskIntoConstraints = false translatesAutoresizingMaskIntoConstraints = false
accessibilityCustomActions = []
isAccessibilityElement = true isAccessibilityElement = true
accessibilityTraits = .staticText
textAlignment = .left
} }
open func reset() { open func setDefaults() {
shouldUpdateView = false backgroundColor = .clear
accessibilityTraits = .staticText
accessibilityCustomActions = []
surface = .light surface = .light
isEnabled = true isEnabled = true
attributes = nil attributes = nil
textStyle = .defaultStyle textStyle = .defaultStyle
lineBreakMode = .byTruncatingTail
textAlignment = .left textAlignment = .left
text = nil text = nil
attributedText = nil attributedText = nil
numberOfLines = 0 numberOfLines = 0
backgroundColor = .clear }
open func reset() {
shouldUpdateView = false
setDefaults()
shouldUpdateView = true shouldUpdateView = true
setNeedsUpdate() setNeedsUpdate()
} }

View File

@ -103,13 +103,13 @@ open class TextField: UITextField, ViewProtocol, Errorable {
initialSetupPerformed = true initialSetupPerformed = true
shouldUpdateView = false shouldUpdateView = false
setup() setup()
setDefaults()
shouldUpdateView = true shouldUpdateView = true
setNeedsUpdate() setNeedsUpdate()
} }
} }
open func setup() { open func setup() {
backgroundColor = .clear
translatesAutoresizingMaskIntoConstraints = false translatesAutoresizingMaskIntoConstraints = false
setContentCompressionResistancePriority(.defaultLow, for: .horizontal) setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
clipsToBounds = true clipsToBounds = true
@ -127,6 +127,17 @@ open class TextField: UITextField, ViewProtocol, Errorable {
inputAccessoryView = accessView inputAccessoryView = accessView
} }
open func setDefaults() {
backgroundColor = .clear
surface = .light
text = nil
formatText = nil
useScaledFont = false
showError = false
errorText = nil
textStyle = .defaultStyle
}
@objc func doneButtonAction() { @objc func doneButtonAction() {
// Resigns the first responder status when 'Done' is tapped // Resigns the first responder status when 'Done' is tapped
let _ = resignFirstResponder() let _ = resignFirstResponder()
@ -177,8 +188,7 @@ open class TextField: UITextField, ViewProtocol, Errorable {
open func reset() { open func reset() {
shouldUpdateView = false shouldUpdateView = false
surface = .light setDefaults()
text = nil
shouldUpdateView = true shouldUpdateView = true
setNeedsUpdate() setNeedsUpdate()
} }

View File

@ -112,13 +112,13 @@ open class TextView: UITextView, ViewProtocol, Errorable {
initialSetupPerformed = true initialSetupPerformed = true
shouldUpdateView = false shouldUpdateView = false
setup() setup()
setDefaults()
shouldUpdateView = true shouldUpdateView = true
setNeedsUpdate() setNeedsUpdate()
} }
} }
open func setup() { open func setup() {
backgroundColor = .clear
translatesAutoresizingMaskIntoConstraints = false translatesAutoresizingMaskIntoConstraints = false
let accessView = UIView(frame: .init(origin: .zero, size: .init(width: UIScreen.main.bounds.width, height: 44))) let accessView = UIView(frame: .init(origin: .zero, size: .init(width: UIScreen.main.bounds.width, height: 44)))
@ -137,6 +137,15 @@ open class TextView: UITextView, ViewProtocol, Errorable {
placeholderLabel.pinToSuperView() placeholderLabel.pinToSuperView()
} }
open func setDefaults() {
backgroundColor = .clear
surface = .light
text = nil
placeholder = nil
errorText = nil
showError = false
}
@objc func doneButtonAction() { @objc func doneButtonAction() {
// Resigns the first responder status when 'Done' is tapped // Resigns the first responder status when 'Done' is tapped
resignFirstResponder() resignFirstResponder()
@ -156,8 +165,7 @@ open class TextView: UITextView, ViewProtocol, Errorable {
open func reset() { open func reset() {
shouldUpdateView = false shouldUpdateView = false
surface = .light setDefaults()
text = nil
shouldUpdateView = true shouldUpdateView = true
setNeedsUpdate() setNeedsUpdate()
} }

View File

@ -22,6 +22,9 @@ public protocol ViewProtocol: AnyObject, Initable, Resettable, Enabling, Surface
/// 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.
func setup() func setup()
/// Default configurations for values and properties. This is called in the setup() and reset().
func setDefaults()
/// 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.
func updateView() func updateView()