Browse Source

compdfkit(rn) - 新增RN层接口注释,修改初始化方法返回值

liuxiaolong 10 months ago
parent
commit
c6fa16fdfd

+ 14 - 5
android/src/main/java/com/compdfkitpdf/reactnative/CompdfkitPdfModule.java

@@ -25,6 +25,8 @@ import com.facebook.react.bridge.ReactApplicationContext;
 import com.facebook.react.bridge.ReactContext;
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
 import com.facebook.react.bridge.ReactMethod;
+import com.facebook.react.bridge.ReadableMap;
+import com.facebook.react.bridge.ReadableMapKeySetIterator;
 
 /**
  * RN and Android native ComPDFKit SDK interaction class
@@ -36,7 +38,7 @@ public class CompdfkitPdfModule extends ReactContextBaseJavaModule {
 
   public static final String NAME = "ComPDFKit";
 
-  public static final String ASSETS_SCHEME = "file://android_assets";
+  public static final String ASSETS_SCHEME = "file:///android_asset";
 
   public static final String CONTENT_SCHEME = "content://";
 
@@ -77,7 +79,6 @@ public class CompdfkitPdfModule extends ReactContextBaseJavaModule {
    *
    * Usage example:<br/>
    * <pre>
-
    * ComPDFKit.getSDKBuildTag().then((buildTag : string) => {
    *   console.log('ComPDFKit Build Tag:', buildTag)
    * })
@@ -89,6 +90,12 @@ public class CompdfkitPdfModule extends ReactContextBaseJavaModule {
     promise.resolve(CPDFSdk.getSDKBuildTag());
   }
 
+
+  @ReactMethod
+  public void testConfig(String json){
+    Log.e(TAG,  json);
+  }
+
   /**
    * Initialize the ComPDFKit PDF SDK using offline authentication.<br/>
    * <p></p>
@@ -100,9 +107,10 @@ public class CompdfkitPdfModule extends ReactContextBaseJavaModule {
    * @param license The offline license.
    */
   @ReactMethod
-  public void init_(String license) {
+  public void init_(String license, Promise promise) {
     CPDFSdk.init(mReactContext, license, true, (code, msg) -> {
       Log.e(TAG, "init_: code:" + code + ", msg:" + msg);
+      promise.resolve(code == CPDFSdk.VERIFY_SUCCESS);
     });
   }
 
@@ -121,9 +129,10 @@ public class CompdfkitPdfModule extends ReactContextBaseJavaModule {
    * @param iosOnlineLicense     The online license for the ComPDFKit SDK on iOS platform.
    */
   @ReactMethod
-  public void initialize(String androidOnlineLicense, String iosOnlineLicense) {
+  public void initialize(String androidOnlineLicense, String iosOnlineLicense, Promise promise) {
     CPDFSdk.init(mReactContext, androidOnlineLicense, false, (code, msg) -> {
       Log.e(TAG, "initialize: code:" + code + ", msg:" + msg);
+      promise.resolve(code == CPDFSdk.VERIFY_SUCCESS);
     });
   }
 
@@ -148,7 +157,7 @@ public class CompdfkitPdfModule extends ReactContextBaseJavaModule {
    *
    * (Android) For assets path: <br/>
    * <pre>
-   *   document = "file://android_assets/..."
+   *   document = "file:///android_asset/..."
    * </pre>
    *
    * @param document          The document URI or file path.

File diff suppressed because it is too large
+ 19 - 3
example/App.tsx


+ 116 - 15
src/index.tsx

@@ -1,23 +1,124 @@
 import { NativeModules } from 'react-native';
 
 declare module 'react-native' {
-    interface NativeModulesStatic {
-      ComPDFKit: {
-        getVersionCode() : () =>  Promise<string>;
-        getSDKBuildTag() : () => Promise<string>;
-        init_: (license : string) => void;
-        initialize: (androidOnlineLicense: string, iosOnlineLicense : string) => void;
-        openDocument : (document : string, password : string, configuration : string) => void;
-      };
-    }
+  interface NativeModulesStatic {
+    ComPDFKit: {
+      testConfig(configuration: string): () => void;
+      /**
+       * Get the version number of the ComPDFKit SDK.
+       * For example : '2.0.0'
+       * @memberof ComPDFKit
+       * @returns { Promise<string> } A Promise returning ComPDFKit PDF SDK Version Code
+       * 
+       * @example
+       * ComPDFKit.getVersionCode().then((versionCode : string) => {
+       *   console.log('ComPDFKit SDK Version:', versionCode)
+       * })
+       */
+      getVersionCode(): () => Promise<string>;
+      /**
+       * Get the build tag of the ComPDFKit PDF SDK.
+       * 
+       * For example: "build_beta_2.0.0_42db96987_202404081007"
+       * @memberof ComPDFKit
+       * @returns { Promise<string> } A Promise returning ComPDFKit PDF SDK Build Tag.
+       * 
+       * @example
+       * ComPDFKit.getSDKBuildTag().then((buildTag : string) => {
+       *  console.log('ComPDFKit Build Tag:', buildTag)
+       * })
+       */
+      getSDKBuildTag(): () => Promise<string>;
+      /**
+       * Initialize the ComPDFKit PDF SDK using offline authentication.
+       * Each ComPDFKit license is bound to a specific app bundle ID(Android Application ID).
+       * 
+       * @method init_
+       * @memberof ComPDFKit
+       * @param { string } [license] Your ComPDFKit for React Native license key.
+       * @returns { Promise<boolean> } Returns ```true``` if initialization is successful, otherwise returns ```false```.
+       * 
+       * @example
+       * ComPDFKit.init_('your compdfkit license')
+       * 
+       */
+      init_: (license: string) => Promise<boolean>;
+      /**
+       * Initialize the ComPDFKit PDF SDK using online authentication.
+       * Each ComPDFKit license is bound to a specific app bundle ID(Android Application ID).
+       * 
+       * @method initialize
+       * @memberof ComPDFKit
+       * @param { string } [androidOnlineLicense] Your ComPDFKit for React Native Android online license key.
+       * @param { string } [iosOnlineLicense] Your ComPDFKit for React Native iOS online license key.
+       * @returns { Promise<boolean> } Returns ```true``` if initialization is successful, otherwise returns ```false```.
+       * 
+       * @example
+       * ComPDFKit.initialize('your android compdfkit license', 'your ios compdfkit license')
+       */
+      initialize: (androidOnlineLicense: string, iosOnlineLicense: string) => Promise<boolean>;
+      /**
+       * Used to present a PDF document.
+       * @method openDocument
+       * @memberof ComPDFKit
+       * @param { string } [document]  document The path to the PDF document to be presented.
+       * 
+       * * (Android) For local storage file path:
+       * ```tsx
+       *    document = 'file:///storage/emulated/0/Download/sample.pdf'
+       * ```
+       * * (Android) For content Uri: 
+       * ```tsx
+       *    document = 'content://...'
+       * ```
+       * * (Android) For assets path:
+       * ```tsx
+       *    document = "file:///android_asset/..."
+       * ```
+       * ---
+       * * ios
+       * ```tsx
+       *    document = 'pdf_document.pdf'
+       * ```
+       * 
+       * @param { string } [password] PDF document password.
+       * @param { string } [configuration] Configuration objects to customize the appearance and behavior of ComPDFKit. See [CPDFConfiguration](configuration/CPDFConfiguration.ts)
+       * @returns { void }
+       * 
+       * @example
+       * const fileName = 'pdf_document.pdf';
+       * const document = 
+       * Platform.OS === 'ios' ? fileName
+       * : 'file:///android_asset/' + fileName;
+       * 
+       * const configuration : CPDFConfiguration = {
+       *    modeConfig: {
+       *       initialViewMode: CPDFModeConfig.ViewMode.VIEWER,
+       *       availableViewModes: [
+       *         CPDFModeConfig.ViewMode.VIEWER,
+       *         CPDFModeConfig.ViewMode.ANNOTATIONS,
+       *         CPDFModeConfig.ViewMode.CONTENT_EDITOR,
+       *         CPDFModeConfig.ViewMode.FORMS,
+       *         CPDFModeConfig.ViewMode.SIGNATURES
+       *       ]
+       *     }
+       * }
+       * 
+       * ComPDFKit.openDocument(document, 'password', JSON.stringify(configuration))
+       * 
+       */
+      openDocument: (document: string, password: string, configuration: string) => void;
+    };
   }
+}
 
-interface ComPDFKit{
-    getVersionCode() : Promise<string>;
-    getSDKBuildTag() : Promise<string>;
-    init_(license : string) : void;
-    initialize(androidOnlineLicense : string,  iosOnlineLicense : string) : void;
-    openDocument(document : string, password : string, configurationJson : string) : void;
+interface ComPDFKit {
+  testConfig(configuration: string): void;
+  getVersionCode(): Promise<string>;
+  getSDKBuildTag(): Promise<string>;
+  init_(license: string): Promise<boolean>;
+  initialize(androidOnlineLicense: string, iosOnlineLicense: string): Promise<boolean>;
+  openDocument(document: string, password: string, configurationJson: string): void;
 }
 
 const ComPDFKit = NativeModules.ComPDFKit