react-native-pdf-renderer 0.0.5 → 1.0.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 +22 -11
- package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererRecyclerView.java +42 -19
- package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererViewManager.java +0 -2
- package/dist/PdfRendererView.js +12 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/react-native-pdf-renderer)
|
|
5
5
|
[](#install-with-react-native-link)
|
|
6
6
|
|
|
7
|
-
⚛ A blazing fast, zero dependencies, pure native PDF Renderer for Android and iOS.
|
|
7
|
+
⚛ A blazing fast, zero dependencies, pure native, typed PDF Renderer for Android and iOS.
|
|
8
8
|
|
|
9
9
|
|Android|iOS|
|
|
10
10
|
|-|-|
|
|
@@ -38,15 +38,17 @@ import PdfRendererView from 'react-native-pdf-renderer';
|
|
|
38
38
|
|
|
39
39
|
const App = () => {
|
|
40
40
|
return (
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
<SafeAreaView style={{flex: 1}}>
|
|
42
|
+
<PdfRendererView
|
|
43
|
+
style={{backgroundColor: 'red'}}
|
|
44
|
+
source="file:///path/to/local/file.pdf"
|
|
45
|
+
distanceBetweenPages={16}
|
|
46
|
+
maxZoom={5}
|
|
47
|
+
onPageChange={(current, total) => {
|
|
48
|
+
console.log(current, total);
|
|
49
|
+
}}
|
|
50
|
+
/>
|
|
51
|
+
</SafeAreaView>
|
|
50
52
|
);
|
|
51
53
|
}
|
|
52
54
|
|
|
@@ -77,7 +79,16 @@ New features, bug fixes and improvements are welcome! For questions and suggesti
|
|
|
77
79
|
<a href="https://www.patreon.com/douglasjunior"><img src="http://i.imgur.com/xEO164Z.png" alt="Become a Patron!" width="200" /></a>
|
|
78
80
|
[](https://paypal.me/douglasnassif)
|
|
79
81
|
|
|
80
|
-
##
|
|
82
|
+
## Thanks to
|
|
83
|
+
|
|
84
|
+
The creation of this lib was only possible thanks to the help of the community:
|
|
85
|
+
|
|
86
|
+
- RecyclerView `notifyDataSetChanged()` not working on React Native: https://stackoverflow.com/a/49381907/2826279
|
|
87
|
+
- Add pinch to zoom on RecyclerView: https://stackoverflow.com/a/37895783/2826279
|
|
88
|
+
- Using `Matrix` to handle zoom in a View: https://stackoverflow.com/a/55299327/2826279
|
|
89
|
+
- Daniel Felipe Sartório for the help with Android native
|
|
90
|
+
|
|
91
|
+
## License
|
|
81
92
|
|
|
82
93
|
```
|
|
83
94
|
The MIT License (MIT)
|
|
@@ -30,7 +30,6 @@ import android.graphics.Color;
|
|
|
30
30
|
import android.graphics.Matrix;
|
|
31
31
|
import android.graphics.pdf.PdfRenderer;
|
|
32
32
|
import android.os.ParcelFileDescriptor;
|
|
33
|
-
import android.util.Log;
|
|
34
33
|
import android.util.TypedValue;
|
|
35
34
|
import android.view.GestureDetector;
|
|
36
35
|
import android.view.MotionEvent;
|
|
@@ -50,12 +49,12 @@ import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
|
50
49
|
|
|
51
50
|
import java.io.File;
|
|
52
51
|
import java.io.IOException;
|
|
53
|
-
import java.util.Arrays;
|
|
54
52
|
|
|
55
53
|
public class PdfRendererRecyclerView extends RecyclerView {
|
|
56
54
|
private final ViewGroup mParent;
|
|
57
55
|
private final GestureDetector mGestureDetector;
|
|
58
56
|
private boolean mRequestedLayout = false;
|
|
57
|
+
private float mMinZoom = 1;
|
|
59
58
|
private float mMaxZoom = 5;
|
|
60
59
|
private float mDistanceBetweenPages = 0;
|
|
61
60
|
private int mWidth;
|
|
@@ -150,7 +149,7 @@ public class PdfRendererRecyclerView extends RecyclerView {
|
|
|
150
149
|
|
|
151
150
|
@Override
|
|
152
151
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
|
153
|
-
super.onSizeChanged(w,h,oldw,oldh);
|
|
152
|
+
super.onSizeChanged(w, h, oldw, oldh);
|
|
154
153
|
float scale = Math.max(w / mWidth, h / mHeight);
|
|
155
154
|
mMatrix.setScale(scale, scale);
|
|
156
155
|
mMatrix.postTranslate((w - scale * mWidth) / 2f, (h - scale * mHeight) / 2f);
|
|
@@ -161,9 +160,6 @@ public class PdfRendererRecyclerView extends RecyclerView {
|
|
|
161
160
|
public boolean onTouchEvent(MotionEvent e) {
|
|
162
161
|
mScaleDetector.onTouchEvent(e);
|
|
163
162
|
mGestureDetector.onTouchEvent(e);
|
|
164
|
-
if (mScaleDetector.isInProgress()) {
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
163
|
return super.onTouchEvent(e);
|
|
168
164
|
}
|
|
169
165
|
|
|
@@ -192,14 +188,11 @@ public class PdfRendererRecyclerView extends RecyclerView {
|
|
|
192
188
|
float[] values = new float[9];
|
|
193
189
|
mMatrix.getValues(values);
|
|
194
190
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
float scaleX = Math.min(Math.max(values[0], 1), mMaxZoom);
|
|
199
|
-
float posX = values[2];
|
|
191
|
+
float scaleX = Math.min(Math.max(values[Matrix.MSCALE_X], mMinZoom), mMaxZoom);
|
|
192
|
+
float posX = values[Matrix.MTRANS_X];
|
|
200
193
|
|
|
201
|
-
float scaleY = Math.min(Math.max(values[
|
|
202
|
-
float posY = values[
|
|
194
|
+
float scaleY = Math.min(Math.max(values[Matrix.MSCALE_Y], mMinZoom), mMaxZoom);
|
|
195
|
+
float posY = values[Matrix.MTRANS_Y];
|
|
203
196
|
|
|
204
197
|
float maxPosX = mWidth - mWidth * scaleX;
|
|
205
198
|
float maxPosY = mHeight - mHeight * scaleY;
|
|
@@ -214,14 +207,12 @@ public class PdfRendererRecyclerView extends RecyclerView {
|
|
|
214
207
|
else if (posY < maxPosY)
|
|
215
208
|
posY = maxPosY;
|
|
216
209
|
|
|
217
|
-
values[
|
|
218
|
-
values[
|
|
219
|
-
values[
|
|
220
|
-
values[
|
|
210
|
+
values[Matrix.MSCALE_X] = scaleX;
|
|
211
|
+
values[Matrix.MTRANS_X] = posX;
|
|
212
|
+
values[Matrix.MSCALE_Y] = scaleY;
|
|
213
|
+
values[Matrix.MTRANS_Y] = posY;
|
|
221
214
|
|
|
222
215
|
mMatrix.setValues(values);
|
|
223
|
-
|
|
224
|
-
Log.d("mMatrix2", Arrays.toString(values) + "");
|
|
225
216
|
}
|
|
226
217
|
|
|
227
218
|
/**
|
|
@@ -243,7 +234,16 @@ public class PdfRendererRecyclerView extends RecyclerView {
|
|
|
243
234
|
private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
|
|
244
235
|
@Override
|
|
245
236
|
public boolean onScale(ScaleGestureDetector detector) {
|
|
237
|
+
float[] values = new float[9];
|
|
238
|
+
mMatrix.getValues(values);
|
|
239
|
+
|
|
240
|
+
float zoom = values[Matrix.MSCALE_X];
|
|
246
241
|
float factor = detector.getScaleFactor();
|
|
242
|
+
|
|
243
|
+
if (zoom >= mMaxZoom && factor > 1) {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
247
|
mMatrix.postScale(factor, factor, getWidth() / 2f, getHeight() / 2f);
|
|
248
248
|
validateMatrixLimits();
|
|
249
249
|
ViewCompat.postInvalidateOnAnimation(PdfRendererRecyclerView.this);
|
|
@@ -259,6 +259,29 @@ public class PdfRendererRecyclerView extends RecyclerView {
|
|
|
259
259
|
ViewCompat.postInvalidateOnAnimation(PdfRendererRecyclerView.this);
|
|
260
260
|
return true;
|
|
261
261
|
}
|
|
262
|
+
|
|
263
|
+
@Override
|
|
264
|
+
public boolean onDoubleTap(@NonNull MotionEvent e) {
|
|
265
|
+
if (e.getPointerCount() > 1) {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
float[] values = new float[9];
|
|
270
|
+
mMatrix.getValues(values);
|
|
271
|
+
|
|
272
|
+
float currentZoom = values[Matrix.MSCALE_X];
|
|
273
|
+
float newZoom = currentZoom > mMinZoom ? mMinZoom : mMaxZoom;
|
|
274
|
+
float centerX = getWidth() / 2f;
|
|
275
|
+
float centerY = getHeight() / 2f;
|
|
276
|
+
|
|
277
|
+
mMatrix.setScale(newZoom, newZoom, centerX, centerY);
|
|
278
|
+
mMatrix.postTranslate(centerX - e.getX(), centerY - e.getY());
|
|
279
|
+
|
|
280
|
+
validateMatrixLimits();
|
|
281
|
+
|
|
282
|
+
ViewCompat.postInvalidateOnAnimation(PdfRendererRecyclerView.this);
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
262
285
|
}
|
|
263
286
|
|
|
264
287
|
class PdfRendererAdapter extends Adapter<PdfRendererAdapter.ViewHolder> {
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
|
|
23
23
|
package com.github.douglasjunior.reactNativePdfRenderer.modules;
|
|
24
24
|
|
|
25
|
-
import android.util.Log;
|
|
26
25
|
import android.view.ViewGroup;
|
|
27
26
|
import android.widget.LinearLayout;
|
|
28
27
|
|
|
@@ -83,7 +82,6 @@ public class PdfRendererViewManager extends SimpleViewManager<ViewGroup> {
|
|
|
83
82
|
|
|
84
83
|
@ReactProp(name = "source")
|
|
85
84
|
public void setSource(ViewGroup layout, @Nullable String source) throws IOException {
|
|
86
|
-
Log.d("PdfRendererViewManager", "setSource");
|
|
87
85
|
PdfRendererRecyclerView recyclerView = (PdfRendererRecyclerView) layout.getChildAt(0);
|
|
88
86
|
|
|
89
87
|
if (source != null) {
|
package/dist/PdfRendererView.js
CHANGED
|
@@ -43,12 +43,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
43
43
|
const react_1 = __importStar(require("react"));
|
|
44
44
|
const react_native_1 = require("react-native");
|
|
45
45
|
const PdfRendererNative = (0, react_native_1.requireNativeComponent)('RNPdfRendererView');
|
|
46
|
+
const styles = react_native_1.StyleSheet.create({
|
|
47
|
+
default: {
|
|
48
|
+
backgroundColor: 'gray',
|
|
49
|
+
flex: 1,
|
|
50
|
+
}
|
|
51
|
+
});
|
|
46
52
|
const PdfRendererView = (props) => {
|
|
47
|
-
const { onPageChange, ...others } = props;
|
|
53
|
+
const { onPageChange, style, ...others } = props;
|
|
54
|
+
const viewStyles = (0, react_1.useMemo)(() => [
|
|
55
|
+
styles.default,
|
|
56
|
+
style,
|
|
57
|
+
], [style]);
|
|
48
58
|
const handlePageChange = (0, react_1.useCallback)((event) => {
|
|
49
59
|
onPageChange?.(event.nativeEvent.position, event.nativeEvent.total);
|
|
50
60
|
}, [onPageChange]);
|
|
51
|
-
return <PdfRendererNative {...others} onPageChange={handlePageChange}/>;
|
|
61
|
+
return <PdfRendererNative {...others} style={viewStyles} onPageChange={handlePageChange}/>;
|
|
52
62
|
};
|
|
53
63
|
PdfRendererView.defaultProps = {
|
|
54
64
|
maxZoom: 5,
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-pdf-renderer",
|
|
3
3
|
"displayName": "React-Native Pdf Renderer",
|
|
4
|
-
"version": "0.0
|
|
5
|
-
"description": "⚛ A blazing fast, zero dependencies, pure native PDF Renderer for Android and iOS.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "⚛ A blazing fast, zero dependencies, pure native, typed PDF Renderer for Android and iOS.",
|
|
6
6
|
"main": "dist",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"private": false,
|