updated with traversal
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
c41599578a
commit
952d688cc2
@ -9,10 +9,28 @@ import Foundation
|
||||
import UIKit
|
||||
import Combine
|
||||
|
||||
public protocol ParentViewProtocol {
|
||||
public protocol ParentViewProtocol: ViewProtocol {
|
||||
var children: [any ViewProtocol] { get }
|
||||
}
|
||||
|
||||
extension ParentViewProtocol {
|
||||
public func getAllChildren() -> [any ViewProtocol] {
|
||||
var allChildren = [any ViewProtocol]()
|
||||
|
||||
func traverse(view: any ViewProtocol) {
|
||||
if let parentView = view as? any ParentViewProtocol {
|
||||
for child in parentView.children {
|
||||
allChildren.append(child)
|
||||
traverse(view: child)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
traverse(view: self)
|
||||
return children
|
||||
}
|
||||
}
|
||||
|
||||
public protocol ViewProtocol: AnyObject, Initable, Resettable, Enabling, Surfaceable, AccessibilityUpdatable {
|
||||
/// Set of Subscribers for any Publishers for this Control.
|
||||
var subscribers: Set<AnyCancellable> { get set }
|
||||
@ -42,11 +60,19 @@ extension ViewProtocol {
|
||||
public func setNeedsUpdate() {
|
||||
if shouldUpdateView {
|
||||
shouldUpdateView = false
|
||||
let parent = self as? ParentViewProtocol
|
||||
parent?.children.forEach{ $0.shouldUpdateView = false }
|
||||
|
||||
//see if this is a view that has children
|
||||
let parent = self as? any ParentViewProtocol
|
||||
let children = parent?.getAllChildren()
|
||||
//if so turn off the shouldUpdate to keep UI
|
||||
//from blocking
|
||||
children?.forEach{ $0.shouldUpdateView = false }
|
||||
|
||||
updateView()
|
||||
updateAccessibility()
|
||||
parent?.children.forEach{
|
||||
|
||||
//if so turn on
|
||||
children?.forEach{
|
||||
$0.updateView()
|
||||
$0.updateAccessibility()
|
||||
$0.shouldUpdateView = true
|
||||
|
||||
Loading…
Reference in New Issue
Block a user