Add modify function for views

This commit is contained in:
david-swift 2024-07-07 16:30:36 +02:00
parent 8da8115172
commit b8f36b7600
2 changed files with 10 additions and 1 deletions

View File

@ -75,6 +75,15 @@ extension AnyView {
|| result as? Body != nil
}
/// Apply a modification onto a view.
/// - Parameter action: The modifications.
/// - Returns: The modified view.
public func modify(action: (inout Self) -> Void) -> Self {
var newSelf = self
action(&newSelf)
return newSelf
}
}
/// `Body` is an array of views.

View File

@ -90,7 +90,7 @@ public enum Backend1 {
public func container<Storage>(modifiers: [(any AnyView) -> any AnyView], type: Storage.Type) -> ViewStorage where Storage: AppStorage {
let storage = ViewStorage(nil)
storage.renderableContent[.mainContent] = (content as [Renderable]).storages(type: MenuElement.self, fields: [:]) ?? []
storage.renderableContent[.mainContent] = (content as [Renderable]).storages(type: MenuElement.self, fields: [:])
return storage
}