Browse Source

compdfkit(rn) - v2.1.2 android bug修复

liuxiaolong 6 months ago
parent
commit
3d39133e3e

+ 1 - 0
.gitignore

@@ -78,3 +78,4 @@ android/keystores/debug.keystore
 # generated by bob
 lib/
 .github/
+/example/ios/Podfile.lock

+ 1 - 0
CHANGELOG.md

@@ -3,6 +3,7 @@
 ### 2.1.2 - 19 Aug 2024
 
 * Added `CPDFReaderView` UI component.
+* Optimize document opening speed.
 
 
 

+ 10 - 4
android/build.gradle

@@ -85,11 +85,17 @@ repositories {
 
 
 dependencies {
-  implementation fileTree(include: ['*.jar'], dir: 'libs')
+  compileOnly fileTree(include: ['*.jar','*.aar'], dir: 'libs')
   implementation "com.facebook.react:react-native:+"
 
-  api "com.compdf:compdfkit:2.1.1"
-  api "com.compdf:compdfkit-ui:2.1.1"
-  api "com.compdf:compdfkit-tools:2.1.1"
+  api "com.compdf:compdfkit:2.1.2"
+  api "com.compdf:compdfkit-ui:2.1.2"
+  api "com.compdf:compdfkit-tools:2.1.2"
+  api 'com.github.bumptech.glide:glide:4.15.1'
+  annotationProcessor 'com.github.bumptech.glide:compiler:4.15.1'
+  api 'androidx.documentfile:documentfile:1.0.1'
+  api 'androidx.appcompat:appcompat:1.6.1'
+  api 'com.google.android.material:material:1.8.0'
+  api 'androidx.constraintlayout:constraintlayout:2.1.4'
 }
 

+ 25 - 31
android/src/main/java/com/compdfkitpdf/reactnative/view/CPDFView.java

@@ -13,22 +13,16 @@ import android.content.Context;
 import android.graphics.Rect;
 import android.net.Uri;
 import android.text.TextUtils;
-import android.util.AttributeSet;
-import android.util.Log;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.ViewTreeObserver;
 import android.widget.FrameLayout;
 import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
 import androidx.fragment.app.FragmentManager;
-import com.compdfkit.core.document.CPDFDocument;
 import com.compdfkit.tools.common.pdf.CPDFDocumentFragment;
 import com.compdfkit.tools.common.pdf.config.CPDFConfiguration;
-import com.compdfkit.ui.reader.CPDFReaderView;
 import com.compdfkitpdf.reactnative.util.CPDFDocumentUtil;
 import com.facebook.react.uimanager.ThemedReactContext;
-import java.util.HashMap;
 
 
 public class CPDFView extends FrameLayout {
@@ -71,26 +65,27 @@ public class CPDFView extends FrameLayout {
     initDocumentFragment();
   }
 
-  public void setPassword(String password){
+  public void setPassword(String password) {
     this.password = password;
     isPasswordSet = true;
     initDocumentFragment();
   }
 
-  public void setConfiguration(CPDFConfiguration configuration){
+  public void setConfiguration(CPDFConfiguration configuration) {
     this.configuration = configuration;
     initDocumentFragment();
   }
 
-  private void initDocumentFragment(){
-    if (TextUtils.isEmpty(document) || configuration == null || !isPasswordSet){
+  private void initDocumentFragment() {
+    if (TextUtils.isEmpty(document) || configuration == null || !isPasswordSet) {
       return;
     }
     if (documentFragment == null) {
       if (document.startsWith(CPDFDocumentUtil.CONTENT_SCHEME) ||
-        document.startsWith(CPDFDocumentUtil.FILE_SCHEME)){
-        documentFragment = CPDFDocumentFragment.newInstance(Uri.parse(document), password, configuration);
-      }else {
+        document.startsWith(CPDFDocumentUtil.FILE_SCHEME)) {
+        documentFragment = CPDFDocumentFragment.newInstance(Uri.parse(document), password,
+          configuration);
+      } else {
         documentFragment = CPDFDocumentFragment.newInstance(document, password, configuration);
       }
       prepareFragment(documentFragment, true);
@@ -122,26 +117,24 @@ public class CPDFView extends FrameLayout {
 
   private boolean mShouldHandleKeyboard = false;
 
-  private final ViewTreeObserver.OnGlobalLayoutListener mOnGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
-    @Override
-    public void onGlobalLayout() {
-      Rect r = new Rect();
-      getWindowVisibleDisplayFrame(r);
-      int screenHeight = getRootView().getHeight();
+  private final ViewTreeObserver.OnGlobalLayoutListener mOnGlobalLayoutListener = () -> {
+    Rect r = new Rect();
+    getWindowVisibleDisplayFrame(r);
+    int screenHeight = getRootView().getHeight();
 
-      // r.bottom is the position above soft keypad or device button.
-      // if keypad is shown, the r.bottom is smaller than that before.
-      int keypadHeight = screenHeight - r.bottom;
+    // r.bottom is the position above soft keypad or device button.
+    // if keypad is shown, the r.bottom is smaller than that before.
+    int keypadHeight = screenHeight - r.bottom;
 
-      if (keypadHeight > screenHeight * 0.15) { // 0.15 ratio is perhaps enough to determine keypad height.
-        // keyboard is opened
-        mShouldHandleKeyboard = true;
-      } else {
-        // keyboard is closed
-        if (mShouldHandleKeyboard) {
-          mShouldHandleKeyboard = false;
-          requestLayout();
-        }
+    if (keypadHeight
+      > screenHeight * 0.15) { // 0.15 ratio is perhaps enough to determine keypad height.
+      // keyboard is opened
+      mShouldHandleKeyboard = true;
+    } else {
+      // keyboard is closed
+      if (mShouldHandleKeyboard) {
+        mShouldHandleKeyboard = false;
+        requestLayout();
       }
     }
   };
@@ -153,6 +146,7 @@ public class CPDFView extends FrameLayout {
     layout(getLeft(), getTop(), getRight(), getBottom());
   };
 
+
   @Override
   public void requestLayout() {
     super.requestLayout();

+ 5 - 5
example/App.tsx

@@ -60,6 +60,11 @@ export default class App extends Component<Props> {
               </TouchableOpacity>
             ),
           })} />
+          <Stack.Screen name='Settings' component={SettingScreen} options={{
+            headerStyle: {
+              backgroundColor: '#FAFCFF',
+            },
+          }}/>
           <Stack.Screen name='CPDFReaderViewExample' component={CPDFReaderViewExampleScreen} options={{
             headerShadowVisible: false,
             headerTitleStyle: { fontSize: 16 },
@@ -67,11 +72,6 @@ export default class App extends Component<Props> {
               backgroundColor: '#FAFCFF',
             },
           }} />
-          <Stack.Screen name='Settings' component={SettingScreen} options={{
-            headerStyle: {
-              backgroundColor: '#FAFCFF',
-            },
-          }}/>
         </Stack.Navigator>
       </NavigationContainer>
     );

+ 1 - 1
example/android/app/build.gradle

@@ -122,7 +122,7 @@ android {
 }
 
 dependencies {
-  implementation fileTree(include: ['*.jar'], dir: 'libs')
+  implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
 
     // The version of react-native is set by the React Native Gradle Plugin
     implementation("com.facebook.react:react-android")

+ 1 - 0
example/android/app/src/main/AndroidManifest.xml

@@ -11,6 +11,7 @@
       android:icon="@mipmap/ic_launcher"
       android:roundIcon="@mipmap/ic_launcher_round"
       android:allowBackup="false"
+      android:requestLegacyExternalStorage="true"
       android:largeHeap="true"
       android:theme="@style/AppTheme">
 

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

@@ -618,7 +618,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;
@@ -690,7 +693,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;

+ 1 - 1
example/src/CPDFReaderViewExample.tsx

@@ -9,7 +9,7 @@
 
 import React, { useState, useEffect, useRef } from 'react';
 import { Platform } from 'react-native';
-import { CPDFReaderView, ComPDFKit,CPDFToolbarAction } from '@compdfkit_pdf_sdk/react_native';
+import { CPDFReaderView, ComPDFKit, CPDFToolbarAction } from '@compdfkit_pdf_sdk/react_native';
 import { useNavigation, useRoute, RouteProp } from '@react-navigation/native';
 
 type RootStackParamList = {

+ 1 - 1
example/src/examples.tsx

@@ -28,7 +28,7 @@ const examples = [
         title: 'Select External Files Example',
         description: `Select pdf document form system file manager`,
         action: (component: any)  => {
-            // Pick a PDF file from the local storage of Android or iOS device, 
+            // Pick a PDF file from the local storage of Android or iOS device,
             // this example uses the `react-native-document-picker` package,
             // If you want to use this example, please add this package to your project first.
             try {

+ 0 - 14
example/tsconfig.json

@@ -1,14 +0,0 @@
-{
-    "compilerOptions": {
-      "target": "esnext",
-      "module": "commonjs",
-      "strict": true,
-      "jsx": "react",
-      "moduleResolution": "node",
-      "esModuleInterop": true,
-      "skipLibCheck": true,
-      "forceConsistentCasingInFileNames": true
-    },
-    "exclude": ["node_modules", "build"]
-  }
-  

+ 1 - 1
src/view/CPDFReaderView.tsx

@@ -72,4 +72,4 @@ export class CPDFReaderView extends PureComponent<CPDFReaderViewProps, any> {
   }
 }
 
-const RCTCPDFReaderView = requireNativeComponent<CPDFReaderViewProps>('RCTCPDFReaderView');
+const RCTCPDFReaderView = requireNativeComponent<CPDFReaderViewProps>('RCTCPDFReaderView');