react-native-pdf-renderer 1.5.1 → 1.6.0

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
@@ -39,6 +39,21 @@ npm i -S react-native-pdf-renderer
39
39
 
40
40
  Go to the folder **your-project/ios** and run `pod install`, and you're done.
41
41
 
42
+ ### Android specific (optional)
43
+
44
+ Customize the [`androidx.recyclerview:recyclerview`](https://developer.android.com/jetpack/androidx/releases/recyclerview) version by setting `ext` in your `android/build.gradle` file.
45
+
46
+ Example:
47
+
48
+ ```gradle
49
+ buildscript {
50
+ ext {
51
+ recyclerviewVersion = "1.2.1"
52
+ }
53
+ ...
54
+ }
55
+ ```
56
+
42
57
  ## Basic usage
43
58
 
44
59
  There is only one component that you need to use to render the PDF file.
@@ -47,19 +62,19 @@ There is only one component that you need to use to render the PDF file.
47
62
  import PdfRendererView from 'react-native-pdf-renderer';
48
63
 
49
64
  const App = () => {
50
- return (
51
- <SafeAreaView style={{flex: 1}}>
52
- <PdfRendererView
53
- style={{backgroundColor: 'red'}}
54
- source="file:///path/to/local/file.pdf"
55
- distanceBetweenPages={16}
56
- maxZoom={5}
57
- onPageChange={(current, total) => {
58
- console.log(current, total);
59
- }}
60
- />
61
- </SafeAreaView>
62
- );
65
+ return (
66
+ <SafeAreaView style={{flex: 1}}>
67
+ <PdfRendererView
68
+ style={{backgroundColor: 'red'}}
69
+ source="file:///path/to/local/file.pdf"
70
+ distanceBetweenPages={16}
71
+ maxZoom={5}
72
+ onPageChange={(current, total) => {
73
+ console.log(current, total);
74
+ }}
75
+ />
76
+ </SafeAreaView>
77
+ );
63
78
  }
64
79
 
65
80
  export default App;
@@ -103,9 +118,9 @@ If you need `borderRadius`, the best option is to wrap the `PdfRendererView` in
103
118
 
104
119
  ```jsx
105
120
  <View style={{ flex: 1, borderRadius: 24, overflow: 'hidden' }}>
106
- <PdfRendererView
107
- // ...
108
- />
121
+ <PdfRendererView
122
+ // ...
123
+ />
109
124
  </View>
110
125
  ```
111
126
 
@@ -1,20 +1,56 @@
1
+ def safeAppExtGet(prop, fallback) {
2
+ def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
3
+ appProject?.ext?.has(prop) ? appProject.ext.get(prop) : fallback
4
+ }
5
+
6
+ def resolveReactNativeDirectory() {
7
+ def reactNativeLocation = safeAppExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
8
+ if (reactNativeLocation != null) {
9
+ return file(reactNativeLocation)
10
+ }
11
+
12
+ // monorepo workaround
13
+ // react-native can be hoisted or in project's own node_modules
14
+ def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
15
+ if (reactNativeFromProjectNodeModules.exists()) {
16
+ return reactNativeFromProjectNodeModules
17
+ }
18
+
19
+ def reactNativeFromNodeModulesWithReanimated = file("${projectDir}/../../react-native")
20
+ if (reactNativeFromNodeModulesWithReanimated.exists()) {
21
+ return reactNativeFromNodeModulesWithReanimated
22
+ }
23
+
24
+ throw new GradleException(
25
+ "Unable to resolve react-native location in node_modules. You should project extension property (in `app/build.gradle`) `REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
26
+ )
27
+ }
28
+
29
+ def reactNativeRootDir = resolveReactNativeDirectory()
30
+
31
+ def reactProperties = new Properties()
32
+ file("$reactNativeRootDir/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
33
+
34
+ def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
35
+ def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 1000 : REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
36
+
1
37
  buildscript {
2
- ext.safeExtGet = {prop, fallback ->
38
+ ext.safeExtGet = { prop, fallback ->
3
39
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
4
40
  }
41
+ ext.IS_ROOT = project == rootProject
5
42
 
6
43
  // The Android Gradle plugin is only required when opening the android folder stand-alone.
7
44
  // This avoids unnecessary downloads and potential conflicts when the library is included as a
8
45
  // module dependency in an application project.
9
- if (project == rootProject) {
46
+
47
+ if (IS_ROOT) {
10
48
  repositories {
11
49
  google()
12
50
  mavenCentral()
13
51
  }
14
-
15
52
  dependencies {
16
- //noinspection GradleDependency
17
- classpath("com.android.tools.build:gradle:4.2.2")
53
+ classpath "com.android.tools.build:gradle:7.3.1"
18
54
  }
19
55
  }
20
56
  }
@@ -22,14 +58,12 @@ buildscript {
22
58
  apply plugin: 'com.android.library'
23
59
 
24
60
  android {
25
- compileSdkVersion safeExtGet('compileSdkVersion', 30)
26
- //noinspection GradleDependency
27
- buildToolsVersion safeExtGet('buildToolsVersion', '30.0.2')
28
-
61
+ namespace "com.github.douglasjunior.reactNativePdfRenderer"
62
+ compileSdkVersion safeExtGet("compileSdkVersion", 33)
29
63
  defaultConfig {
30
64
  minSdkVersion safeExtGet('minSdkVersion', 21)
31
65
  //noinspection OldTargetApi
32
- targetSdkVersion safeExtGet('targetSdkVersion', 30)
66
+ targetSdkVersion safeExtGet('targetSdkVersion', 33)
33
67
  }
34
68
  lintOptions {
35
69
  abortOnError false
@@ -37,26 +71,29 @@ android {
37
71
  }
38
72
 
39
73
  repositories {
40
- repositories {
41
- mavenCentral()
42
- mavenLocal()
74
+ mavenCentral()
75
+ mavenLocal()
76
+ if (REACT_NATIVE_MINOR_VERSION < 71) {
43
77
  maven {
44
78
  // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
45
- url("$rootDir/../node_modules/react-native/android")
79
+ url "$reactNativeRootDir/android"
46
80
  }
47
81
  maven {
48
82
  // Android JSC is installed from npm
49
- url("$rootDir/../node_modules/jsc-android/dist")
83
+ url "$reactNativeRootDir/../jsc-android/dist"
50
84
  }
51
-
52
- google()
53
- maven { url 'https://www.jitpack.io' }
54
85
  }
86
+ google()
55
87
  }
56
88
 
57
89
  dependencies {
58
- //noinspection GradleDynamicVersion
59
- implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
90
+ if (REACT_NATIVE_MINOR_VERSION >= 71) {
91
+ implementation "com.facebook.react:react-android${IS_ROOT ? ':+' : ''}"
92
+ // version substituted by RNGP
93
+ } else {
94
+ // noinspection GradleDynamicVersion
95
+ implementation "com.facebook.react:react-native:+" // From node_modules
96
+ }
60
97
 
61
98
  implementation "androidx.recyclerview:recyclerview:${safeExtGet('recyclerViewVersion', '1.2.1')}"
62
99
  }
@@ -1,4 +1,3 @@
1
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
- package="com.github.douglasjunior.reactNativePdfRenderer" >
1
+ <manifest>
3
2
 
4
3
  </manifest>
@@ -1,63 +1,63 @@
1
- // MIT License
2
-
3
- // Copyright (c) 2023 Douglas Nassif Roma Junior
4
-
5
- // Permission is hereby granted, free of charge, to any person obtaining a copy
6
- // of this software and associated documentation files (the "Software"), to deal
7
- // in the Software without restriction, including without limitation the rights
8
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- // copies of the Software, and to permit persons to whom the Software is
10
- // furnished to do so, subject to the following conditions:
11
-
12
- // The above copyright notice and this permission notice shall be included in all
13
- // copies or substantial portions of the Software.
14
-
15
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- // SOFTWARE.
22
-
23
- package com.github.douglasjunior.reactNativePdfRenderer.modules;
24
-
25
- import java.util.HashSet;
26
- import java.util.Set;
27
-
28
- public class ObservableZoom {
29
- private final Set<ZoomChangeListener> listeners = new HashSet<>();
30
- private float zoom;
31
-
32
- public ObservableZoom(int initialZoom) {
33
- this.zoom = initialZoom;
34
- }
35
-
36
- public void addListener(ZoomChangeListener listener) {
37
- this.listeners.add(listener);
38
- }
39
-
40
- public void removeListener(ZoomChangeListener zoomListener) {
41
- this.listeners.remove(zoomListener);
42
- }
43
-
44
- private void notifyListeners() {
45
- for (ZoomChangeListener listener : listeners) {
46
- listener.onZoomChange(this.zoom);
47
- }
48
- }
49
-
50
- public float getZoom() {
51
- return zoom;
52
- }
53
-
54
- public void setZoom(float newZoom) {
55
- if (newZoom == this.zoom) return;
56
- this.zoom = newZoom;
57
- notifyListeners();
58
- }
59
-
60
- public interface ZoomChangeListener {
61
- void onZoomChange(float newZoom);
62
- }
63
- }
1
+ // MIT License
2
+
3
+ // Copyright (c) 2023 Douglas Nassif Roma Junior
4
+
5
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ // of this software and associated documentation files (the "Software"), to deal
7
+ // in the Software without restriction, including without limitation the rights
8
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ // copies of the Software, and to permit persons to whom the Software is
10
+ // furnished to do so, subject to the following conditions:
11
+
12
+ // The above copyright notice and this permission notice shall be included in all
13
+ // copies or substantial portions of the Software.
14
+
15
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ // SOFTWARE.
22
+
23
+ package com.github.douglasjunior.reactNativePdfRenderer.modules;
24
+
25
+ import java.util.HashSet;
26
+ import java.util.Set;
27
+
28
+ public class ObservableZoom {
29
+ private final Set<ZoomChangeListener> listeners = new HashSet<>();
30
+ private float zoom;
31
+
32
+ public ObservableZoom(int initialZoom) {
33
+ this.zoom = initialZoom;
34
+ }
35
+
36
+ public void addListener(ZoomChangeListener listener) {
37
+ this.listeners.add(listener);
38
+ }
39
+
40
+ public void removeListener(ZoomChangeListener zoomListener) {
41
+ this.listeners.remove(zoomListener);
42
+ }
43
+
44
+ private void notifyListeners() {
45
+ for (ZoomChangeListener listener : listeners) {
46
+ listener.onZoomChange(this.zoom);
47
+ }
48
+ }
49
+
50
+ public float getZoom() {
51
+ return zoom;
52
+ }
53
+
54
+ public void setZoom(float newZoom) {
55
+ if (newZoom == this.zoom) return;
56
+ this.zoom = newZoom;
57
+ notifyListeners();
58
+ }
59
+
60
+ public interface ZoomChangeListener {
61
+ void onZoomChange(float newZoom);
62
+ }
63
+ }
@@ -433,11 +433,14 @@ public class PdfRendererRecyclerView extends RecyclerView {
433
433
 
434
434
  float zoomFactor = Math.min(newZoom, scalingFactor);
435
435
 
436
- return Bitmap.createBitmap(
436
+ var bitmap = Bitmap.createBitmap(
437
437
  Math.round(scaledPageWidth * zoomFactor),
438
438
  Math.round(scaledPageHeight * zoomFactor),
439
439
  Bitmap.Config.ARGB_8888
440
440
  );
441
+ // Fill the bitmap with white color by default to prevent issues with transparent PDFs
442
+ bitmap.eraseColor(Color.WHITE);
443
+ return bitmap;
441
444
  }
442
445
 
443
446
  public void update(int position, float newZoom) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-pdf-renderer",
3
3
  "displayName": "React-Native Pdf Renderer",
4
- "version": "1.5.1",
4
+ "version": "1.6.0",
5
5
  "description": "⚛ A zoomable, blazing fast, zero dependencies, pure native, typed PDF Renderer for Android and iOS.",
6
6
  "main": "dist",
7
7
  "license": "MIT",