Add support for accessing the widget data when inspecting
This commit is contained in:
parent
681a51110d
commit
9f50e272f3
@ -9,7 +9,7 @@
|
|||||||
struct AppearObserver: ConvenienceWidget {
|
struct AppearObserver: ConvenienceWidget {
|
||||||
|
|
||||||
/// The custom code to edit the widget.
|
/// The custom code to edit the widget.
|
||||||
var modify: (ViewStorage) -> Void
|
var modify: (ViewStorage, WidgetData) -> Void
|
||||||
/// The wrapped view.
|
/// The wrapped view.
|
||||||
var content: AnyView
|
var content: AnyView
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ struct AppearObserver: ConvenienceWidget {
|
|||||||
type: Data.Type
|
type: Data.Type
|
||||||
) -> ViewStorage where Data: ViewRenderData {
|
) -> ViewStorage where Data: ViewRenderData {
|
||||||
let storage = content.storage(data: data, type: type)
|
let storage = content.storage(data: data, type: type)
|
||||||
modify(storage)
|
modify(storage, data)
|
||||||
return storage
|
return storage
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,10 +50,17 @@ extension AnyView {
|
|||||||
/// Run a function on the widget when it appears for the first time.
|
/// Run a function on the widget when it appears for the first time.
|
||||||
/// - Parameter closure: The function.
|
/// - Parameter closure: The function.
|
||||||
/// - Returns: A view.
|
/// - Returns: A view.
|
||||||
public func inspectOnAppear(_ closure: @escaping (ViewStorage) -> Void) -> AnyView {
|
public func inspectOnAppear(_ closure: @escaping (ViewStorage, WidgetData) -> Void) -> AnyView {
|
||||||
AppearObserver(modify: closure, content: self)
|
AppearObserver(modify: closure, content: self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Run a function on the widget when it appears for the first time.
|
||||||
|
/// - Parameter closure: The function.
|
||||||
|
/// - Returns: A view.
|
||||||
|
public func inspectOnAppear(_ closure: @escaping (ViewStorage) -> Void) -> AnyView {
|
||||||
|
inspectOnAppear { storage, _ in closure(storage) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Run a function when the view appears for the first time.
|
/// Run a function when the view appears for the first time.
|
||||||
/// - Parameter closure: The function.
|
/// - Parameter closure: The function.
|
||||||
/// - Returns: A view.
|
/// - Returns: A view.
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
struct InspectorWrapper: ConvenienceWidget {
|
struct InspectorWrapper: ConvenienceWidget {
|
||||||
|
|
||||||
/// The custom code to edit the widget.
|
/// The custom code to edit the widget.
|
||||||
var modify: (ViewStorage, Bool) -> Void
|
var modify: (ViewStorage, WidgetData, Bool) -> Void
|
||||||
/// The wrapped view.
|
/// The wrapped view.
|
||||||
var content: AnyView
|
var content: AnyView
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ struct InspectorWrapper: ConvenienceWidget {
|
|||||||
type: Data.Type
|
type: Data.Type
|
||||||
) -> ViewStorage where Data: ViewRenderData {
|
) -> ViewStorage where Data: ViewRenderData {
|
||||||
let storage = content.storage(data: data, type: type)
|
let storage = content.storage(data: data, type: type)
|
||||||
modify(storage, true)
|
modify(storage, data, true)
|
||||||
return storage
|
return storage
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ struct InspectorWrapper: ConvenienceWidget {
|
|||||||
type: Data.Type
|
type: Data.Type
|
||||||
) where Data: ViewRenderData {
|
) where Data: ViewRenderData {
|
||||||
content.updateStorage(storage, data: data, updateProperties: updateProperties, type: type)
|
content.updateStorage(storage, data: data, updateProperties: updateProperties, type: type)
|
||||||
modify(storage, updateProperties)
|
modify(storage, data, updateProperties)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -51,10 +51,17 @@ extension AnyView {
|
|||||||
/// Run a custom code accessing the view's storage when initializing and updating the view.
|
/// 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.
|
/// - Parameter modify: Modify the storage. The boolean indicates whether state in parent views changed.
|
||||||
/// - Returns: A view.
|
/// - Returns: A view.
|
||||||
public func inspect(_ modify: @escaping (ViewStorage, Bool) -> Void) -> AnyView {
|
public func inspect(_ modify: @escaping (ViewStorage, WidgetData, Bool) -> Void) -> AnyView {
|
||||||
InspectorWrapper(modify: modify, content: self)
|
InspectorWrapper(modify: modify, content: self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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: @escaping (ViewStorage, Bool) -> Void) -> AnyView {
|
||||||
|
inspect { storage, _, updateProperties in modify(storage, updateProperties) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Run a function when the view gets updated.
|
/// Run a function when the view gets updated.
|
||||||
/// - Parameter onUpdate: The function.
|
/// - Parameter onUpdate: The function.
|
||||||
/// - Returns: A view.
|
/// - Returns: A view.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user