added new updateStrategy

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-07-14 11:53:57 -05:00
parent a8e1cf9b48
commit d159075f83
5 changed files with 28 additions and 14 deletions

View File

@ -142,10 +142,11 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
//--------------------------------------------------
open override func didMoveToWindow() {
super.didMoveToWindow()
if window != nil {
print("sss - \(Self.self) changed to delayed update strategy")
updateStrategy = .delayed
}
// Keep the strategy if it's 'alwaysImmediate'
guard updateStrategy != .alwaysImmediate else { return }
// Update the strategy based on whether the view is in a window
updateStrategy = window == nil ? .delayed : .immediate
}
/// Update this view based off of property changes

View File

@ -74,9 +74,11 @@ open class View: UIView, Handlerable, ViewProtocol, Resettable, UserInfoable {
//--------------------------------------------------
open override func didMoveToWindow() {
super.didMoveToWindow()
if window != nil {
updateStrategy = .delayed
}
// Keep the strategy if it's 'alwaysImmediate'
guard updateStrategy != .alwaysImmediate else { return }
// Update the strategy based on whether the view is in a window
updateStrategy = window == nil ? .delayed : .immediate
}
/// Update this view based off of property changes

View File

@ -151,9 +151,11 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
//--------------------------------------------------
open override func didMoveToWindow() {
super.didMoveToWindow()
if window != nil {
updateStrategy = .delayed
}
// Keep the strategy if it's 'alwaysImmediate'
guard updateStrategy != .alwaysImmediate else { return }
// Update the strategy based on whether the view is in a window
updateStrategy = window == nil ? .delayed : .immediate
}
override open var intrinsicContentSize: CGSize {

View File

@ -110,9 +110,11 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable {
//--------------------------------------------------
open override func didMoveToWindow() {
super.didMoveToWindow()
if window != nil {
updateStrategy = .delayed
}
// Keep the strategy if it's 'alwaysImmediate'
guard updateStrategy != .alwaysImmediate else { return }
// Update the strategy based on whether the view is in a window
updateStrategy = window == nil ? .delayed : .immediate
}
open func updateView() {

View File

@ -12,6 +12,7 @@ import UIKit
public enum HandlerableUpdateStrategy {
case immediate
case delayed
case alwaysImmediate
}
public protocol Handlerable: AnyObject, Initable, Disabling, Surfaceable {
@ -40,10 +41,16 @@ extension Handlerable {
switch updateStrategy {
case .delayed:
delayedSubject.send()
case .immediate:
case .immediate, .alwaysImmediate:
immediateSubject.send()
}
}
public func updateIfNeeded<T: Equatable>(_ oldValue: T, _ newValue: T) {
if oldValue != newValue {
setNeedsUpdate()
}
}
}
extension Handlerable where Self: UIControl {