DocumentLaunchView

A view to present when launching document-related user experience.

Declaration

React
import { DocumentLaunchView } from 'swiftui-react-native';
Swift
nonisolated struct DocumentLaunchView<Actions, DocumentView> where Actions : View, DocumentView : View

Initializers

24 SwiftUI initializers back <DocumentLaunchView>. The props you pass pick one.

React
<DocumentLaunchView
  title: string
  for: string[]
  actions?: ReactNode
  onDocumentOpen?: ReactNode | ((arg0: string) => ReactNode)
/>
Swift
nonisolated init(
    _ title: some StringProtocol,
    for contentTypes: [UTType],
    @ContentBuilder _ actions: () -> Actions,
    @ContentBuilder onDocumentOpen: @escaping (URL) -> DocumentView
)
  • title*string

    A title to use for the view title.

  • for*string[]

    Content types that the view can open.

    Swift for contentTypes: [UTType]

  • actionsReactNode

    A content builder returning the view's actions

  • onDocumentOpenReactNode | ((arg0: string) => ReactNode)

    A closure that handles an open file.

Also takes the common view props: modifiers, style and testID.

Overview

doc://com.apple.documentation/documentation/bundleresources/information-property-list/uisupportsdocumentbrowser to YES in your app's information property list. Without this key, document creation doesn't work.

Configure DocumentLaunchView to open and display files and trigger custom actions.

For example, an application that offers writing books can present the DocumentLaunchView as its launch view:

public import UniformTypeIdentifiers

struct BookEditorLaunchView: View {

    var body: some View {
        DocumentLaunchView(for: [.book]) {
            NewDocumentButton("Start New Book")
        } onDocumentOpen: { url in
            BookEditor(url)
        }
    }
}

struct BookEditor: View {
    init(_ url: URL) { }
}

extension UTType {
    static let book = UTType(exportedAs: "com.example.bookEditor")
}

An alternative to DocumentLaunchView is a scene variant of this API: DocumentGroupLaunchScene. If the app definition contains DocumentGroup scenes, consider using a DocumentGroupLaunchScene instead of this view.

From Apple’s SwiftUI documentation. Code samples there are Swift.

Relationships

Conforms to

  • View

See also

More in Documents.