Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Sources/FilePicker/FilePicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ public struct FilePicker<LabelView: View>: View {

public let types: [UTType]
public let allowMultiple: Bool
public let asCopy: Bool
public let pickedCompletionHandler: PickedURLsCompletionHandler
public let labelViewContent: LabelViewContent

public init(types: [UTType], allowMultiple: Bool, onPicked completionHandler: @escaping PickedURLsCompletionHandler, @ViewBuilder label labelViewContent: @escaping LabelViewContent) {
public init(types: [UTType], allowMultiple: Bool, asCopy: Bool = true, onPicked completionHandler: @escaping PickedURLsCompletionHandler, @ViewBuilder label labelViewContent: @escaping LabelViewContent) {
self.types = types
self.allowMultiple = allowMultiple
self.asCopy = asCopy
self.pickedCompletionHandler = completionHandler
self.labelViewContent = labelViewContent
}

public init(types: [UTType], allowMultiple: Bool, title: String, onPicked completionHandler: @escaping PickedURLsCompletionHandler) where LabelView == Text {
self.init(types: types, allowMultiple: allowMultiple, onPicked: completionHandler) { Text(title) }
public init(types: [UTType], allowMultiple: Bool, title: String, asCopy: Bool = true, onPicked completionHandler: @escaping PickedURLsCompletionHandler) where LabelView == Text {
self.init(types: types, allowMultiple: allowMultiple, asCopy: asCopy, onPicked: completionHandler) { Text(title) }
}

#if os(iOS)
Expand All @@ -61,7 +63,7 @@ public struct FilePicker<LabelView: View>: View {
)
.disabled(isPresented)
.sheet(isPresented: $isPresented) {
FilePickerUIRepresentable(types: types, allowMultiple: allowMultiple, onPicked: pickedCompletionHandler)
FilePickerUIRepresentable(types: types, allowMultiple: allowMultiple, asCopy: asCopy, onPicked: pickedCompletionHandler)
}
}

Expand Down
6 changes: 4 additions & 2 deletions Sources/FilePicker/FilePickerUIRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ public struct FilePickerUIRepresentable: UIViewControllerRepresentable {

public let types: [UTType]
public let allowMultiple: Bool
public let asCopy: Bool
public let pickedCompletionHandler: PickedURLsCompletionHandler

public init(types: [UTType], allowMultiple: Bool, onPicked completionHandler: @escaping PickedURLsCompletionHandler) {
public init(types: [UTType], allowMultiple: Bool, asCopy: Bool, onPicked completionHandler: @escaping PickedURLsCompletionHandler) {
self.types = types
self.allowMultiple = allowMultiple
self.asCopy = asCopy
self.pickedCompletionHandler = completionHandler
}

Expand All @@ -48,7 +50,7 @@ public struct FilePickerUIRepresentable: UIViewControllerRepresentable {
}

public func makeUIViewController(context: Context) -> UIDocumentPickerViewController {
let picker = UIDocumentPickerViewController(forOpeningContentTypes: types, asCopy: true)
let picker = UIDocumentPickerViewController(forOpeningContentTypes: types, asCopy: asCopy)
picker.delegate = context.coordinator
picker.allowsMultipleSelection = allowMultiple
return picker
Expand Down