Add support for setting a view's visibility
Use the visibility instead of a ViewStack for optional views
This commit is contained in:
parent
3ee1cf38fa
commit
b4e88a4a42
@ -147,6 +147,12 @@ Make the view insensitive (useful e.g. in overlays).
|
||||
- Parameter insensitive: Whether the view is insensitive.
|
||||
- Returns: A view.
|
||||
|
||||
### `visible(_:)`
|
||||
|
||||
Set the view's visibility.
|
||||
- Parameter visible: Whether the view is visible.
|
||||
- Returns: A view.
|
||||
|
||||
### `stopModifiers()`
|
||||
|
||||
Remove all of the content modifiers for the wrapped views.
|
||||
|
||||
@ -57,11 +57,16 @@ public enum ViewBuilder {
|
||||
/// - Parameter component: An optional component.
|
||||
/// - Returns: A nonoptional component.
|
||||
public static func buildOptional(_ component: Component?) -> Component {
|
||||
if let component {
|
||||
return .element(ViewStack(id: true) { _ in buildFinalResult(component) })
|
||||
} else {
|
||||
return .element(ViewStack(id: false) { _ in [] })
|
||||
}
|
||||
.element(
|
||||
VStack {
|
||||
if let component {
|
||||
buildFinalResult(component)
|
||||
} else {
|
||||
[]
|
||||
}
|
||||
}
|
||||
.visible(component != nil)
|
||||
)
|
||||
}
|
||||
|
||||
/// Enables support for `if`-`else` and `switch` statements.
|
||||
|
||||
@ -131,4 +131,11 @@ extension View {
|
||||
inspect { gtk_widget_set_sensitive($0.pointer?.cast(), insensitive ? 0 : 1) }
|
||||
}
|
||||
|
||||
/// Set the view's visibility.
|
||||
/// - Parameter visible: Whether the view is visible.
|
||||
/// - Returns: A view.
|
||||
public func visible(_ visible: Bool = true) -> View {
|
||||
inspect { gtk_widget_set_visible($0.pointer?.cast(), visible.cBool) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user