From 952d688cc2729fa8f16710bc5668b743e4eda0fe Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 23 Aug 2024 08:35:36 -0500 Subject: [PATCH] updated with traversal Signed-off-by: Matt Bruce --- VDS/Protocols/ViewProtocol.swift | 34 ++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/VDS/Protocols/ViewProtocol.swift b/VDS/Protocols/ViewProtocol.swift index e38d5df4..4eb091b1 100644 --- a/VDS/Protocols/ViewProtocol.swift +++ b/VDS/Protocols/ViewProtocol.swift @@ -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 { 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