Переглянути джерело

compdfkit(RN) - iOS 端组件化接入

yangliuhua 3 місяців тому
батько
коміт
25c56c1e6c
4 змінених файлів з 103 додано та 46 видалено
  1. 0 34
      ios/RCTCPDFView.m
  2. 66 0
      ios/RCTCPDFView.swift
  3. 10 12
      ios/RCTCPDFViewManager.m
  4. 27 0
      ios/RCTCPDFViewManager.swift

+ 0 - 34
ios/RCTCPDFView.m

@@ -1,34 +0,0 @@
-//
-//  CPDFView.m
-//  react-native-compdfkit-pdf
-//
-//  Created by Xiaolong Liu on 2024/7/4.
-//
-
-#import <Foundation/Foundation.h>
-#import <UIKit/UIKit.h>
-#import <ComPDFKit_Tools/ComPDFKit_Tools.h>
-
-@interface RCTCPDFView : UIView
-
-@property (nonatomic, strong) CPDFViewController *pdfViewController;
-
-- (void)setDocument:(NSURL *) documentURL;
-
-@end
-
-@implementation RCTCPDFView
-
-- (instancetype)initWithFrame:(CGRect)frame {
-    self = [super initWithFrame:frame];
-    if (self) {
-        // 初始化
-    }
-    return self;
-}
-
-- (void)setDocument:(NSURL *)documentURL {
-    
-}
-
-@end

+ 66 - 0
ios/RCTCPDFView.swift

@@ -0,0 +1,66 @@
+//
+//  RCTCPDFView.swift
+//  react-native-compdfkit-pdf
+//
+//  Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
+//
+//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+//  This notice may not be removed from this file.
+//
+
+import UIKit
+import ComPDFKit_Tools
+
+class RCTCPDFView: UIView {
+    
+    private var pdfViewController : CPDFViewController?
+    
+    private var navigationController : CNavigationController?
+   
+    init() {
+        super.init(frame: CGRect(x: 0, y: 0, width: 500, height: 400))
+    }
+    
+    required init?(coder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+    
+    private func createCPDFView() {
+        let jsonData = CPDFJSONDataParse(String: configuration)
+        let configurations = jsonData.configuration ?? CPDFConfiguration()
+
+        pdfViewController = CPDFViewController(filePath: document.path, password: password, configuration: configurations)
+        navigationController = CNavigationController(rootViewController: pdfViewController!)
+        navigationController?.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
+        navigationController?.view.frame = self.frame
+
+        navigationController?.setViewControllers([pdfViewController!], animated: true)
+        
+        addSubview(navigationController?.view ?? UIView())
+    }
+    
+    private var configuration: String = ""
+    @objc func setConfiguration(_ newSection: String) {
+       configuration = newSection
+        
+        if (document.path.count > 1) && (configuration.count > 1) {
+            createCPDFView()
+        }
+    }
+    
+    private var document: URL = URL(fileURLWithPath: "")
+    @objc func setDocument(_ newSection: URL) {
+        document = newSection
+        
+        if (document.path.count > 1) && (configuration.count > 1) {
+            createCPDFView()
+        }
+    }
+    
+    private var password: String = ""
+    @objc func setPassword(_ newSection: String) {
+       password = newSection
+    }
+}

+ 10 - 12
ios/RCTCPDFViewManager.m

@@ -2,26 +2,24 @@
 //  RCTCPDFViewManager.m
 //  react-native-compdfkit-pdf
 //
-//  Created by Xiaolong Liu on 2024/7/4.
+//  Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
+//
+//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+//  This notice may not be removed from this file.
 //
 
 #import <Foundation/Foundation.h>
 #import <React/RCTViewManager.h>
 #import <MapKit/MapKit.h>
 
-@interface RCTCPDFViewManager : RCTViewManager
-
-@end
-
-@implementation RCTCPDFViewManager
+@interface RCT_EXTERN_MODULE(RCTCPDFReaderView, RCTViewManager)
 
-RCT_EXPORT_MODULE(RCTCPDFReaderView)
+RCT_EXPORT_VIEW_PROPERTY(configuration, NSString);
 
-- (UIView *)view
-{
-  return [[MKMapView alloc] init];
-}
+RCT_EXPORT_VIEW_PROPERTY(document, NSURL);
 
-RCT_EXPORT_VIEW_PROPERTY(zoomEnabled, BOOL)
+RCT_EXPORT_VIEW_PROPERTY(password, NSString);
 
 @end

+ 27 - 0
ios/RCTCPDFViewManager.swift

@@ -0,0 +1,27 @@
+//
+//  RCTCPDFViewManager.swift
+//  react-native-compdfkit-pdf
+//
+//  Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
+//
+//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
+//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
+//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
+//  This notice may not be removed from this file.
+//
+
+import UIKit
+
+@objc(RCTCPDFReaderView)
+class RCTCPDFReaderView: RCTViewManager {
+    
+    @objc override static func requiresMainQueueSetup() -> Bool {
+        return true
+    }
+    
+    @objc override func view() -> UIView! {
+        let rtcCPDFView = RCTCPDFView()
+        return rtcCPDFView
+    }
+  
+}