Browse Source

test

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 years ago
parent
commit
286a2b83d1

+ 2 - 0
.swiftlint.yml

@@ -44,6 +44,7 @@ excluded:
   - Pods
 
   # iOS Files Quarantine
+
   - File Provider Extension/FileProviderData.swift
   - File Provider Extension/FileProviderDomain.swift
   - File Provider Extension/FileProviderEnumerator.swift
@@ -60,6 +61,7 @@ excluded:
   - Widget/Lockscreen/LockscreenData.swift
   - Widget/Lockscreen/LockscreenWidgetView.swift
   - Widget/Lockscreen/LockscreenWidgetProvider.swift
+  - iOSClient/GUI
   - iOSClient/ExternalResources
   - iOSClient/Activity/NCActivity.swift
   - iOSClient/Activity/NCActivityTableViewCell.swift

+ 17 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -96,6 +96,7 @@
 		F70460522499061800BB98A7 /* NotificationCenter+MainThread.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70460512499061800BB98A7 /* NotificationCenter+MainThread.swift */; };
 		F70460532499095400BB98A7 /* NotificationCenter+MainThread.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70460512499061800BB98A7 /* NotificationCenter+MainThread.swift */; };
 		F70460542499095400BB98A7 /* NotificationCenter+MainThread.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70460512499061800BB98A7 /* NotificationCenter+MainThread.swift */; };
+		F704A950296EE1C200D0737A /* Mantis in Frameworks */ = {isa = PBXBuildFile; productRef = F704A94F296EE1C200D0737A /* Mantis */; };
 		F704B5E32430AA6F00632F5F /* NCCreateFormUploadConflict.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F704B5E22430AA6F00632F5F /* NCCreateFormUploadConflict.storyboard */; };
 		F704B5E52430AA8000632F5F /* NCCreateFormUploadConflict.swift in Sources */ = {isa = PBXBuildFile; fileRef = F704B5E42430AA8000632F5F /* NCCreateFormUploadConflict.swift */; };
 		F704B5E72430C06700632F5F /* NCCreateFormUploadConflictCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F704B5E62430C06700632F5F /* NCCreateFormUploadConflictCell.xib */; };
@@ -1256,6 +1257,7 @@
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				F704A950296EE1C200D0737A /* Mantis in Frameworks */,
 				F76DA941277B75870082465B /* KTVHTTPCache.xcframework in Frameworks */,
 				F7ED547C25EEA65400956C55 /* QRCodeReader in Frameworks */,
 				F788ECC7263AAAFA00ADC67F /* MarkdownKit in Frameworks */,
@@ -2493,6 +2495,7 @@
 				F734B06528E75C0100E180D5 /* TLPhotoPicker */,
 				F77333872927A72100466E35 /* OpenSSL */,
 				F77BC3EA293E5268005F2B08 /* Swifter */,
+				F704A94F296EE1C200D0737A /* Mantis */,
 			);
 			productName = "Crypto Cloud";
 			productReference = F7CE8AFA1DC1F8D8009CAE48 /* Nextcloud.app */;
@@ -2651,6 +2654,7 @@
 				F734B06428E75C0100E180D5 /* XCRemoteSwiftPackageReference "TLPhotoPicker" */,
 				F77333862927A72100466E35 /* XCRemoteSwiftPackageReference "OpenSSL" */,
 				F77BC3E9293E5268005F2B08 /* XCRemoteSwiftPackageReference "swifter" */,
+				F704A94E296EE1C200D0737A /* XCRemoteSwiftPackageReference "Mantis" */,
 			);
 			productRefGroup = F7F67B9F1A24D27800EE80DA;
 			projectDirPath = "";
@@ -3930,6 +3934,14 @@
 /* End XCConfigurationList section */
 
 /* Begin XCRemoteSwiftPackageReference section */
+		F704A94E296EE1C200D0737A /* XCRemoteSwiftPackageReference "Mantis" */ = {
+			isa = XCRemoteSwiftPackageReference;
+			repositoryURL = "https://github.com/guoyingtao/Mantis.git";
+			requirement = {
+				branch = master;
+				kind = branch;
+			};
+		};
 		F70B86732642CE3B00ED5349 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = {
 			isa = XCRemoteSwiftPackageReference;
 			repositoryURL = "https://github.com/firebase/firebase-ios-sdk";
@@ -4093,6 +4105,11 @@
 /* End XCRemoteSwiftPackageReference section */
 
 /* Begin XCSwiftPackageProductDependency section */
+		F704A94F296EE1C200D0737A /* Mantis */ = {
+			isa = XCSwiftPackageProductDependency;
+			package = F704A94E296EE1C200D0737A /* XCRemoteSwiftPackageReference "Mantis" */;
+			productName = Mantis;
+		};
 		F70B86742642CE3B00ED5349 /* FirebaseCrashlytics */ = {
 			isa = XCSwiftPackageProductDependency;
 			package = F70B86732642CE3B00ED5349 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;

+ 69 - 3
iOSClient/Main/Create cloud/NCUploadAssets.swift

@@ -24,6 +24,7 @@
 import SwiftUI
 import NextcloudKit
 import TLPhotoPicker
+import Mantis
 
 class NCHostingUploadAssetsView: NSObject {
 
@@ -86,8 +87,11 @@ struct UploadAssetsView: View {
     @State private var isAddFilenametype: Bool = CCUtility.getFileNameType(NCGlobal.shared.keyFileNameType)
     @State private var isPresentedSelect = false
     @State private var isPresentedUploadConflict = false
+
     @State private var isPresentedCrop = false
-    @State private var imageCrop = UIImage()
+    @State private var imageForCrop: UIImage = UIImage()
+    @State private var cropShapeType: Mantis.CropShapeType = .rect
+    @State private var presetFixedRatioType: Mantis.PresetFixedRatioType = .canUseMultiplePresetFixedRatio()
 
     var gridItems: [GridItem] = [GridItem()]
 
@@ -227,7 +231,7 @@ struct UploadAssetsView: View {
                                         .cornerRadius(10)
                                         .scaledToFit()
                                         .onTapGesture {
-                                            imageCrop = uploadAssets.images[index]
+                                            imageForCrop = uploadAssets.images[index]
                                             isPresentedCrop = true
                                         }
                                 }
@@ -313,7 +317,8 @@ struct UploadAssetsView: View {
             .navigationBarTitleDisplayMode(.inline)
         }
         .sheet(isPresented: $isPresentedCrop) {
-            // CropView(image: $imageCrop)
+            ImageCropper(image: $imageForCrop, cropShapeType: $cropShapeType, presetFixedRatioType: $presetFixedRatioType)
+                .ignoresSafeArea()
         }
         .sheet(isPresented: $isPresentedSelect) {
             SelectView(serverUrl: $uploadAssets.serverUrl)
@@ -329,6 +334,67 @@ struct UploadAssetsView: View {
     }
 }
 
+// MARK: - ImageCropper
+
+struct ImageCropper: UIViewControllerRepresentable {
+
+    @Binding var image: UIImage
+    @Binding var cropShapeType: Mantis.CropShapeType
+    @Binding var presetFixedRatioType: Mantis.PresetFixedRatioType
+
+    @Environment(\.presentationMode) var presentationMode
+
+    class Coordinator: CropViewControllerDelegate {
+
+        var parent: ImageCropper
+
+        init(_ parent: ImageCropper) {
+            self.parent = parent
+        }
+
+        func cropViewControllerDidCrop(_ cropViewController: CropViewController, cropped: UIImage, transformation: Transformation, cropInfo: CropInfo) {
+            parent.image = cropped
+            print("transformation is \(transformation)")
+            parent.presentationMode.wrappedValue.dismiss()
+        }
+
+        func cropViewControllerDidImageTransformed(_ cropViewController: Mantis.CropViewController) {
+
+        }
+
+        func cropViewControllerDidCancel(_ cropViewController: CropViewController, original: UIImage) {
+            parent.presentationMode.wrappedValue.dismiss()
+        }
+
+        func cropViewControllerDidFailToCrop(_ cropViewController: CropViewController, original: UIImage) {
+        }
+
+        func cropViewControllerDidBeginResize(_ cropViewController: CropViewController) {
+        }
+
+        func cropViewControllerDidEndResize(_ cropViewController: CropViewController, original: UIImage, cropInfo: CropInfo) {
+        }
+    }
+
+    func makeCoordinator() -> Coordinator {
+        Coordinator(self)
+    }
+
+    func makeUIViewController(context: Context) -> CropViewController {
+        var config = Mantis.Config()
+        config.cropViewConfig.cropShapeType = cropShapeType
+        config.presetFixedRatioType = presetFixedRatioType
+        let cropViewController = Mantis.cropViewController(image: image,
+                                                           config: config)
+        cropViewController.delegate = context.coordinator
+        return cropViewController
+    }
+
+    func updateUIViewController(_ uiViewController: CropViewController, context: Context) {
+
+    }
+}
+
 // MARK: - Preview
 
 struct UploadAssetsView_Previews: PreviewProvider {