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

View File

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

View File

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

View File

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

View File

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