added new updateStrategy
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
a8e1cf9b48
commit
d159075f83
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user