Selaa lähdekoodia

PDFTool(Android) - 修复RN中页码指示器显示异常问题

liuxiaolong 3 kuukautta sitten
vanhempi
commit
c402e8ad33

BIN
ComPDFKit_Repo/compdfkit-ui/ComPDFKit-UI.aar


BIN
ComPDFKit_Repo/compdfkit/ComPDFKit.aar


+ 4 - 4
ComPDFKit_Tools/build.gradle

@@ -52,11 +52,11 @@ dependencies {
 
     api fileTree(include: ['*.jar'], dir: 'libs')
     // use this
-//    api project(path:':ComPDFKit_Repo:compdfkit')
-//    api project(path:':ComPDFKit_Repo:compdfkit-ui')
+    api project(path:':ComPDFKit_Repo:compdfkit')
+    api project(path:':ComPDFKit_Repo:compdfkit-ui')
     // or use
-    api ('com.compdf:compdfkit:2.2.0-SNAPSHOT')
-    api ('com.compdf:compdfkit-ui:2.2.0-SNAPSHOT')
+//    api ('com.compdf:compdfkit:2.2.0-SNAPSHOT')
+//    api ('com.compdf:compdfkit-ui:2.2.0-SNAPSHOT')
 //    api project(path: ':ComPDFKit')
 //    api project(path: ':ComPDFKit-UI')
     api 'com.github.bumptech.glide:glide:4.15.1'

+ 4 - 1
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/annotation/pdfannotationlist/dialog/CPDFEditReplyDialogFragment.java

@@ -78,7 +78,10 @@ public class CPDFEditReplyDialogFragment extends CBasicBottomSheetDialogFragment
     toolBar = rootView.findViewById(R.id.tool_bar);
     editText = rootView.findViewById(R.id.tv_reply_content);
     btnDone = rootView.findViewById(R.id.btn_save);
-    toolBar.setBackBtnClickListener(v -> dismiss());
+    toolBar.setBackBtnClickListener(v -> {
+      CViewUtils.hideKeyboard(editText);
+      dismiss();
+    });
     btnDone.setOnClickListener(v -> {
       CViewUtils.hideKeyboard(editText);
       editText.postDelayed(()->{

+ 27 - 27
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/views/pdfview/CPDFPageIndicatorView.java

@@ -11,9 +11,9 @@ package com.compdfkit.tools.common.views.pdfview;
 
 
 import android.content.Context;
-import android.graphics.Color;
 import android.util.AttributeSet;
 import android.view.Gravity;
+import android.view.LayoutInflater;
 import android.widget.LinearLayout;
 
 import androidx.annotation.Nullable;
@@ -45,7 +45,11 @@ public class CPDFPageIndicatorView extends LinearLayout {
      */
     private OnPageIndicatorClickListener pageIndicatorClickListener;
 
-    private AppCompatTextView tvPageIndicator;
+    private AppCompatTextView tvPageIndex;
+
+    private AppCompatTextView tvTotalPage;
+
+    private boolean isRNMeasureLayout = false;
 
     public CPDFPageIndicatorView(Context context) {
         this(context, null);
@@ -65,23 +69,11 @@ public class CPDFPageIndicatorView extends LinearLayout {
      * Initializes the view by creating and configuring the text view and adding it to the layout.
      */
     private void initView(){
-        // create the text view for displaying the page indicator
-        tvPageIndicator = new AppCompatTextView(getContext());
-        // set layout params for the text view
-        LinearLayout.LayoutParams currentPageLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
-        currentPageLayoutParams.gravity = Gravity.CENTER;
-        int horizontalMargin = CDimensUtils.dp2px(getContext(), 8);
-        int verticalMargin = CDimensUtils.dp2px(getContext(), 4);
-        currentPageLayoutParams.setMargins(horizontalMargin, verticalMargin, horizontalMargin, verticalMargin);
-//        tvPageIndicator.setLayoutParams(currentPageLayoutParams);
-        // set text color to white
-        tvPageIndicator.setTextColor(Color.WHITE);
-        tvPageIndicator.setGravity(Gravity.CENTER);
-        tvPageIndicator.setMinimumWidth(CDimensUtils.dp2px(getContext(), 45));
-        // add the text view to the layout
-        addView(tvPageIndicator, currentPageLayoutParams);
-        // set background resource for the layout
-        setBackgroundResource(R.drawable.tools_pdf_page_indactor_bg);
+        LayoutInflater.from(getContext()).inflate(R.layout.tools_page_indicator_view, this);
+        setGravity(Gravity.CENTER_HORIZONTAL);
+        tvPageIndex = findViewById(R.id.tv_page_index);
+        tvTotalPage = findViewById(R.id.tv_page_count);
+
         // set click listener for the layout
         setOnClickListener(v -> {
             if (pageIndicatorClickListener != null) {
@@ -97,7 +89,9 @@ public class CPDFPageIndicatorView extends LinearLayout {
      */
     public void setTotalPage(int total){
         this.totalPage = total;
-        updatePageIndicator();
+        if (tvTotalPage != null) {
+            tvTotalPage.setText(totalPage + "");
+        }
     }
     /**
 
@@ -106,17 +100,23 @@ public class CPDFPageIndicatorView extends LinearLayout {
      */
     public void setCurrentPageIndex(int pageIndex){
         this.currentPageIndex = pageIndex + 1;
-        updatePageIndicator();
+        if (tvPageIndex != null) {
+            tvPageIndex.setText(currentPageIndex + "");
+        }
+        if (isRNMeasureLayout){
+            measure(
+                    MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
+                    MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY));
+            layout(getLeft(), getTop(), getRight(), getBottom());
+        }
     }
-    /**
 
-     Updates the text view to display the current page index and the total number of pages.
-     */
-    private void updatePageIndicator(){
-        tvPageIndicator.setText(currentPageIndex + "/" + totalPage);
+    public void setRNMeasureLayout(boolean RNMeasureLayout) {
+        isRNMeasureLayout = RNMeasureLayout;
+        invalidate();
     }
-    /**
 
+    /**
      Sets the listener for page indicator click events.
      @param pageIndicatorClickListener the listener to be set
      */

+ 2 - 2
ComPDFKit_Tools/src/main/java/com/compdfkit/tools/common/views/pdfview/CPDFViewCtrl.java

@@ -593,12 +593,12 @@ public class CPDFViewCtrl extends ConstraintLayout implements IReaderViewCallbac
             return;
         }
         removeView(indicatorView);
-        LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
+        LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
         layoutParams.startToStart = LayoutParams.PARENT_ID;
         layoutParams.endToEnd = LayoutParams.PARENT_ID;
         layoutParams.bottomToBottom = LayoutParams.PARENT_ID;
         int margin = CDimensUtils.dp2px(getContext(), 16);
-        layoutParams.setMargins(margin, 0, 0, pageIndicatorMarginBottom);
+        layoutParams.setMargins(margin, 0, margin, pageIndicatorMarginBottom);
         indicatorView.setLayoutParams(layoutParams);
         indicatorView.setAlpha(0F);
         addView(indicatorView);

+ 38 - 0
ComPDFKit_Tools/src/main/res/layout/tools_page_indicator_view.xml

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:background="@drawable/tools_pdf_page_indactor_bg"
+    android:orientation="horizontal"
+    android:minWidth="60dp"
+    android:gravity="center_horizontal"
+    android:layout_gravity="center"
+    android:paddingHorizontal="8dp"
+    android:paddingVertical="4dp">
+
+    <androidx.appcompat.widget.AppCompatTextView
+        android:id="@+id/tv_page_index"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:textColor="@android:color/white"
+        android:textSize="12sp"
+        tools:text="1" />
+
+    <androidx.appcompat.widget.AppCompatTextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="/"
+        android:textColor="@android:color/white"
+        android:textSize="12sp" />
+
+    <androidx.appcompat.widget.AppCompatTextView
+        android:id="@+id/tv_page_count"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:textColor="@android:color/white"
+        android:textSize="12sp"
+        tools:text="1" />
+
+
+</LinearLayout>

+ 1 - 1
config.gradle

@@ -3,7 +3,7 @@ ext {
             COMPILESDK: 34,
             MINSDK: 21,
             TARGETSDK: 34,
-            VERSIONCODE: 1016
+            VERSIONCODE: 1017
     ]
     sdk = [
             COMPDFKIT_SDK_VERSION : "2.2.0",

+ 1 - 1
settings.gradle

@@ -3,7 +3,7 @@ pluginManagement {
         google()
         mavenCentral()
         gradlePluginPortal()
-
+        mavenLocal()
     }
 }
 dependencyResolutionManagement {