Skip to main content

conditional

Function conditional 

Source
pub fn conditional(
    flag: bool,
    if_true: &ViewHandle,
    if_false: &ViewHandle,
) -> ViewHandle
Expand description

The if/else a ViewBuilder produces.

This matters beyond picking a view. Branching in Rust and handing SwiftUI the winner erases the branch: both arms are AnyView, so SwiftUI sees one view whose value changed. _ConditionalContent tells it a branch changed, which is what drives insertion and removal transitions and keeps each arm’s identity — and therefore its @State — separate.

The type is one AnyView followed by a one-byte tag, so it is built directly.