react-native-pdf-renderer 1.0.5 → 1.1.0-beta.1

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/.gitattributes CHANGED
@@ -1,2 +1,2 @@
1
1
  *.pbxproj -text
2
- Sample/** linguist-documentation
2
+ Sample/** linguist-vendored
package/README.md CHANGED
@@ -109,7 +109,7 @@ This lib is only possible thanks to the community help:
109
109
  - RecyclerView `notifyDataSetChanged()` not working on React Native: https://stackoverflow.com/a/49381907/2826279
110
110
  - Add pinch to zoom on RecyclerView: https://stackoverflow.com/a/37895783/2826279
111
111
  - Using `Matrix` to handle zoom in a View: https://stackoverflow.com/a/55299327/2826279
112
- - Daniel Felipe Sartório for the help with Android native
112
+ - **Daniel Felipe Sartório** for the help with Android native code
113
113
 
114
114
  ## Star History
115
115
 
@@ -23,6 +23,7 @@
23
23
  package com.github.douglasjunior.reactNativePdfRenderer.modules;
24
24
 
25
25
  import android.annotation.SuppressLint;
26
+ import android.content.Context;
26
27
  import android.content.res.Resources;
27
28
  import android.graphics.Bitmap;
28
29
  import android.graphics.Canvas;
@@ -67,12 +68,16 @@ public class PdfRendererRecyclerView extends RecyclerView {
67
68
 
68
69
  public PdfRendererRecyclerView(@NonNull ReactApplicationContext context, ViewGroup parent) {
69
70
  super(context);
70
- LinearLayoutManager lm = new LinearLayoutManager(context);
71
+
72
+ LayoutManager lm = new LayoutManager(context);
71
73
  lm.setOrientation(LinearLayoutManager.VERTICAL);
72
- this.setLayoutManager(lm);
74
+
73
75
  PdfRendererAdapter adapter = new PdfRendererAdapter();
76
+
77
+ this.setLayoutManager(lm);
74
78
  this.setAdapter(adapter);
75
79
  this.addOnScrollListener(new ScrollListener());
80
+
76
81
  mReactApplicationContext = context;
77
82
  mParent = parent;
78
83
  mMatrix = new Matrix();
@@ -156,11 +161,32 @@ public class PdfRendererRecyclerView extends RecyclerView {
156
161
  mMatrix.postTranslate((w - scale * mWidth) / 2f, (h - scale * mHeight) / 2f);
157
162
  }
158
163
 
164
+ private boolean isScrollingInsideZoomedArea() {
165
+ float[] values = new float[9];
166
+ mMatrix.getValues(values);
167
+
168
+ float scaleY = Math.min(Math.max(values[Matrix.MSCALE_Y], mMinZoom), mMaxZoom);
169
+ float posY = values[Matrix.MTRANS_Y];
170
+
171
+ float maxPosY = mHeight - mHeight * scaleY;
172
+
173
+ return posY < 0 && posY > maxPosY;
174
+ }
175
+
159
176
  @Override
160
177
  @SuppressLint("ClickableViewAccessibility")
161
178
  public boolean onTouchEvent(MotionEvent e) {
162
179
  mScaleDetector.onTouchEvent(e);
163
180
  mGestureDetector.onTouchEvent(e);
181
+
182
+ /*
183
+ * Disables the RecyclerView scroll when scrolling inside zoomed area
184
+ * https://github.com/douglasjunior/react-native-pdf-renderer/issues/3
185
+ */
186
+ if (isScrollingInsideZoomedArea()) {
187
+ return true;
188
+ }
189
+
164
190
  return super.onTouchEvent(e);
165
191
  }
166
192
 
@@ -381,4 +407,27 @@ public class PdfRendererRecyclerView extends RecyclerView {
381
407
  dispatchPageChangeEvent();
382
408
  }
383
409
  }
410
+
411
+ class LayoutManager extends LinearLayoutManager {
412
+ public LayoutManager(Context context) {
413
+ super(context);
414
+ }
415
+
416
+ @Override
417
+ public int scrollVerticallyBy(int dy, Recycler recycler, State state) {
418
+ /*
419
+ * Reduces the scroll speed when zoomed
420
+ * https://github.com/douglasjunior/react-native-pdf-renderer/issues/3
421
+ */
422
+
423
+ float[] values = new float[9];
424
+ mMatrix.getValues(values);
425
+
426
+ float scaleY = values[Matrix.MSCALE_Y];
427
+
428
+ int dyWithScale = Math.round(dy / scaleY);
429
+
430
+ return super.scrollVerticallyBy(dyWithScale, recycler, state);
431
+ }
432
+ }
384
433
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "react-native-pdf-renderer",
3
3
  "displayName": "React-Native Pdf Renderer",
4
- "version": "1.0.5",
4
+ "version": "1.1.0-beta.1",
5
5
  "description": "⚛ A zoomable, blazing fast, zero dependencies, pure native, typed PDF Renderer for Android and iOS.",
6
- "main": "dist",
6
+ "main": "src",
7
7
  "license": "MIT",
8
8
  "private": false,
9
9
  "repository": {
@@ -52,6 +52,5 @@
52
52
  "react-native": "0.71.4",
53
53
  "react-test-renderer": "18.2.0",
54
54
  "typescript": "4.8.4"
55
- },
56
- "types": "dist"
55
+ }
57
56
  }
@@ -0,0 +1,93 @@
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
+ import React, {useCallback, useMemo} from 'react';
24
+ import {
25
+ NativeSyntheticEvent,
26
+ requireNativeComponent,
27
+ StyleSheet,
28
+ ViewProps,
29
+ } from 'react-native';
30
+
31
+ export type PdfRendererViewPropsType = ViewProps & {
32
+ source?: string;
33
+ distanceBetweenPages: number;
34
+ maxZoom: number;
35
+ singlePage: boolean;
36
+ onPageChange?: (page: number, totalPages: number) => void;
37
+ };
38
+
39
+ type OnPageChangeEventType = {
40
+ position: number;
41
+ total: number;
42
+ };
43
+
44
+ const PdfRendererNative = requireNativeComponent('RNPdfRendererView') as any;
45
+
46
+ const styles = StyleSheet.create({
47
+ default: {
48
+ backgroundColor: 'gray',
49
+ flex: 1,
50
+ },
51
+ });
52
+
53
+ const PdfRendererView = (props: PdfRendererViewPropsType): JSX.Element => {
54
+ const {onPageChange, style, source, singlePage, maxZoom, ...others} = props;
55
+
56
+ const viewStyles = useMemo(() => [styles.default, style, {
57
+ // See https://github.com/douglasjunior/react-native-pdf-renderer#limitations
58
+ borderRadius: null,
59
+ }], [style]);
60
+
61
+ const handlePageChange = useCallback(
62
+ (event: NativeSyntheticEvent<OnPageChangeEventType>) => {
63
+ onPageChange?.(event.nativeEvent.position, event.nativeEvent.total);
64
+ },
65
+ [onPageChange],
66
+ );
67
+
68
+ const params = useMemo(
69
+ () => ({
70
+ source,
71
+ singlePage,
72
+ maxZoom,
73
+ }),
74
+ [source, singlePage, maxZoom],
75
+ );
76
+
77
+ return (
78
+ <PdfRendererNative
79
+ {...others}
80
+ style={viewStyles}
81
+ params={params}
82
+ onPageChange={handlePageChange}
83
+ />
84
+ );
85
+ };
86
+
87
+ PdfRendererView.defaultProps = {
88
+ maxZoom: 5,
89
+ distanceBetweenPages: 16,
90
+ singlePage: false,
91
+ };
92
+
93
+ export default PdfRendererView;
@@ -1,19 +1,17 @@
1
- "use strict";
2
1
  // MIT License
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.default = void 0;
2
+
8
3
  // Copyright (c) 2023 Douglas Nassif Roma Junior
4
+
9
5
  // Permission is hereby granted, free of charge, to any person obtaining a copy
10
6
  // of this software and associated documentation files (the "Software"), to deal
11
7
  // in the Software without restriction, including without limitation the rights
12
8
  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
9
  // copies of the Software, and to permit persons to whom the Software is
14
10
  // furnished to do so, subject to the following conditions:
11
+
15
12
  // The above copyright notice and this permission notice shall be included in all
16
13
  // copies or substantial portions of the Software.
14
+
17
15
  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
16
  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
17
  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -21,6 +19,6 @@ exports.default = void 0;
21
19
  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
20
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
21
  // SOFTWARE.
24
- var PdfRendererView_1 = require("./PdfRendererView");
25
- Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(PdfRendererView_1).default; } });
26
- //# sourceMappingURL=index.js.map
22
+
23
+ export {default} from './PdfRendererView';
24
+ export type {PdfRendererViewPropsType} from './PdfRendererView';
@@ -1,17 +0,0 @@
1
- import { ViewProps } from 'react-native';
2
- export declare type PdfRendererViewPropsType = ViewProps & {
3
- source?: string;
4
- distanceBetweenPages: number;
5
- maxZoom: number;
6
- singlePage: boolean;
7
- onPageChange?: (page: number, totalPages: number) => void;
8
- };
9
- declare const PdfRendererView: {
10
- (props: PdfRendererViewPropsType): JSX.Element;
11
- defaultProps: {
12
- maxZoom: number;
13
- distanceBetweenPages: number;
14
- singlePage: boolean;
15
- };
16
- };
17
- export default PdfRendererView;
@@ -1,74 +0,0 @@
1
- "use strict";
2
- // MIT License
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- // Copyright (c) 2023 Douglas Nassif Roma Junior
28
- // Permission is hereby granted, free of charge, to any person obtaining a copy
29
- // of this software and associated documentation files (the "Software"), to deal
30
- // in the Software without restriction, including without limitation the rights
31
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
32
- // copies of the Software, and to permit persons to whom the Software is
33
- // furnished to do so, subject to the following conditions:
34
- // The above copyright notice and this permission notice shall be included in all
35
- // copies or substantial portions of the Software.
36
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
39
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
41
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
42
- // SOFTWARE.
43
- const react_1 = __importStar(require("react"));
44
- const react_native_1 = require("react-native");
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
- });
52
- const PdfRendererView = (props) => {
53
- const { onPageChange, style, source, singlePage, maxZoom, ...others } = props;
54
- const viewStyles = (0, react_1.useMemo)(() => [styles.default, style, {
55
- // See https://github.com/douglasjunior/react-native-pdf-renderer#limitations
56
- borderRadius: null,
57
- }], [style]);
58
- const handlePageChange = (0, react_1.useCallback)((event) => {
59
- onPageChange?.(event.nativeEvent.position, event.nativeEvent.total);
60
- }, [onPageChange]);
61
- const params = (0, react_1.useMemo)(() => ({
62
- source,
63
- singlePage,
64
- maxZoom,
65
- }), [source, singlePage, maxZoom]);
66
- return (react_1.default.createElement(PdfRendererNative, { ...others, style: viewStyles, params: params, onPageChange: handlePageChange }));
67
- };
68
- PdfRendererView.defaultProps = {
69
- maxZoom: 5,
70
- distanceBetweenPages: 16,
71
- singlePage: false,
72
- };
73
- exports.default = PdfRendererView;
74
- //# sourceMappingURL=PdfRendererView.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PdfRendererView.js","sourceRoot":"","sources":["../src/PdfRendererView.tsx"],"names":[],"mappings":";AAAA,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;AAEd,gDAAgD;AAEhD,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAE3D,iFAAiF;AACjF,kDAAkD;AAElD,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;AAEZ,+CAAkD;AAClD,+CAKsB;AAetB,MAAM,iBAAiB,GAAG,IAAA,qCAAsB,EAAC,mBAAmB,CAAQ,CAAC;AAE7E,MAAM,MAAM,GAAG,yBAAU,CAAC,MAAM,CAAC;IAC/B,OAAO,EAAE;QACP,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,CAAC;KACR;CACF,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,CAAC,KAA+B,EAAe,EAAE;IACvE,MAAM,EAAC,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,MAAM,EAAC,GAAG,KAAK,CAAC;IAE5E,MAAM,UAAU,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE;YACvD,6EAA6E;YAC7E,YAAY,EAAE,IAAI;SACnB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEb,MAAM,gBAAgB,GAAG,IAAA,mBAAW,EAClC,CAAC,KAAkD,EAAE,EAAE;QACrD,YAAY,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACtE,CAAC,EACD,CAAC,YAAY,CAAC,CACf,CAAC;IAEF,MAAM,MAAM,GAAG,IAAA,eAAO,EACpB,GAAG,EAAE,CAAC,CAAC;QACL,MAAM;QACN,UAAU;QACV,OAAO;KACR,CAAC,EACF,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAC9B,CAAC;IAEF,OAAO,CACL,8BAAC,iBAAiB,OACZ,MAAM,EACV,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,gBAAgB,GAC9B,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,CAAC,YAAY,GAAG;IAC7B,OAAO,EAAE,CAAC;IACV,oBAAoB,EAAE,EAAE;IACxB,UAAU,EAAE,KAAK;CAClB,CAAC;AAEF,kBAAe,eAAe,CAAC"}
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export { default } from './PdfRendererView';
2
- export type { PdfRendererViewPropsType } from './PdfRendererView';
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,cAAc;;;;;;AAEd,gDAAgD;AAEhD,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAE3D,iFAAiF;AACjF,kDAAkD;AAElD,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;AAEZ,qDAA0C;AAAlC,2HAAA,OAAO,OAAA"}
@@ -1,14 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>SchemeUserState</key>
6
- <dict>
7
- <key>RNPdfRendererView.xcscheme_^#shared#^_</key>
8
- <dict>
9
- <key>orderHint</key>
10
- <integer>0</integer>
11
- </dict>
12
- </dict>
13
- </dict>
14
- </plist>