react-native-pdf-renderer 1.3.2 → 1.5.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 +7 -0
- package/dist/PdfRendererView.d.ts +11 -1
- package/dist/PdfRendererView.js +2 -2
- package/dist/PdfRendererView.js.map +1 -1
- package/package.json +1 -1
- package/android/src/main/AndroidManifest.xml +0 -4
- package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/PdfRendererPackage.java +0 -50
- package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/modules/ObservableZoom.java +0 -63
- package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererRecyclerView.java +0 -481
- package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererViewManager.java +0 -112
package/README.md
CHANGED
|
@@ -78,6 +78,7 @@ For more details, see the [Sample Project](https://github.com/douglasjunior/reac
|
|
|
78
78
|
|source|`string`||Path to a file stored on the device.|
|
|
79
79
|
|distanceBetweenPages|`number`|`16`|Distance in `DPI` between pages.|
|
|
80
80
|
|maxZoom|`number`|`5`|Max zoom scale.|
|
|
81
|
+
|maxPageResolution|`number`|`2048`|(Android only) Max page resolution (width/height) in pixels when zooming. Defined to prevent Android crash when zooming too much: https://github.com/douglasjunior/react-native-pdf-renderer/issues/26 . |
|
|
81
82
|
|singlePage|`boolean`|`false`|(Experimental) Renders only the first page without scroll. (useful for display thumbnail)|
|
|
82
83
|
|onPageChange|`(current: number, total: number) => void`||Invoked on pages scroll.|
|
|
83
84
|
|style|`StyleProp<ViewStyle>`||Styles to be applied to the native [view](https://reactnative.dev/docs/view-style-props).|
|
|
@@ -108,6 +109,12 @@ If you need `borderRadius`, the best option is to wrap the `PdfRendererView` in
|
|
|
108
109
|
</View>
|
|
109
110
|
```
|
|
110
111
|
|
|
112
|
+
### Android crash when zooming too much
|
|
113
|
+
|
|
114
|
+
To prevent Android from crashing when zooming too much, we have a `maxPageResolution` prop that limits the page resolution when zooming. (read more [#26](https://github.com/douglasjunior/react-native-pdf-renderer/issues/26))
|
|
115
|
+
|
|
116
|
+
If you are receiving the error `java.lang.RuntimeException: Canvas: trying to draw too large(134806560bytes) bitmap`, try to reduce the `maxPageResolution` prop.
|
|
117
|
+
|
|
111
118
|
## Mock with jest
|
|
112
119
|
|
|
113
120
|
```js
|
|
@@ -25,6 +25,16 @@ export type PdfRendererViewPropsType = {
|
|
|
25
25
|
* Default: 5
|
|
26
26
|
*/
|
|
27
27
|
maxZoom?: number;
|
|
28
|
+
/**
|
|
29
|
+
* (Android only)
|
|
30
|
+
*
|
|
31
|
+
* Max page resolution (width/height) in pixels when zooming.
|
|
32
|
+
*
|
|
33
|
+
* Defined to prevent Android crash when zooming too much: https://github.com/douglasjunior/react-native-pdf-renderer/issues/26
|
|
34
|
+
*
|
|
35
|
+
* Default: 2048
|
|
36
|
+
*/
|
|
37
|
+
maxPageResolution?: number;
|
|
28
38
|
/**
|
|
29
39
|
* (Experimental)
|
|
30
40
|
*
|
|
@@ -41,5 +51,5 @@ export type PdfRendererViewPropsType = {
|
|
|
41
51
|
*/
|
|
42
52
|
onPageChange?: (page: number, totalPages: number) => void;
|
|
43
53
|
};
|
|
44
|
-
declare const PdfRendererView: ({ testID, onPageChange, style, source, singlePage, distanceBetweenPages, maxZoom, }: PdfRendererViewPropsType) => JSX.Element;
|
|
54
|
+
declare const PdfRendererView: ({ testID, onPageChange, style, source, singlePage, distanceBetweenPages, maxZoom, maxPageResolution, }: PdfRendererViewPropsType) => JSX.Element;
|
|
45
55
|
export default PdfRendererView;
|
package/dist/PdfRendererView.js
CHANGED
|
@@ -24,7 +24,7 @@ const styles = StyleSheet.create({
|
|
|
24
24
|
flex: 1,
|
|
25
25
|
},
|
|
26
26
|
});
|
|
27
|
-
const PdfRendererView = ({ testID = undefined, onPageChange, style, source, singlePage = false, distanceBetweenPages = 16, maxZoom = 5, }) => {
|
|
27
|
+
const PdfRendererView = ({ testID = undefined, onPageChange, style, source, singlePage = false, distanceBetweenPages = 16, maxZoom = 5, maxPageResolution = 2048, }) => {
|
|
28
28
|
const viewStyles = useMemo(() => [
|
|
29
29
|
styles.default,
|
|
30
30
|
style,
|
|
@@ -41,7 +41,7 @@ const PdfRendererView = ({ testID = undefined, onPageChange, style, source, sing
|
|
|
41
41
|
singlePage,
|
|
42
42
|
maxZoom,
|
|
43
43
|
}), [source, singlePage, maxZoom]);
|
|
44
|
-
return (React.createElement(PdfRendererNative, { testID: testID, distanceBetweenPages: distanceBetweenPages, style: viewStyles, params: params, onPageChange: handlePageChange }));
|
|
44
|
+
return (React.createElement(PdfRendererNative, { testID: testID, maxPageResolution: maxPageResolution, distanceBetweenPages: distanceBetweenPages, style: viewStyles, params: params, onPageChange: handlePageChange }));
|
|
45
45
|
};
|
|
46
46
|
export default PdfRendererView;
|
|
47
47
|
//# sourceMappingURL=PdfRendererView.js.map
|
|
@@ -1 +1 @@
|
|
|
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,OAAO,KAAK,EAAE,EAAC,WAAW,EAAE,OAAO,EAAC,MAAM,OAAO,CAAC;AAClD,OAAO,EAEL,sBAAsB,EACtB,UAAU,GAEX,MAAM,cAAc,CAAC;
|
|
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,OAAO,KAAK,EAAE,EAAC,WAAW,EAAE,OAAO,EAAC,MAAM,OAAO,CAAC;AAClD,OAAO,EAEL,sBAAsB,EACtB,UAAU,GAEX,MAAM,cAAc,CAAC;AA4DtB,MAAM,iBAAiB,GAAG,sBAAsB,CAAC,mBAAmB,CAAQ,CAAC;AAE7E,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,OAAO,EAAE;QACP,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,CAAC;KACR;CACF,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,CAAC,EACvB,MAAM,GAAG,SAAS,EAClB,YAAY,EACZ,KAAK,EACL,MAAM,EACN,UAAU,GAAG,KAAK,EAClB,oBAAoB,GAAG,EAAE,EACzB,OAAO,GAAG,CAAC,EACX,iBAAiB,GAAG,IAAI,GACC,EAAe,EAAE;IAC1C,MAAM,UAAU,GAAG,OAAO,CACxB,GAAG,EAAE,CAAC;QACJ,MAAM,CAAC,OAAO;QACd,KAAK;QACL;YACE,6EAA6E;YAC7E,YAAY,EAAE,IAAI;SACnB;KACF,EACD,CAAC,KAAK,CAAC,CACR,CAAC;IAEF,MAAM,gBAAgB,GAAG,WAAW,CAClC,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,OAAO,CACpB,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,oBAAC,iBAAiB,IAChB,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,iBAAiB,EACpC,oBAAoB,EAAE,oBAAoB,EAC1C,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,gBAAgB,GAC9B,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
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.
|
|
4
|
+
"version": "1.5.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",
|
|
@@ -1,50 +0,0 @@
|
|
|
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;
|
|
24
|
-
|
|
25
|
-
import androidx.annotation.NonNull;
|
|
26
|
-
|
|
27
|
-
import com.facebook.react.ReactPackage;
|
|
28
|
-
import com.facebook.react.bridge.NativeModule;
|
|
29
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
30
|
-
import com.facebook.react.uimanager.ViewManager;
|
|
31
|
-
import com.github.douglasjunior.reactNativePdfRenderer.modules.PdfRendererViewManager;
|
|
32
|
-
|
|
33
|
-
import java.util.Collections;
|
|
34
|
-
import java.util.List;
|
|
35
|
-
|
|
36
|
-
public class PdfRendererPackage implements ReactPackage {
|
|
37
|
-
@NonNull
|
|
38
|
-
@Override
|
|
39
|
-
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactApplicationContext) {
|
|
40
|
-
return Collections.emptyList();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
@NonNull
|
|
44
|
-
@Override
|
|
45
|
-
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactApplicationContext) {
|
|
46
|
-
return Collections.singletonList(
|
|
47
|
-
new PdfRendererViewManager(reactApplicationContext)
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
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,481 +0,0 @@
|
|
|
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 android.annotation.SuppressLint;
|
|
26
|
-
import android.content.Context;
|
|
27
|
-
import android.content.res.Resources;
|
|
28
|
-
import android.graphics.Bitmap;
|
|
29
|
-
import android.graphics.Canvas;
|
|
30
|
-
import android.graphics.Color;
|
|
31
|
-
import android.graphics.Matrix;
|
|
32
|
-
import android.graphics.pdf.PdfRenderer;
|
|
33
|
-
import android.os.ParcelFileDescriptor;
|
|
34
|
-
import android.text.TextUtils;
|
|
35
|
-
import android.util.Log;
|
|
36
|
-
import android.util.TypedValue;
|
|
37
|
-
import android.view.GestureDetector;
|
|
38
|
-
import android.view.MotionEvent;
|
|
39
|
-
import android.view.ScaleGestureDetector;
|
|
40
|
-
import android.view.ViewGroup;
|
|
41
|
-
import android.widget.ImageView;
|
|
42
|
-
|
|
43
|
-
import androidx.annotation.NonNull;
|
|
44
|
-
import androidx.core.view.ViewCompat;
|
|
45
|
-
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
46
|
-
import androidx.recyclerview.widget.RecyclerView;
|
|
47
|
-
|
|
48
|
-
import com.facebook.react.bridge.Arguments;
|
|
49
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
50
|
-
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
51
|
-
|
|
52
|
-
import java.io.File;
|
|
53
|
-
import java.io.IOException;
|
|
54
|
-
|
|
55
|
-
@SuppressLint({"ViewConstructor", "NotifyDataSetChanged"})
|
|
56
|
-
public class PdfRendererRecyclerView extends RecyclerView {
|
|
57
|
-
private final ViewGroup mParent;
|
|
58
|
-
private final GestureDetector mGestureDetector;
|
|
59
|
-
private final int mMinZoom = 1;
|
|
60
|
-
private final ReactApplicationContext mReactApplicationContext;
|
|
61
|
-
private final ScaleGestureDetector mScaleDetector;
|
|
62
|
-
private final Matrix mMatrix;
|
|
63
|
-
private final ObservableZoom mZoomObserver;
|
|
64
|
-
private final LayoutManager mLayoutManager;
|
|
65
|
-
private boolean mRequestedLayout = false;
|
|
66
|
-
private float mMaxZoom = 5;
|
|
67
|
-
private float mDistanceBetweenPages = 0;
|
|
68
|
-
private int mWidth;
|
|
69
|
-
private int mHeight;
|
|
70
|
-
private int mCurrentItemPosition = -1;
|
|
71
|
-
private boolean mSinglePage;
|
|
72
|
-
|
|
73
|
-
public PdfRendererRecyclerView(@NonNull ReactApplicationContext context, ViewGroup parent) {
|
|
74
|
-
super(context);
|
|
75
|
-
|
|
76
|
-
mZoomObserver = new ObservableZoom(mMinZoom);
|
|
77
|
-
|
|
78
|
-
mLayoutManager = new LayoutManager(context);
|
|
79
|
-
mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
|
80
|
-
|
|
81
|
-
var adapter = new PdfRendererAdapter();
|
|
82
|
-
|
|
83
|
-
this.setLayoutManager(mLayoutManager);
|
|
84
|
-
this.setAdapter(adapter);
|
|
85
|
-
this.addOnScrollListener(new OnScrollListener() {
|
|
86
|
-
@Override
|
|
87
|
-
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
|
88
|
-
dispatchPageChangeEvent();
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
mReactApplicationContext = context;
|
|
93
|
-
mParent = parent;
|
|
94
|
-
mMatrix = new Matrix();
|
|
95
|
-
mScaleDetector = new ScaleGestureDetector(getContext(), new ScaleListener());
|
|
96
|
-
mGestureDetector = new GestureDetector(context, new GestureListener());
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
public void setDistanceBetweenPages(float distanceBetweenPages) {
|
|
100
|
-
mDistanceBetweenPages = TypedValue.applyDimension(
|
|
101
|
-
TypedValue.COMPLEX_UNIT_DIP,
|
|
102
|
-
distanceBetweenPages,
|
|
103
|
-
Resources.getSystem().getDisplayMetrics()
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
public void setMaxZoom(float maxZoom) {
|
|
108
|
-
this.mMaxZoom = maxZoom;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public void closeAdapter() {
|
|
112
|
-
try {
|
|
113
|
-
var adapter = (PdfRendererAdapter) getAdapter();
|
|
114
|
-
assert adapter != null;
|
|
115
|
-
adapter.close();
|
|
116
|
-
adapter.notifyDataSetChanged();
|
|
117
|
-
} catch (Exception ex) {
|
|
118
|
-
Log.e("PdfRendererRecyclerView", "Error closing adapter", ex);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
public void updateSource(String source) throws IOException {
|
|
123
|
-
mCurrentItemPosition = -1;
|
|
124
|
-
var adapter = (PdfRendererAdapter) getAdapter();
|
|
125
|
-
if (adapter == null) return;
|
|
126
|
-
adapter.close();
|
|
127
|
-
adapter.updateSource(source);
|
|
128
|
-
adapter.notifyDataSetChanged();
|
|
129
|
-
post(this::dispatchPageChangeEvent);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
private void dispatchPageChangeEvent() {
|
|
133
|
-
var newPosition = mLayoutManager.findLastCompletelyVisibleItemPosition();
|
|
134
|
-
if (newPosition < 0) newPosition = mLayoutManager.findLastVisibleItemPosition();
|
|
135
|
-
|
|
136
|
-
if (newPosition != mCurrentItemPosition) {
|
|
137
|
-
mCurrentItemPosition = newPosition;
|
|
138
|
-
|
|
139
|
-
var adapter = (PdfRendererAdapter) getAdapter();
|
|
140
|
-
if (adapter == null) return;
|
|
141
|
-
|
|
142
|
-
var event = Arguments.createMap();
|
|
143
|
-
event.putInt("position", newPosition);
|
|
144
|
-
event.putInt("total", adapter.getPageCount());
|
|
145
|
-
|
|
146
|
-
mReactApplicationContext
|
|
147
|
-
.getJSModule(RCTEventEmitter.class)
|
|
148
|
-
.receiveEvent(mParent.getId(), "pageChange", event);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
@Override
|
|
153
|
-
protected void dispatchDraw(@NonNull Canvas canvas) {
|
|
154
|
-
canvas.save();
|
|
155
|
-
canvas.concat(mMatrix);
|
|
156
|
-
super.dispatchDraw(canvas);
|
|
157
|
-
canvas.restore();
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
@Override
|
|
161
|
-
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
162
|
-
mWidth = MeasureSpec.getSize(widthMeasureSpec);
|
|
163
|
-
mHeight = MeasureSpec.getSize(heightMeasureSpec);
|
|
164
|
-
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
@Override
|
|
168
|
-
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
|
169
|
-
super.onSizeChanged(w, h, oldw, oldh);
|
|
170
|
-
var scale = mWidth > 0 && mHeight > 0
|
|
171
|
-
? Math.max(w / mWidth, h / mHeight)
|
|
172
|
-
: 1;
|
|
173
|
-
mMatrix.setScale(scale, scale);
|
|
174
|
-
mMatrix.postTranslate((w - scale * mWidth) / 2f, (h - scale * mHeight) / 2f);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
private boolean isScrollingInsideZoomedArea() {
|
|
178
|
-
var values = new float[9];
|
|
179
|
-
mMatrix.getValues(values);
|
|
180
|
-
|
|
181
|
-
var scaleY = Math.min(Math.max(values[Matrix.MSCALE_Y], mMinZoom), mMaxZoom);
|
|
182
|
-
var posY = values[Matrix.MTRANS_Y];
|
|
183
|
-
|
|
184
|
-
var maxPosY = mHeight - mHeight * scaleY;
|
|
185
|
-
|
|
186
|
-
return posY < 0 && posY > maxPosY;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
@Override
|
|
190
|
-
@SuppressLint("ClickableViewAccessibility")
|
|
191
|
-
public boolean onTouchEvent(MotionEvent e) {
|
|
192
|
-
mScaleDetector.onTouchEvent(e);
|
|
193
|
-
mGestureDetector.onTouchEvent(e);
|
|
194
|
-
|
|
195
|
-
/*
|
|
196
|
-
* Disables the RecyclerView scroll when scrolling inside zoomed area
|
|
197
|
-
* https://github.com/douglasjunior/react-native-pdf-renderer/issues/3
|
|
198
|
-
*/
|
|
199
|
-
if (isScrollingInsideZoomedArea()) {
|
|
200
|
-
return true;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return super.onTouchEvent(e);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
@Override
|
|
207
|
-
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
208
|
-
try {
|
|
209
|
-
return super.onInterceptTouchEvent(ev);
|
|
210
|
-
} catch (IllegalArgumentException ex) {
|
|
211
|
-
Log.e("PdfRendererRecyclerView", "Error intercepting touch event", ex);
|
|
212
|
-
}
|
|
213
|
-
return false;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
public void forceRequestLayout() {
|
|
217
|
-
mRequestedLayout = false;
|
|
218
|
-
requestLayout();
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
private void validateMatrixLimits() {
|
|
222
|
-
var values = new float[9];
|
|
223
|
-
mMatrix.getValues(values);
|
|
224
|
-
|
|
225
|
-
var scaleX = Math.min(Math.max(values[Matrix.MSCALE_X], mMinZoom), mMaxZoom);
|
|
226
|
-
var posX = values[Matrix.MTRANS_X];
|
|
227
|
-
|
|
228
|
-
var scaleY = Math.min(Math.max(values[Matrix.MSCALE_Y], mMinZoom), mMaxZoom);
|
|
229
|
-
var posY = values[Matrix.MTRANS_Y];
|
|
230
|
-
|
|
231
|
-
var maxPosX = mWidth - mWidth * scaleX;
|
|
232
|
-
var maxPosY = mHeight - mHeight * scaleY;
|
|
233
|
-
|
|
234
|
-
if (posX > 0.0f)
|
|
235
|
-
posX = 0.0f;
|
|
236
|
-
else if (posX < maxPosX)
|
|
237
|
-
posX = maxPosX;
|
|
238
|
-
|
|
239
|
-
if (posY > 0.0f)
|
|
240
|
-
posY = 0.0f;
|
|
241
|
-
else if (posY < maxPosY)
|
|
242
|
-
posY = maxPosY;
|
|
243
|
-
|
|
244
|
-
values[Matrix.MSCALE_X] = scaleX;
|
|
245
|
-
values[Matrix.MTRANS_X] = posX;
|
|
246
|
-
values[Matrix.MSCALE_Y] = scaleY;
|
|
247
|
-
values[Matrix.MTRANS_Y] = posY;
|
|
248
|
-
|
|
249
|
-
mMatrix.setValues(values);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Fix a problem with React Native layout
|
|
254
|
-
* https://stackoverflow.com/a/49381907/2826279
|
|
255
|
-
*/
|
|
256
|
-
@SuppressLint("WrongCall")
|
|
257
|
-
@Override
|
|
258
|
-
public void requestLayout() {
|
|
259
|
-
super.requestLayout();
|
|
260
|
-
if (!mRequestedLayout) {
|
|
261
|
-
mRequestedLayout = true;
|
|
262
|
-
this.post(() -> {
|
|
263
|
-
onLayout(false, getLeft(), getTop(), getRight(), getBottom());
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
public void setSinglePage(boolean singlePage) {
|
|
269
|
-
this.mSinglePage = singlePage;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
|
|
273
|
-
@Override
|
|
274
|
-
public boolean onScale(ScaleGestureDetector detector) {
|
|
275
|
-
var values = new float[9];
|
|
276
|
-
mMatrix.getValues(values);
|
|
277
|
-
|
|
278
|
-
var zoom = values[Matrix.MSCALE_X];
|
|
279
|
-
var factor = detector.getScaleFactor();
|
|
280
|
-
|
|
281
|
-
if (zoom >= mMaxZoom && factor > 1) {
|
|
282
|
-
return false;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
mMatrix.postScale(factor, factor, getWidth() / 2f, getHeight() / 2f);
|
|
286
|
-
validateMatrixLimits();
|
|
287
|
-
ViewCompat.postInvalidateOnAnimation(PdfRendererRecyclerView.this);
|
|
288
|
-
|
|
289
|
-
return true;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
@Override
|
|
293
|
-
public void onScaleEnd(@NonNull ScaleGestureDetector detector) {
|
|
294
|
-
super.onScaleEnd(detector);
|
|
295
|
-
|
|
296
|
-
var values = new float[9];
|
|
297
|
-
mMatrix.getValues(values);
|
|
298
|
-
var zoom = values[Matrix.MSCALE_X];
|
|
299
|
-
|
|
300
|
-
mZoomObserver.setZoom(zoom);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
private class GestureListener extends GestureDetector.SimpleOnGestureListener {
|
|
305
|
-
@Override
|
|
306
|
-
public boolean onScroll(MotionEvent e1, MotionEvent e2, float dX, float dY) {
|
|
307
|
-
mMatrix.postTranslate(-dX, -dY);
|
|
308
|
-
validateMatrixLimits();
|
|
309
|
-
ViewCompat.postInvalidateOnAnimation(PdfRendererRecyclerView.this);
|
|
310
|
-
return true;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
@Override
|
|
314
|
-
public boolean onDoubleTap(@NonNull MotionEvent e) {
|
|
315
|
-
if (e.getPointerCount() > 1) {
|
|
316
|
-
return false;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
var values = new float[9];
|
|
320
|
-
mMatrix.getValues(values);
|
|
321
|
-
|
|
322
|
-
var currentZoom = values[Matrix.MSCALE_X];
|
|
323
|
-
var newZoom = currentZoom > mMinZoom ? mMinZoom : mMaxZoom;
|
|
324
|
-
var centerX = getWidth() / 2f;
|
|
325
|
-
var centerY = getHeight() / 2f;
|
|
326
|
-
|
|
327
|
-
mMatrix.setScale(newZoom, newZoom, centerX, centerY);
|
|
328
|
-
mMatrix.postTranslate(centerX - e.getX(), centerY - e.getY());
|
|
329
|
-
|
|
330
|
-
validateMatrixLimits();
|
|
331
|
-
|
|
332
|
-
ViewCompat.postInvalidateOnAnimation(PdfRendererRecyclerView.this);
|
|
333
|
-
|
|
334
|
-
mZoomObserver.setZoom(newZoom);
|
|
335
|
-
return true;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
class PdfRendererAdapter extends Adapter<PdfRendererAdapter.ViewHolder> {
|
|
340
|
-
|
|
341
|
-
private ParcelFileDescriptor mFileDescriptor;
|
|
342
|
-
private PdfRenderer mPdfRenderer;
|
|
343
|
-
|
|
344
|
-
public void updateSource(String source) throws IOException {
|
|
345
|
-
if (TextUtils.isEmpty(source)) return;
|
|
346
|
-
var file = new File(source.replace("file://", ""));
|
|
347
|
-
mFileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
|
|
348
|
-
mPdfRenderer = new PdfRenderer(mFileDescriptor);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
public void close() throws IOException {
|
|
352
|
-
if (mPdfRenderer != null) mPdfRenderer.close();
|
|
353
|
-
if (mFileDescriptor != null) mFileDescriptor.close();
|
|
354
|
-
mPdfRenderer = null;
|
|
355
|
-
mFileDescriptor = null;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
@NonNull
|
|
359
|
-
@Override
|
|
360
|
-
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
361
|
-
var imageView = new ImageView(parent.getContext());
|
|
362
|
-
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
|
363
|
-
imageView.setBackgroundColor(Color.WHITE);
|
|
364
|
-
var params = new LayoutParams(LayoutParams.MATCH_PARENT, 0);
|
|
365
|
-
imageView.setLayoutParams(params);
|
|
366
|
-
return new ViewHolder(imageView);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
@Override
|
|
370
|
-
public void onViewDetachedFromWindow(@NonNull ViewHolder holder) {
|
|
371
|
-
super.onViewDetachedFromWindow(holder);
|
|
372
|
-
holder.detachFromWindow();
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
@Override
|
|
376
|
-
public void onViewAttachedToWindow(@NonNull ViewHolder holder) {
|
|
377
|
-
super.onViewAttachedToWindow(holder);
|
|
378
|
-
holder.attachFromWindow();
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
@Override
|
|
382
|
-
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
|
383
|
-
if (mPdfRenderer == null) return;
|
|
384
|
-
holder.update(position, mZoomObserver.getZoom());
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
@Override
|
|
388
|
-
public int getItemCount() {
|
|
389
|
-
if (mPdfRenderer == null) return 0;
|
|
390
|
-
if (mSinglePage) {
|
|
391
|
-
return Math.min(mPdfRenderer.getPageCount(), 1);
|
|
392
|
-
}
|
|
393
|
-
return mPdfRenderer.getPageCount();
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
public int getPageCount() {
|
|
397
|
-
if (mPdfRenderer == null) return 0;
|
|
398
|
-
return mPdfRenderer.getPageCount();
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
public class ViewHolder extends RecyclerView.ViewHolder {
|
|
402
|
-
private ObservableZoom.ZoomChangeListener zoomListener;
|
|
403
|
-
|
|
404
|
-
public ViewHolder(ImageView imageView) {
|
|
405
|
-
super(imageView);
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
public ImageView getImageView() {
|
|
409
|
-
return (ImageView) this.itemView;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
public void update(int position, float newZoom) {
|
|
413
|
-
var page = mPdfRenderer.openPage(position);
|
|
414
|
-
var bitmap = Bitmap.createBitmap(
|
|
415
|
-
Math.round(page.getWidth() * newZoom),
|
|
416
|
-
Math.round(page.getHeight() * newZoom),
|
|
417
|
-
Bitmap.Config.ARGB_4444
|
|
418
|
-
);
|
|
419
|
-
page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
|
|
420
|
-
|
|
421
|
-
var imageView = getImageView();
|
|
422
|
-
imageView.setImageBitmap(bitmap);
|
|
423
|
-
|
|
424
|
-
var lp = (LayoutParams) imageView.getLayoutParams();
|
|
425
|
-
lp.width = LayoutParams.MATCH_PARENT;
|
|
426
|
-
|
|
427
|
-
if (mSinglePage) {
|
|
428
|
-
lp.height = LayoutParams.MATCH_PARENT;
|
|
429
|
-
lp.setMargins(0, 0, 0, 0);
|
|
430
|
-
} else {
|
|
431
|
-
lp.height = Math.round(((float) mWidth / (float) page.getWidth()) * (float) page.getHeight());
|
|
432
|
-
lp.setMargins(0, 0, 0, (int) mDistanceBetweenPages);
|
|
433
|
-
}
|
|
434
|
-
imageView.setLayoutParams(lp);
|
|
435
|
-
|
|
436
|
-
page.close();
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
public void detachFromWindow() {
|
|
440
|
-
if (zoomListener != null) {
|
|
441
|
-
mZoomObserver.removeListener(zoomListener);
|
|
442
|
-
zoomListener = null;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
public void attachFromWindow() {
|
|
447
|
-
detachFromWindow();
|
|
448
|
-
zoomListener = newZoom -> {
|
|
449
|
-
var position = getLayoutPosition();
|
|
450
|
-
if (position == NO_POSITION) return;
|
|
451
|
-
if (position < mLayoutManager.findFirstVisibleItemPosition()
|
|
452
|
-
|| position > mLayoutManager.findLastVisibleItemPosition()) return;
|
|
453
|
-
update(position, newZoom);
|
|
454
|
-
};
|
|
455
|
-
mZoomObserver.addListener(zoomListener);
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
class LayoutManager extends LinearLayoutManager {
|
|
461
|
-
public LayoutManager(Context context) {
|
|
462
|
-
super(context);
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
@Override
|
|
466
|
-
public int scrollVerticallyBy(int dy, Recycler recycler, State state) {
|
|
467
|
-
/*
|
|
468
|
-
* Reduces the scroll speed when zoomed
|
|
469
|
-
* https://github.com/douglasjunior/react-native-pdf-renderer/issues/3
|
|
470
|
-
*/
|
|
471
|
-
|
|
472
|
-
var values = new float[9];
|
|
473
|
-
mMatrix.getValues(values);
|
|
474
|
-
|
|
475
|
-
var scaleY = values[Matrix.MSCALE_Y];
|
|
476
|
-
var dyWithScale = Math.round(dy / scaleY);
|
|
477
|
-
|
|
478
|
-
return super.scrollVerticallyBy(dyWithScale, recycler, state);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
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 android.view.View;
|
|
26
|
-
import android.view.ViewGroup;
|
|
27
|
-
import android.widget.LinearLayout;
|
|
28
|
-
|
|
29
|
-
import androidx.annotation.NonNull;
|
|
30
|
-
import androidx.annotation.Nullable;
|
|
31
|
-
|
|
32
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
33
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
34
|
-
import com.facebook.react.common.MapBuilder;
|
|
35
|
-
import com.facebook.react.uimanager.SimpleViewManager;
|
|
36
|
-
import com.facebook.react.uimanager.ThemedReactContext;
|
|
37
|
-
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
38
|
-
|
|
39
|
-
import java.io.IOException;
|
|
40
|
-
import java.util.Map;
|
|
41
|
-
|
|
42
|
-
public class PdfRendererViewManager extends SimpleViewManager<ViewGroup> {
|
|
43
|
-
private final ReactApplicationContext mReactApplicationContext;
|
|
44
|
-
|
|
45
|
-
public PdfRendererViewManager(ReactApplicationContext reactApplicationContext) {
|
|
46
|
-
this.mReactApplicationContext = reactApplicationContext;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@NonNull
|
|
50
|
-
@Override
|
|
51
|
-
public String getName() {
|
|
52
|
-
return "RNPdfRendererView";
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
@NonNull
|
|
56
|
-
@Override
|
|
57
|
-
protected ViewGroup createViewInstance(@NonNull ThemedReactContext themedReactContext) {
|
|
58
|
-
var layout = new LinearLayout(themedReactContext);
|
|
59
|
-
layout.setOrientation(LinearLayout.VERTICAL);
|
|
60
|
-
|
|
61
|
-
var params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
62
|
-
|
|
63
|
-
var recyclerView = new PdfRendererRecyclerView(mReactApplicationContext, layout);
|
|
64
|
-
recyclerView.setLayoutParams(params);
|
|
65
|
-
|
|
66
|
-
layout.addView(recyclerView);
|
|
67
|
-
layout.setClipToOutline(true);
|
|
68
|
-
|
|
69
|
-
return layout;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
@Nullable
|
|
73
|
-
@Override
|
|
74
|
-
public Map<String, Object> getExportedCustomBubblingEventTypeConstants() {
|
|
75
|
-
var map = super.getExportedCustomBubblingEventTypeConstants();
|
|
76
|
-
if (map == null) map = MapBuilder.of();
|
|
77
|
-
map.put("pageChange", MapBuilder.of(
|
|
78
|
-
"phasedRegistrationNames",
|
|
79
|
-
MapBuilder.of("bubbled", "onPageChange")
|
|
80
|
-
));
|
|
81
|
-
return map;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
@ReactProp(name = "params")
|
|
85
|
-
public void setParams(ViewGroup layout, @Nullable ReadableMap params) throws IOException {
|
|
86
|
-
if (params == null) return;
|
|
87
|
-
|
|
88
|
-
var recyclerView = (PdfRendererRecyclerView) layout.getChildAt(0);
|
|
89
|
-
|
|
90
|
-
var source = params.getString("source");
|
|
91
|
-
var singlePage = params.hasKey("singlePage") && params.getBoolean("singlePage");
|
|
92
|
-
var maxZoom = params.hasKey("maxZoom") ? Double.valueOf(params.getDouble("maxZoom")).floatValue() : 5;
|
|
93
|
-
|
|
94
|
-
if (source != null) {
|
|
95
|
-
recyclerView.updateSource(source);
|
|
96
|
-
} else {
|
|
97
|
-
recyclerView.closeAdapter();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
recyclerView.setSinglePage(singlePage);
|
|
101
|
-
recyclerView.setMaxZoom(maxZoom);
|
|
102
|
-
recyclerView.setOverScrollMode(singlePage ? View.OVER_SCROLL_NEVER : View.OVER_SCROLL_IF_CONTENT_SCROLLS);
|
|
103
|
-
|
|
104
|
-
recyclerView.forceRequestLayout();
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
@ReactProp(name = "distanceBetweenPages")
|
|
108
|
-
public void setDistanceBetweenPages(ViewGroup layout, @Nullable float distanceBetweenPages) {
|
|
109
|
-
var recyclerView = (PdfRendererRecyclerView) layout.getChildAt(0);
|
|
110
|
-
recyclerView.setDistanceBetweenPages(distanceBetweenPages);
|
|
111
|
-
}
|
|
112
|
-
}
|