diff --git a/Sources/Model/User Interface/Scene/SceneStorage.swift b/Sources/Model/User Interface/Scene/SceneStorage.swift index f1c078a..1f26763 100644 --- a/Sources/Model/User Interface/Scene/SceneStorage.swift +++ b/Sources/Model/User Interface/Scene/SceneStorage.swift @@ -22,6 +22,8 @@ public class SceneStorage { public var destroy = false /// Show the scene element (including moving into the foreground, if possible). public var show: () -> Void + /// The previous state of the scene element. + public var previousState: SceneElement? /// The pointer as an opaque pointer, as this may be needed with backends interoperating with C or C++. public var opaquePointer: OpaquePointer? { diff --git a/Sources/Model/User Interface/View/ViewStorage.swift b/Sources/Model/User Interface/View/ViewStorage.swift index 7b6ef0a..5ef9d0e 100644 --- a/Sources/Model/User Interface/View/ViewStorage.swift +++ b/Sources/Model/User Interface/View/ViewStorage.swift @@ -18,6 +18,8 @@ public class ViewStorage { var state: [String: StateProtocol] = [:] /// Various properties of a widget. public var fields: [String: Any] = [:] + /// The previous state of the widget. + public var previousState: Widget? /// The pointer as an opaque pointer, as this is needed with backends interoperating with C or C++. public var opaquePointer: OpaquePointer? { @@ -35,10 +37,12 @@ public class ViewStorage { /// - content: The view's content for container widgets. public init( _ pointer: Any?, - content: [String: [ViewStorage]] = [:] + content: [String: [ViewStorage]] = [:], + state: Widget? = nil ) { self.pointer = pointer self.content = content + self.previousState = state } } diff --git a/Tests/SampleBackends/Backend1.swift b/Tests/SampleBackends/Backend1.swift index 89de7b7..4f935db 100644 --- a/Tests/SampleBackends/Backend1.swift +++ b/Tests/SampleBackends/Backend1.swift @@ -62,7 +62,9 @@ public enum Backend1 { public func update(_ storage: ViewStorage, modifiers: [(any AnyView) -> any AnyView], updateProperties: Bool, type: Data.Type) { storage.fields["action"] = action if updateProperties { - print("Update button (label = \(label))") + if (storage.previousState as? Self)?.label != label { + print("Update button (label = \(label))") + } } else { print("Do not update button (label = \(label))") }