From 1a5cc43ef1681141e61c4312a0ecd6ef3a666a72 Mon Sep 17 00:00:00 2001 From: david-swift Date: Thu, 19 Sep 2024 13:07:44 +0200 Subject: [PATCH] Make appear observer and inspector wrapper async --- Sources/View/AppearObserver.swift | 10 +++++----- Sources/View/InspectorWrapper.swift | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Sources/View/AppearObserver.swift b/Sources/View/AppearObserver.swift index 8a724a0..47c7bcc 100644 --- a/Sources/View/AppearObserver.swift +++ b/Sources/View/AppearObserver.swift @@ -9,7 +9,7 @@ struct AppearObserver: ConvenienceWidget { /// The custom code to edit the widget. - var modify: @Sendable (ViewStorage) -> Void + var modify: @Sendable (ViewStorage) async -> Void /// The wrapped view. var content: AnyView @@ -23,7 +23,7 @@ struct AppearObserver: ConvenienceWidget { type: Data.Type ) async -> ViewStorage where Data: ViewRenderData { let storage = await content.storage(data: data, type: type) - modify(storage) + await modify(storage) return storage } @@ -50,15 +50,15 @@ extension AnyView { /// Run a function on the widget when it appears for the first time. /// - Parameter closure: The function. /// - Returns: A view. - public func inspectOnAppear(_ closure: @Sendable @escaping (ViewStorage) -> Void) -> AnyView { + public func inspectOnAppear(_ closure: @Sendable @escaping (ViewStorage) async -> Void) -> AnyView { AppearObserver(modify: closure, content: self) } /// Run a function when the view appears for the first time. /// - Parameter closure: The function. /// - Returns: A view. - public func onAppear(_ closure: @Sendable @escaping () -> Void) -> AnyView { - inspectOnAppear { _ in closure() } + public func onAppear(_ closure: @Sendable @escaping () async -> Void) -> AnyView { + inspectOnAppear { _ in await closure() } } } diff --git a/Sources/View/InspectorWrapper.swift b/Sources/View/InspectorWrapper.swift index 36cc809..5841ef6 100644 --- a/Sources/View/InspectorWrapper.swift +++ b/Sources/View/InspectorWrapper.swift @@ -9,7 +9,7 @@ struct InspectorWrapper: ConvenienceWidget { /// The custom code to edit the widget. - var modify: @Sendable (ViewStorage, Bool) -> Void + var modify: @Sendable (ViewStorage, Bool) async -> Void /// The wrapped view. var content: AnyView @@ -23,7 +23,7 @@ struct InspectorWrapper: ConvenienceWidget { type: Data.Type ) async -> ViewStorage where Data: ViewRenderData { let storage = await content.storage(data: data, type: type) - modify(storage, true) + await modify(storage, true) return storage } @@ -40,7 +40,7 @@ struct InspectorWrapper: ConvenienceWidget { type: Data.Type ) async where Data: ViewRenderData { await content.updateStorage(storage, data: data, updateProperties: updateProperties, type: type) - modify(storage, updateProperties) + await modify(storage, updateProperties) } } @@ -51,15 +51,15 @@ extension AnyView { /// Run a custom code accessing the view's storage when initializing and updating the view. /// - Parameter modify: Modify the storage. The boolean indicates whether state in parent views changed. /// - Returns: A view. - public func inspect(_ modify: @Sendable @escaping (ViewStorage, Bool) -> Void) -> AnyView { + public func inspect(_ modify: @Sendable @escaping (ViewStorage, Bool) async -> Void) -> AnyView { InspectorWrapper(modify: modify, content: self) } /// Run a function when the view gets updated. /// - Parameter onUpdate: The function. /// - Returns: A view. - public func onUpdate(_ onUpdate: @Sendable @escaping () -> Void) -> AnyView { - inspect { _, _ in onUpdate() } + public func onUpdate(_ onUpdate: @Sendable @escaping () async -> Void) -> AnyView { + inspect { _, _ in await onUpdate() } } }