Instance Property インスタンスプロパティ

isPresented

A Boolean value that indicates whether the view associated with this environment is currently presented.

Declaration 宣言

var isPresented: Bool { get }

Discussion 議論

You can read this value like any of the other EnvironmentValues by creating a property with the Environment property wrapper:


@Environment(\.isPresented) private var isPresented

Read the value inside a view if you need to know when SwiftUI presents that view. For example, you can take an action when SwiftUI presents a view by using the onChange(of:perform:) modifier:


.onChange(of: isPresented) { isPresented in
    if isPresented {
        // Do something when first presented.
    }
}

This behaves differently than onAppear(perform:), which SwiftUI can call more than once for a given presentation, like when you navigate back to a view that’s already in the navigation hierarchy.

To dismiss the currently presented view, use dismiss.

See Also 参照

State 状態