refactored out layout subviews, causing infinite loop

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-11-02 11:04:34 -05:00
parent 2f0600eafb
commit 85337833d4
5 changed files with 32 additions and 36 deletions

View File

@ -66,6 +66,7 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable {
if !initialSetupPerformed {
initialSetupPerformed = true
setup()
setupDidChangeEvent()
}
}
@ -79,11 +80,6 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable {
//--------------------------------------------------
// MARK: - Overrides
//--------------------------------------------------
open override func layoutSubviews() {
super.layoutSubviews()
updateView()
}
open func updateView() {}
open func reset() {

View File

@ -65,14 +65,10 @@ open class View: UIView, Handlerable, ViewProtocol, Resettable {
if !initialSetupPerformed {
initialSetupPerformed = true
setup()
setupDidChangeEvent()
}
}
open override func layoutSubviews() {
super.layoutSubviews()
updateView()
}
//--------------------------------------------------
// MARK: - Overrides
//--------------------------------------------------

View File

@ -31,7 +31,8 @@ open class Button: UIButton, Handlerable, ViewProtocol, Resettable, Useable {
private var minWidthConstraint: NSLayoutConstraint?
private var widthConstraint: NSLayoutConstraint?
private var heightConstraint: NSLayoutConstraint?
private var initialSetupPerformed = false
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
@ -120,11 +121,14 @@ open class Button: UIButton, Handlerable, ViewProtocol, Resettable, Useable {
// MARK: - Public Functions
//--------------------------------------------------
open func initialSetup() {
backgroundColor = .clear
translatesAutoresizingMaskIntoConstraints = false
accessibilityCustomActions = []
accessibilityTraits = .staticText
setup()
if !initialSetupPerformed {
backgroundColor = .clear
translatesAutoresizingMaskIntoConstraints = false
accessibilityCustomActions = []
accessibilityTraits = .staticText
setup()
setupDidChangeEvent()
}
}
open func setup() {
@ -150,11 +154,6 @@ open class Button: UIButton, Handlerable, ViewProtocol, Resettable, Useable {
accessibilityCustomActions = []
accessibilityTraits = .staticText
}
open override func layoutSubviews() {
super.layoutSubviews()
updateView()
}
//--------------------------------------------------
// MARK: - Overrides

View File

@ -26,11 +26,13 @@ open class LabelBase: UILabel, Handlerable, ViewProtocol, Resettable {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
private var initialSetupPerformed = false
open var surface: Surface = .light { didSet { didChange() }}
open var disabled: Bool = false { didSet { isEnabled = !disabled } }
open var attributes: [any LabelAttributeModel]? { didSet { didChange() }}
open var attributes: [any LabelAttributeModel]? { didSet { didChange() }}
open var typograpicalStyle: TypographicalStyle = .defaultStyle { didSet { didChange() }}
@ -85,13 +87,16 @@ open class LabelBase: UILabel, Handlerable, ViewProtocol, Resettable {
// MARK: - Public Functions
//--------------------------------------------------
open func initialSetup() {
backgroundColor = .clear
numberOfLines = 0
lineBreakMode = .byWordWrapping
translatesAutoresizingMaskIntoConstraints = false
accessibilityCustomActions = []
accessibilityTraits = .staticText
setup()
if !initialSetupPerformed {
backgroundColor = .clear
numberOfLines = 0
lineBreakMode = .byWordWrapping
translatesAutoresizingMaskIntoConstraints = false
accessibilityCustomActions = []
accessibilityTraits = .staticText
setup()
setupDidChangeEvent()
}
}
open func setup() {}
@ -111,12 +116,7 @@ open class LabelBase: UILabel, Handlerable, ViewProtocol, Resettable {
//--------------------------------------------------
// MARK: - Overrides
//--------------------------------------------------
open override func layoutSubviews() {
super.layoutSubviews()
updateView()
}
//--------------------------------------------------
open func updateView() {
textAlignment = textPosition.textAlignment
textColor = textColorConfiguration.getColor(self)

View File

@ -17,6 +17,12 @@ public protocol Handlerable: AnyObject, Initable, Disabling, Surfaceable {
extension Handlerable {
public func setupDidChangeEvent() {
handlerPublisher().sink { [weak self] _ in
self?.updateView()
}.store(in: &subscribers)
}
public func handlerPublisher() -> AnyPublisher<Void, Never> {
subject
.eraseToAnyPublisher()
@ -28,6 +34,5 @@ extension Handlerable {
extension Handlerable where Self: UIView {
public func didChange() {
subject.send()
setNeedsLayout()
}
}