react-native-pdf 7.0.0 → 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -85,7 +85,7 @@ react-native link react-native-pdf
85
85
 
86
86
  ### Windows installation
87
87
  <details>
88
- <sumary>Windows details</summary>
88
+ <summary>Windows details</summary>
89
89
 
90
90
  - Open your solution in Visual Studio 2019 (eg. `windows\yourapp.sln`)
91
91
  - Right-click Solution icon in Solution Explorer > Add > Existing Project...
@@ -168,7 +168,12 @@ react-native run-ios
168
168
  ### ChangeLog
169
169
  <details>
170
170
  <summary>ChangeLog details</summary>
171
- v7.0.0
171
+ v7.0.2
172
+ 1. Fixed: `Loaded page is null` error when `bookmarks` is 0 (#978)
173
+ 2. Feature: agp 7.3+ fully supported (#980)
174
+ 3. Fixed: Downgrade pdfiumandroid version to 1.0.32
175
+
176
+ v7.0.1
172
177
  1. Fixed: not rendering on iOS
173
178
  2. Added: Android 16 KB Page Size support
174
179
  3. Fixed: crash issue in io.legere:pdfiumandroid that occurred due to multithreading
@@ -30,6 +30,19 @@ repositories {
30
30
 
31
31
  apply plugin: 'com.android.library'
32
32
 
33
+ def supportsNamespace() {
34
+ def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
35
+ def major = parsed[0].toInteger()
36
+ def minor = parsed[1].toInteger()
37
+
38
+ // Namespace support was added in 7.3.0
39
+ if (major == 7 && minor >= 3) {
40
+ return true
41
+ }
42
+
43
+ return major >= 8
44
+ }
45
+
33
46
  def resolveReactNativeDirectory() {
34
47
  def reactNativeLocation = safeExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
35
48
  if (reactNativeLocation != null) {
@@ -80,9 +93,13 @@ if (isNewArchitectureEnabled()) {
80
93
  }
81
94
 
82
95
  android {
83
- def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
84
- if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
96
+ if (supportsNamespace()) {
85
97
  namespace "org.wonday.pdf"
98
+ sourceSets {
99
+ main {
100
+ manifest.srcFile "src/main/AndroidManifestNew.xml"
101
+ }
102
+ }
86
103
  }
87
104
  compileSdkVersion safeExtGet('compileSdkVersion', 31)
88
105
 
@@ -126,6 +143,6 @@ dependencies {
126
143
  // The repo from zacharee is based on PdfiumAndroidKt, a much newer fork of PdfiumAndroid, with better maintenance and updated native libraries.
127
144
  implementation 'com.github.zacharee:AndroidPdfViewer:4.0.1'
128
145
  // Depend on PdfiumAndroidKt directly so this can be updated independently of AndroidPdfViewer as updates are provided.
129
- implementation 'io.legere:pdfiumandroid:1.0.34'
146
+ implementation 'io.legere:pdfiumandroid:1.0.32'
130
147
  implementation 'com.google.code.gson:gson:2.13.2'
131
148
  }
@@ -0,0 +1,4 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+
3
+
4
+ </manifest>
@@ -99,6 +99,11 @@ public class PdfManager extends SimpleViewManager<PdfView> implements RNPDFPdfVi
99
99
  // NOOP on Android
100
100
  }
101
101
 
102
+ @Override
103
+ public void setShowsVerticalScrollIndicator(PdfView view, boolean value) {
104
+ // NOOP on Android
105
+ }
106
+
102
107
  @ReactProp(name = "enableRTL")
103
108
  public void setEnableRTL(PdfView view, boolean enableRTL) {
104
109
  pdfView.setEnableRTL(enableRTL);
@@ -139,11 +144,6 @@ public class PdfManager extends SimpleViewManager<PdfView> implements RNPDFPdfVi
139
144
  pdfView.setEnablePaging(enablePaging);
140
145
  }
141
146
 
142
- @Override
143
- public void setEnableRTL(PdfView view, boolean value) {
144
- // NOOP on Android
145
- }
146
-
147
147
  @ReactProp(name = "fitPolicy")
148
148
  public void setFitPolicy(PdfView pdfView, int fitPolicy) {
149
149
  pdfView.setFitPolicy(fitPolicy);
@@ -9,11 +9,13 @@
9
9
  package org.wonday.pdf;
10
10
 
11
11
  import java.io.File;
12
+ import java.io.IOException;
12
13
 
13
14
  import android.content.ContentResolver;
14
15
  import android.content.Context;
15
16
  import android.os.Handler;
16
17
  import android.os.Looper;
18
+ import android.os.ParcelFileDescriptor;
17
19
  import android.util.SizeF;
18
20
  import android.view.View;
19
21
  import android.view.ViewGroup;
@@ -22,7 +24,7 @@ import android.net.Uri;
22
24
  import android.util.AttributeSet;
23
25
  import android.view.MotionEvent;
24
26
  import android.graphics.Canvas;
25
-
27
+ import android.graphics.pdf.PdfRenderer;
26
28
 
27
29
  import com.facebook.react.uimanager.ThemedReactContext;
28
30
  import com.facebook.react.uimanager.UIManagerHelper;
@@ -87,10 +89,6 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
87
89
  private int oldW = 0;
88
90
  private int oldH = 0;
89
91
 
90
- private int totalPages = 0;
91
- private int[] pagesArrays;
92
- private int bookmarks = 0;
93
-
94
92
  public PdfView(Context context, AttributeSet set){
95
93
  super(context, set);
96
94
  }
@@ -249,7 +247,7 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
249
247
  if (originalWidth == 0) {
250
248
  originalWidth = pageWidth;
251
249
  }
252
-
250
+
253
251
  if (lastPageWidth>0 && lastPageHeight>0 && (pageWidth!=lastPageWidth || pageHeight!=lastPageHeight)) {
254
252
  // maybe change by other instance, restore zoom setting
255
253
  Constants.Pinch.MINIMUM_ZOOM = this.minScale;
@@ -285,36 +283,19 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
285
283
  this.drawPdf();
286
284
  }
287
285
 
286
+ private int getPdfPageCount(File pdfFile) throws IOException {
287
+ ParcelFileDescriptor fileDescriptor =
288
+ ParcelFileDescriptor.open(pdfFile, ParcelFileDescriptor.MODE_READ_ONLY);
289
+ PdfRenderer renderer = new PdfRenderer(fileDescriptor);
290
+ int pageCount = renderer.getPageCount();
291
+ renderer.close();
292
+ fileDescriptor.close();
293
+ return pageCount;
294
+ }
295
+
288
296
  public void drawPdf() {
289
297
  showLog(format("drawPdf path:%s %s", this.path, this.page));
290
- File file = new File(this.path);
291
-
292
- if (file.exists()) {
293
- try {
294
- ParcelFileDescriptor fileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
295
- PdfRenderer pdfRenderer = new PdfRenderer(fileDescriptor);
296
- this.totalPages = pdfRenderer.getPageCount();
297
- int[] pagesArrays = new int[this.totalPages];
298
- if (this.enableRTL) {
299
- if(this.page>0){
300
- this.page= this.bookmarks-1;
301
- }else{
302
- this.page=this.totalPages;
303
- }
304
- for (int i = totalPages-1; i>=0; i--) {
305
- pagesArrays[i] =totalPages-1- i;
306
- }
307
- this.pagesArrays = pagesArrays;
308
-
309
- }else{
310
- this.pagesArrays = null;
311
- this.page=this.bookmarks-1;
312
- }
313
- } catch (IOException e) {
314
- Log.e("error", "error read PDF", e);
315
- }
316
- }
317
-
298
+
318
299
  if (this.path != null){
319
300
 
320
301
  // set scale
@@ -340,9 +321,7 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
340
321
  configurator = this.fromUri(getURI(this.path));
341
322
  }
342
323
 
343
- configurator
344
- .pages(this.pagesArrays)
345
- .defaultPage(this.page)
324
+ configurator.defaultPage(this.page-1)
346
325
  .swipeHorizontal(this.horizontal)
347
326
  .onPageChange(this)
348
327
  .onLoad(this)
@@ -359,7 +338,24 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
359
338
  .enableSwipe(!this.singlePage && this.scrollEnabled)
360
339
  .enableDoubletap(!this.singlePage && this.enableDoubleTapZoom)
361
340
  .enableAnnotationRendering(this.enableAnnotationRendering)
362
- .linkHandler(this);
341
+ .linkHandler(this)
342
+ ;
343
+
344
+ if (enableRTL) {
345
+ try {
346
+ int pageCount = getPdfPageCount(new File(this.path));
347
+ int[] reversedPages = new int[pageCount];
348
+ for (int i=0; i<pageCount; i++) {
349
+ reversedPages[i] = pageCount-1 - i;
350
+ }
351
+ configurator.pages(reversedPages);
352
+ if(this.page != 1){
353
+ this.page = pageCount;
354
+ }
355
+ } catch (IOException e) {
356
+ Log.e("error", "error while reading PDF", e);
357
+ }
358
+ }
363
359
 
364
360
  if (this.singlePage) {
365
361
  configurator.pages(this.page-1);
@@ -382,14 +378,12 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
382
378
 
383
379
  // page start from 1
384
380
  public void setPage(int page) {
385
- this.page = page;
386
- this.bookmarks = page;
381
+ this.page = Math.max(page, 1);
387
382
  }
388
383
 
389
- public void setEnableRTL(boolean enableRTL){
390
- this.enableRTL= enableRTL;
391
-
392
- }
384
+ public void setEnableRTL(boolean enableRTL) {
385
+ this.enableRTL = enableRTL;
386
+ }
393
387
 
394
388
  public void setScale(float scale) {
395
389
  this.scale = scale;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-pdf",
3
- "version": "7.0.0",
3
+ "version": "7.0.2",
4
4
  "summary": "A react native PDF view component",
5
5
  "description": "A react native PDF view component, support ios and android platform",
6
6
  "main": "index.js",