Browse Source

Improved code

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 years ago
parent
commit
5266672f83
1 changed files with 22 additions and 1 deletions
  1. 22 1
      iOSClient/Scan document/NCUploadScanDocument.swift

+ 22 - 1
iOSClient/Scan document/NCUploadScanDocument.swift

@@ -64,6 +64,7 @@ class NCUploadScanDocument: ObservableObject {
 
     func save(fileName: String, password: String = "", isTextRecognition: Bool = false, removeAllFiles: Bool, quality: Double, completion: @escaping (_ openConflictViewController: Bool) -> Void) {
 
+        guard !fileName.isEmpty else { return }
         let ext = (fileName as NSString).pathExtension.uppercased()
         var fileNameMetadata = ""
 
@@ -362,7 +363,6 @@ struct UploadScanDocumentView: View {
     var metadatasConflict: [tableMetadata] = []
 
     @ObservedObject var uploadScanDocument: NCUploadScanDocument
-    @Environment(\.presentationMode) var presentationMode
 
     init(_ uploadScanDocument: NCUploadScanDocument) {
         self.uploadScanDocument = uploadScanDocument
@@ -406,6 +406,7 @@ struct UploadScanDocumentView: View {
                         HStack {
                             Text(NSLocalizedString("_filename_", comment: ""))
                             TextField(NSLocalizedString("_enter_filename_", comment: ""), text: $fileName)
+                                .modifier(TextFieldClearButton(text: $fileName))
                                 .multilineTextAlignment(.trailing)
                         }
 
@@ -426,6 +427,7 @@ struct UploadScanDocumentView: View {
                                 Image(systemName: self.isSecuredPassword ? "eye.slash" : "eye")
                                     .accentColor(.gray)
                             }
+                            .buttonStyle(BorderlessButtonStyle())
                         }
 
                         HStack {
@@ -500,6 +502,25 @@ struct UploadScanDocumentView: View {
     }
 }
 
+struct TextFieldClearButton: ViewModifier {
+    @Binding var text: String
+
+    func body(content: Content) -> some View {
+        HStack {
+            content
+            if !text.isEmpty {
+                Button(
+                    action: { self.text = "" },
+                    label: {
+                        Image(systemName: "delete.left")
+                            .foregroundColor(Color(UIColor.opaqueSeparator))
+                    }
+                ).buttonStyle(BorderlessButtonStyle())
+            }
+        }
+    }
+}
+
 struct ButtonUploadScanDocumenStyle: ButtonStyle {
     var disabled = false
     func makeBody(configuration: Configuration) -> some View {