Instance Method インスタンスメソッド

fullScreenCover(item:onDismiss:content:)

Presents a modal view that covers as much of the screen as possible using the binding you provide as a data source for the sheet’s content.

Declaration 宣言

func fullScreenCover<Item, Content>(item: Binding<Item?>, onDismiss: (() -> Void)? = nil, content: @escaping (Item) -> Content) -> some View where Item : Identifiable, Content : View

Parameters パラメータ

item

A binding to an optional source of truth for the sheet. シートに対するある随意の信頼できる情報源へのあるバインディング。 When item is non-nil, the system passes the contents to the modifier’s closure. You display this content in a sheet that you create that the system displays to the user. If item changes, the system dismisses the currently displayed sheet and replaces it with a new one using the same process.

onDismiss

The closure to execute when dismissing the modal view.

content

A closure returning the content of the modal view. モーダルビューの内容を返しているクロージャ。

Discussion 議論

Use this method to display a modal view that covers as much of the screen as possible. In the example below a custom structure — CoverData — provides data for the full-screen view to display in the content closure when the user clicks or taps the “Present Full-Screen Cover With Data” button:


struct FullScreenCoverItemOnDismissContent: View {
    @State var coverData: CoverData?
    var body: some View {
        Button("Present Full-Screen Cover With Data") {
            coverData = CoverData(body: "Custom Data")
        }
        .fullScreenCover(item: $coverData,
                         onDismiss: didDismiss) { details in
            VStack(spacing: 20) {
                Text("\(details.body)")
            }
            .onTapGesture {
                coverData = nil
            }
        }
    }


    func didDismiss() {
        // Handle the dismissing action.
    }


}


struct CoverData: Identifiable {
    var id: String {
        return body
    }
    let body: String
}

A full-screen modal view that shows Custom

See Also 参照

Sheets