Use widget instead of view for DummyEitherView

This commit is contained in:
david-swift 2024-08-10 10:25:39 +02:00
parent 1c0d491b02
commit aabd36d7ac
2 changed files with 30 additions and 6 deletions

View File

@ -20,9 +20,6 @@ extension AnyView {
for modifier in modifiers { for modifier in modifiers {
modified = modifier(modified) modified = modifier(modified)
} }
if let dummy = modified as? DummyEitherView {
modified = type.EitherViewType(dummy.condition) { dummy.view1 ?? [] } else: { dummy.view2 ?? [] }
}
return modified return modified
} }

View File

@ -6,7 +6,7 @@
// //
/// A dummy either view. This will be replaced by the platform-specific either view. /// A dummy either view. This will be replaced by the platform-specific either view.
struct DummyEitherView: SimpleView { struct DummyEitherView: Widget {
/// Whether to present the first view. /// Whether to present the first view.
var condition: Bool var condition: Bool
@ -15,7 +15,34 @@ struct DummyEitherView: SimpleView {
/// The second view. /// The second view.
var view2: Body? var view2: Body?
/// By default, show the first view. /// The view storage.
var view: Body { view1 ?? view2 ?? [] } /// - Parameters:
/// - modifiers: Modify views before being updated.
/// - type: The type of the app storage.
/// - Returns: The view storage.
func container<Data>(
modifiers: [(any AnyView) -> any AnyView],
type: Data.Type
) -> ViewStorage where Data: ViewRenderData {
let content = type.EitherViewType(condition) { view1 ?? [] } else: { view2 ?? [] }
let storage = content.storage(modifiers: modifiers, type: type)
return storage
}
/// Update the stored content.
/// - Parameters:
/// - storage: The storage to update.
/// - modifiers: Modify views before being updated
/// - updateProperties: Whether to update the view's properties.
/// - type: The type of the app storage.
func update<Data>(
_ storage: ViewStorage,
modifiers: [(any AnyView) -> any AnyView],
updateProperties: Bool,
type: Data.Type
) where Data: ViewRenderData {
let content = type.EitherViewType(condition) { view1 ?? [] } else: { view2 ?? [] }
content.updateStorage(storage, modifiers: modifiers, updateProperties: updateProperties, type: type)
}
} }