diff --git a/Sources/FilePicker/FilePicker.swift b/Sources/FilePicker/FilePicker.swift index 8febfe1..02d23b5 100644 --- a/Sources/FilePicker/FilePicker.swift +++ b/Sources/FilePicker/FilePicker.swift @@ -34,18 +34,20 @@ public struct FilePicker: 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) @@ -61,7 +63,7 @@ public struct FilePicker: View { ) .disabled(isPresented) .sheet(isPresented: $isPresented) { - FilePickerUIRepresentable(types: types, allowMultiple: allowMultiple, onPicked: pickedCompletionHandler) + FilePickerUIRepresentable(types: types, allowMultiple: allowMultiple, asCopy: asCopy, onPicked: pickedCompletionHandler) } } diff --git a/Sources/FilePicker/FilePickerUIRepresentable.swift b/Sources/FilePicker/FilePickerUIRepresentable.swift index f877c31..dace299 100644 --- a/Sources/FilePicker/FilePickerUIRepresentable.swift +++ b/Sources/FilePicker/FilePickerUIRepresentable.swift @@ -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 } @@ -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