Browse Source

compdfkit(rn) - ios端接口预定义

liuxiaolong 3 months ago
parent
commit
d6921b436b

+ 8 - 2
example/ios/CompdfkitPdfExample.xcodeproj/project.pbxproj

@@ -625,7 +625,10 @@
 					"-DFOLLY_CFG_NO_COROUTINES=1",
 					"-DFOLLY_HAVE_CLOCK_GETTIME=1",
 				);
-				OTHER_LDFLAGS = "$(inherited)  ";
+				OTHER_LDFLAGS = (
+					"$(inherited)",
+					" ",
+				);
 				REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
 				SDKROOT = iphoneos;
 				USE_HERMES = true;
@@ -698,7 +701,10 @@
 					"-DFOLLY_CFG_NO_COROUTINES=1",
 					"-DFOLLY_HAVE_CLOCK_GETTIME=1",
 				);
-				OTHER_LDFLAGS = "$(inherited)  ";
+				OTHER_LDFLAGS = (
+					"$(inherited)",
+					" ",
+				);
 				REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
 				SDKROOT = iphoneos;
 				USE_HERMES = true;

+ 2 - 2
example/ios/Podfile

@@ -16,8 +16,8 @@ end
 
 target 'CompdfkitPdfExample' do
   config = use_native_modules!
-  pod "ComPDFKit", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/2.1.3.podspec'
-  pod "ComPDFKit_Tools", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/2.1.3.podspec'
+  pod "ComPDFKit", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit/2.2.0.podspec'
+  pod "ComPDFKit_Tools", podspec:'https://www.compdf.com/download/ios/cocoapods/xcframeworks/compdfkit_tools/2.2.0.podspec'
 
 
   use_react_native!(

+ 30 - 24
ios/ComPDFKitRN.swift

@@ -17,7 +17,7 @@ import ComPDFKit_Tools
  */
 @objc(ComPDFKit)
 class ComPDFKit: NSObject, CPDFViewBaseControllerDelete{
-    
+
     /**
       * Get the version number of the ComPDFKit SDK.<br/>
       * For example: "2.0.0".<br/>
@@ -54,8 +54,8 @@ class ComPDFKit: NSObject, CPDFViewBaseControllerDelete{
         let sdkBuildTag = CPDFKit.sharedInstance().versionString
         resolve(sdkBuildTag)
     }
-    
-    
+
+
     /**
      * Initialize the ComPDFKit PDF SDK using offline authentication.<br/>
      * <p></p>
@@ -74,8 +74,8 @@ class ComPDFKit: NSObject, CPDFViewBaseControllerDelete{
             resolve(code == CPDFKitLicenseCode.success)
         }
     }
-    
-    
+
+
     /**
      * Initialize the ComPDFKit PDF SDK using online authentication. <br/>
      * Requires internet connection. Please ensure that the network permission has been added in [AndroidManifest.xml] file. <br/>
@@ -98,8 +98,8 @@ class ComPDFKit: NSObject, CPDFViewBaseControllerDelete{
         }
       }
     }
-    
-    
+
+
     /**
        * Display a PDF.<br/>
        *
@@ -134,18 +134,18 @@ class ComPDFKit: NSObject, CPDFViewBaseControllerDelete{
             let samplesFilePath = NSHomeDirectory().appending("/Documents/Files")
             let fileName = document.lastPathComponent
             let docsFilePath = samplesFilePath + "/" + fileName
-            
+
             if !fileManager.fileExists(atPath: samplesFilePath) {
                 try? FileManager.default.createDirectory(atPath: samplesFilePath, withIntermediateDirectories: true, attributes: nil)
             }
-            
+
             try? FileManager.default.copyItem(atPath: document.path, toPath: docsFilePath)
-            
+
             let rootNav = ComPDFKit.presentedViewController()
-          
+
             let jsonDataParse = CPDFJSONDataParse(String: configurationJson)
             guard let configuration = jsonDataParse.configuration else { return }
-            
+
             let pdfViewController = CPDFViewController(filePath: docsFilePath, password: password, configuration: configuration)
             pdfViewController.delegate = self
             let nav = CNavigationController(rootViewController: pdfViewController)
@@ -153,46 +153,46 @@ class ComPDFKit: NSObject, CPDFViewBaseControllerDelete{
             rootNav?.present(nav, animated: true)
         }
     }
-    
-    
+
+
     /**
      * CPDFViewBaseControllerDelete delegate to dismiss ViewController.<br/>
      */
     func PDFViewBaseControllerDissmiss(_ baseControllerDelete: CPDFViewBaseController) {
       baseControllerDelete.dismiss(animated: true)
     }
-    
+
     /**
      *  Cet a root ViewController.<br/>
      */
     class func presentedViewController() -> UIViewController? {
-      
+
       var rootViewController: UIViewController? = nil
-      
+
       if let appDelegate = UIApplication.shared.delegate as? NSObject {
         if appDelegate.responds(to: Selector(("viewController"))) {
           rootViewController = appDelegate.value(forKey: "viewController") as? UIViewController
         }
       }
-      
+
       if rootViewController == nil, let appDelegate = UIApplication.shared.delegate as? NSObject, appDelegate.responds(to: #selector(getter: UIApplicationDelegate.window)) {
         if let window = appDelegate.value(forKey: "window") as? UIWindow {
           rootViewController = window.rootViewController
         }
       }
-      
+
       if rootViewController == nil {
         if let window = UIApplication.shared.keyWindow {
           rootViewController = window.rootViewController
         }
       }
-      
+
       guard let finalRootViewController = rootViewController else {
         return nil
       }
-      
+
       var currentViewController = finalRootViewController
-      
+
       while let presentedViewController = currentViewController.presentedViewController {
         if !(presentedViewController is UIAlertController) && currentViewController.modalPresentationStyle != .popover {
           currentViewController = presentedViewController
@@ -200,8 +200,14 @@ class ComPDFKit: NSObject, CPDFViewBaseControllerDelete{
           return currentViewController
         }
       }
-      
+
       return currentViewController
     }
-    
+
+    @objc(removeSignFileList:withRejecter:)
+    func removeSignFileList(resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
+        // TODO: 清空注释电子签名文件列表,返回true、false
+        resolve(true)
+    }
+
 }

+ 16 - 0
ios/RCTCPDFViewManager.swift

@@ -33,6 +33,22 @@ class RCTCPDFReaderView: RCTViewManager, RCTCPDFViewDelegate {
         rtcCPDFView?.saveDocument(completionHandler: { success in
             completionHandler(success)
         })
+        
+        // TODO: 监听滚动的页码变动,返回当前页码
+        // WritableMap params = Arguments.createMap();
+        // params.putInt("onPageChanged", pageIndex);
+        // themedReactContext.getJSModule(RCTEventEmitter.class).receiveEvent(
+        // getId(),
+        // "topChange",
+        // event);
+        
+        // TODO: 监听文档保存,回调保存的通知
+        // WritableMap event = Arguments.createMap();
+        // event.putString("saveDocument", "saveDocument");
+        // themedReactContext.getJSModule(RCTEventEmitter.class).receiveEvent(
+        // getId(),
+        // "topChange",
+        // event);
     }
     
     // MARK: - RCTCPDFViewDelegate

+ 31 - 0
ios/RCTDocumentManager.swift

@@ -40,4 +40,35 @@ class RCTDocumentManager: NSObject, RCTBridgeModule {
         }
     }
     
+    func setMargins(tag : Int, left : Int, top : Int, right : Int, bottom : Int) -> Void {
+        // TODO: 设置阅读区域边距
+        // 无返回值
+    }
+    
+    func removeAllAnnotations(tag : Int, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock){
+        // TODO: 删除当前文档所有注释, 返回true、false
+    }
+    
+    func importAnnotations(tag : Int, xfdfFile : String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
+        // TODO: 导入注释, 返回:true、false
+        resolve(true)
+    }
+    
+    func exportAnnotations(tag : Int, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock){
+        // TODO: 导出注释,返回:xfdf文件路径
+        resolve("xxxx.xfdf")
+    }
+    
+    func setDisplayPageIndex(tag : Int, pageIndex : Int) -> Void {
+        // TODO: 跳转到指定页码, 无返回值
+    }
+    
+    func getCurrentPageIndex(tag : Int,resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
+        // TODO: 返回当前页码
+    }
+    
+    func hasChange(tag : Int, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock){
+        // TODO: 返回当前展示的文档是否存在修改, 返回:true、false
+    }
+    
 }