react-native-pdf-renderer 1.5.1 → 2.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.
Files changed (33) hide show
  1. package/README.md +32 -17
  2. package/ReactNativePdfRenderer.podspec +9 -2
  3. package/android/build.gradle +121 -39
  4. package/android/gradle/wrapper/gradle-wrapper.properties +3 -1
  5. package/android/src/main/AndroidManifest.xml +1 -2
  6. package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/PdfRendererPackage.java +32 -9
  7. package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/PdfRendererViewManagerImpl.java +94 -0
  8. package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/modules/ObservableZoom.java +63 -63
  9. package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererRecyclerView.java +30 -33
  10. package/android/src/newarch/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererViewManager.java +102 -0
  11. package/android/src/oldarch/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererViewManager.java +92 -0
  12. package/dist/PdfRendererView.d.ts +4 -4
  13. package/dist/PdfRendererView.js +3 -3
  14. package/dist/PdfRendererView.js.map +1 -1
  15. package/dist/index.js.map +1 -1
  16. package/dist/mock.js +17 -0
  17. package/dist/mock.js.map +1 -1
  18. package/dist/specs/RNPdfRendererViewNativeComponent.d.ts +19 -0
  19. package/dist/specs/RNPdfRendererViewNativeComponent.js +4 -0
  20. package/dist/specs/RNPdfRendererViewNativeComponent.js.map +1 -0
  21. package/ios/ReactNativePdfRenderer.xcodeproj/project.pbxproj +10 -4
  22. package/ios/ReactNativePdfRendererLibrary/RNPDFView.h +9 -3
  23. package/ios/ReactNativePdfRendererLibrary/{RNPDFView.m → RNPDFView.mm} +9 -10
  24. package/ios/ReactNativePdfRendererLibrary/RNPdfRendererComponentView.h +44 -0
  25. package/ios/ReactNativePdfRendererLibrary/RNPdfRendererComponentView.mm +134 -0
  26. package/ios/ReactNativePdfRendererLibrary/RNPdfRendererModule.h +7 -0
  27. package/ios/ReactNativePdfRendererLibrary/RNPdfRendererModule.m +13 -0
  28. package/package.json +35 -16
  29. package/src/PdfRendererView.tsx +147 -0
  30. package/src/index.ts +24 -0
  31. package/src/mock.tsx +32 -0
  32. package/src/specs/RNPdfRendererViewNativeComponent.ts +51 -0
  33. package/android/src/main/java/com/github/douglasjunior/reactNativePdfRenderer/modules/PdfRendererViewManager.java +0 -118
@@ -0,0 +1,134 @@
1
+ // MIT License
2
+ //
3
+ // Copyright (c) 2025 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
+ // Created by Douglas Nassif Roma Junior on 08/03/23.
24
+ //
25
+
26
+ #ifdef RCT_NEW_ARCH_ENABLED
27
+
28
+ #import "RNPdfRendererComponentView.h"
29
+
30
+ #import <react/renderer/components/rnpdfrenderer_codegen/ComponentDescriptors.h>
31
+ #import <react/renderer/components/rnpdfrenderer_codegen/EventEmitters.h>
32
+ #import <react/renderer/components/rnpdfrenderer_codegen/Props.h>
33
+ #import <react/renderer/components/rnpdfrenderer_codegen/RCTComponentViewHelpers.h>
34
+
35
+ using namespace facebook::react;
36
+
37
+ @interface RNPdfRendererComponentView () <RCTRNPdfRendererViewViewProtocol>
38
+ @end
39
+
40
+ @implementation RNPdfRendererComponentView {
41
+ RNPDFView * _pdfView;
42
+ }
43
+
44
+ BOOL observerAdded = NO;
45
+
46
+ -(instancetype)init
47
+ {
48
+ if (!observerAdded) {
49
+ observerAdded = YES;
50
+ [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(handlePageChange:) name:PDFViewPageChangedNotification object:nil];
51
+ }
52
+ if(self = [super init]) {
53
+ _pdfView = [RNPDFView new];
54
+ _pdfView.backgroundColor = UIColor.clearColor;
55
+ [self addSubview:_pdfView];
56
+ }
57
+ return self;
58
+ }
59
+
60
+ - (void)dealloc
61
+ {
62
+ if (observerAdded) {
63
+ observerAdded = NO;
64
+ [NSNotificationCenter.defaultCenter removeObserver:self name:PDFViewPageChangedNotification object:nil];
65
+ }
66
+ }
67
+
68
+ - (void)handlePageChange:(NSNotification*) notification {
69
+ if ([RNPDFView class] != [notification.object class]) {
70
+ return;
71
+ }
72
+
73
+ RNPDFView *view = notification.object;
74
+
75
+ NSUInteger currentPageNumber = [view.document indexForPage:view.currentPage];
76
+
77
+ RNPdfRendererViewEventEmitter::OnPageChange result = RNPdfRendererViewEventEmitter::OnPageChange{};
78
+ result.position = currentPageNumber;
79
+ result.total = view.document.pageCount;
80
+
81
+ if (_eventEmitter) {
82
+ self.eventEmitter.onPageChange(result);
83
+ }
84
+ }
85
+
86
+ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
87
+ {
88
+ const auto &oldViewProps = *std::static_pointer_cast<RNPdfRendererViewProps const>(_props);
89
+ const auto &newViewProps = *std::static_pointer_cast<RNPdfRendererViewProps const>(props);
90
+
91
+ if (oldViewProps.params.source != newViewProps.params.source ||
92
+ oldViewProps.params.maxZoom != newViewProps.params.maxZoom ||
93
+ oldViewProps.params.singlePage != newViewProps.params.singlePage) {
94
+
95
+ NSString *sourceString = [NSString stringWithUTF8String:newViewProps.params.source.c_str()];
96
+
97
+ NSDictionary* params = @{
98
+ @"source": sourceString,
99
+ @"maxZoom": @(newViewProps.params.maxZoom),
100
+ @"singlePage": @(newViewProps.params.singlePage)
101
+ };
102
+
103
+ [_pdfView setParams: params];
104
+
105
+ [self setNeedsLayout];
106
+ }
107
+
108
+ if (oldViewProps.distanceBetweenPages != newViewProps.distanceBetweenPages) {
109
+ [_pdfView setDistanceBetweenPages: @(newViewProps.distanceBetweenPages)];
110
+ }
111
+
112
+ [super updateProps:props oldProps:oldProps];
113
+ }
114
+
115
+ -(void)layoutSubviews
116
+ {
117
+ [super layoutSubviews];
118
+ _pdfView.frame = self.bounds;
119
+ }
120
+
121
+ // Event emitter convenience method
122
+ - (const RNPdfRendererViewEventEmitter &)eventEmitter
123
+ {
124
+ return static_cast<const RNPdfRendererViewEventEmitter &>(*_eventEmitter);
125
+ }
126
+
127
+ + (ComponentDescriptorProvider)componentDescriptorProvider
128
+ {
129
+ return concreteComponentDescriptorProvider<RNPdfRendererViewComponentDescriptor>();
130
+ }
131
+
132
+ @end
133
+
134
+ #endif // RCT_NEW_ARCH_ENABLED
@@ -23,12 +23,19 @@
23
23
  // Created by Douglas Nassif Roma Junior on 08/03/23.
24
24
  //
25
25
 
26
+ #ifdef RCT_NEW_ARCH_ENABLED
27
+ #else
28
+
26
29
  @import Foundation;
27
30
  @import UIKit;
28
31
  @import PDFKit;
29
32
 
30
33
  #import <React/RCTViewManager.h>
34
+ #import <PDFKit/PDFKit.h>
35
+
31
36
  #import "RNPDFView.h"
32
37
 
33
38
  @interface RNPdfRendererModule : RCTViewManager
34
39
  @end
40
+
41
+ #endif // RCT_NEW_ARCH_ENABLED
@@ -23,6 +23,9 @@
23
23
  // Created by Douglas Nassif Roma Junior on 08/03/23.
24
24
  //
25
25
 
26
+ #ifdef RCT_NEW_ARCH_ENABLED
27
+ #else
28
+
26
29
  #import "RNPdfRendererModule.h"
27
30
 
28
31
  @implementation RNPdfRendererModule
@@ -43,6 +46,14 @@ BOOL observerAdded = NO;
43
46
  return view;
44
47
  }
45
48
 
49
+ - (void)dealloc
50
+ {
51
+ if (observerAdded) {
52
+ observerAdded = NO;
53
+ [NSNotificationCenter.defaultCenter removeObserver:self name:PDFViewPageChangedNotification object:nil];
54
+ }
55
+ }
56
+
46
57
  - (void)handlePageChange:(NSNotification*) notification {
47
58
  if ([RNPDFView class] != [notification.object class]) {
48
59
  return;
@@ -73,3 +84,5 @@ RCT_CUSTOM_VIEW_PROPERTY(distanceBetweenPages, NSNumber, RNPDFView)
73
84
  }
74
85
 
75
86
  @end
87
+
88
+ #endif // RCT_NEW_ARCH_ENABLED
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": "2.0.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",
@@ -26,31 +26,50 @@
26
26
  "url": "https://github.com/douglasjunior/react-native-pdf-renderer/issues"
27
27
  },
28
28
  "homepage": "https://github.com/douglasjunior/react-native-pdf-renderer",
29
+ "codegenConfig": {
30
+ "name": "rnpdfrenderer_codegen",
31
+ "type": "components",
32
+ "jsSrcsDir": "./src/specs",
33
+ "android": {
34
+ "javaPackageName": "com.github.douglasjunior.reactNativePdfRenderer"
35
+ },
36
+ "ios": {
37
+ "componentProvider": {
38
+ "RNPdfRendererView": "RNPdfRendererComponentView"
39
+ }
40
+ }
41
+ },
29
42
  "scripts": {
30
43
  "build": "tsc",
31
44
  "publish-script": "node scripts/publish.js"
32
45
  },
33
46
  "peerDependencies": {
34
- "react-native": ">=0.60"
47
+ "react-native": ">=0.71"
35
48
  },
36
49
  "devDependencies": {
37
- "react": "18.2.0",
38
- "react-native": "0.74.1",
39
- "@babel/core": "^7.20.0",
40
- "@babel/preset-env": "^7.20.0",
41
- "@babel/runtime": "^7.20.0",
42
- "@react-native/babel-preset": "0.74.83",
43
- "@react-native/eslint-config": "0.74.83",
44
- "@react-native/metro-config": "0.74.83",
45
- "@react-native/typescript-config": "0.74.83",
46
- "@types/react": "^18.2.6",
47
- "@types/react-test-renderer": "^18.0.0",
48
- "babel-jest": "^29.6.3",
50
+ "react": "19.0.0",
51
+ "react-native": "0.79.4",
52
+ "@babel/core": "^7.25.2",
53
+ "@babel/preset-env": "^7.25.3",
54
+ "@babel/runtime": "^7.25.0",
55
+ "@react-native-community/cli": "18.0.0",
56
+ "@react-native-community/cli-platform-android": "18.0.0",
57
+ "@react-native-community/cli-platform-ios": "18.0.0",
58
+ "@react-native/babel-preset": "0.79.4",
59
+ "@react-native/eslint-config": "0.79.4",
60
+ "@react-native/metro-config": "0.79.4",
61
+ "@react-native/typescript-config": "0.79.4",
62
+ "@types/jest": "^29.5.13",
63
+ "@types/react": "^19.0.0",
64
+ "@types/react-test-renderer": "^19.0.0",
49
65
  "eslint": "^8.19.0",
50
66
  "jest": "^29.6.3",
51
67
  "prettier": "2.8.8",
52
- "react-test-renderer": "18.2.0",
53
- "typescript": "5.0.4"
68
+ "react-test-renderer": "19.0.0",
69
+ "typescript": "~5.8.3"
70
+ },
71
+ "engines": {
72
+ "node": ">=18"
54
73
  },
55
74
  "types": "dist"
56
75
  }
@@ -0,0 +1,147 @@
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
+ StyleProp,
27
+ StyleSheet,
28
+ ViewStyle,
29
+ } from 'react-native';
30
+
31
+ import PdfRendererNative, { NativeParams } from './specs/RNPdfRendererViewNativeComponent';
32
+
33
+ export type PdfRendererViewPropsType = {
34
+ testID?: string;
35
+ /**
36
+ * Styles to be applied to the View.
37
+ *
38
+ * Note: Border radius is not supported.
39
+ */
40
+ style?: StyleProp<ViewStyle>;
41
+ /**
42
+ * Path to a file stored on device.
43
+ *
44
+ * Ex.: `file:///path/to/file.pdf`
45
+ */
46
+ source?: string;
47
+ /**
48
+ * Distance in `DPI` between pages.
49
+ *
50
+ * Default: 16
51
+ */
52
+ distanceBetweenPages?: number;
53
+ /**
54
+ * Max zoom scale.
55
+ *
56
+ * Default: 5
57
+ */
58
+ maxZoom?: number;
59
+ /**
60
+ * (Android only)
61
+ *
62
+ * Max page resolution (width/height) in pixels when zooming.
63
+ *
64
+ * Defined to prevent Android crash when zooming too much: https://github.com/douglasjunior/react-native-pdf-renderer/issues/26
65
+ *
66
+ * Default: 2048
67
+ */
68
+ maxPageResolution?: number;
69
+ /**
70
+ *
71
+ * Renders only the first page without scroll. (useful for display thumbnail).
72
+ *
73
+ * Default: false
74
+ */
75
+ singlePage?: boolean;
76
+ /**
77
+ * Invoked on pages scroll.
78
+ *
79
+ * @param page current page number
80
+ * @param totalPages total pages number
81
+ */
82
+ onPageChange?: (page: number, totalPages: number) => void;
83
+ };
84
+
85
+ type OnPageChangeEventType = {
86
+ position: number;
87
+ total: number;
88
+ };
89
+
90
+ const styles = StyleSheet.create({
91
+ default: {
92
+ backgroundColor: 'gray',
93
+ flex: 1,
94
+ },
95
+ });
96
+
97
+ const PdfRendererView = ({
98
+ testID = undefined,
99
+ onPageChange,
100
+ style,
101
+ source,
102
+ singlePage = false,
103
+ distanceBetweenPages = 16,
104
+ maxZoom = 5,
105
+ maxPageResolution = 2048,
106
+ }: PdfRendererViewPropsType): React.JSX.Element => {
107
+ const viewStyles: StyleProp<ViewStyle> = useMemo(
108
+ () => [
109
+ styles.default,
110
+ style,
111
+ {
112
+ // See https://github.com/douglasjunior/react-native-pdf-renderer#limitations
113
+ borderRadius: undefined,
114
+ },
115
+ ],
116
+ [style],
117
+ );
118
+
119
+ const handlePageChange = useCallback(
120
+ (event: NativeSyntheticEvent<OnPageChangeEventType>) => {
121
+ onPageChange?.(event.nativeEvent.position, event.nativeEvent.total);
122
+ },
123
+ [onPageChange],
124
+ );
125
+
126
+ const params: NativeParams = useMemo(
127
+ () => ({
128
+ source,
129
+ singlePage,
130
+ maxZoom,
131
+ }),
132
+ [source, singlePage, maxZoom],
133
+ );
134
+
135
+ return (
136
+ <PdfRendererNative
137
+ testID={testID}
138
+ maxPageResolution={maxPageResolution}
139
+ distanceBetweenPages={distanceBetweenPages}
140
+ style={viewStyles}
141
+ params={params}
142
+ onPageChange={handlePageChange}
143
+ />
144
+ );
145
+ };
146
+
147
+ export default PdfRendererView;
package/src/index.ts ADDED
@@ -0,0 +1,24 @@
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
+ export { default } from './PdfRendererView';
24
+ export type { PdfRendererViewPropsType } from './PdfRendererView';
package/src/mock.tsx ADDED
@@ -0,0 +1,32 @@
1
+ // MIT License
2
+
3
+ // Copyright (c) 2024 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 from 'react';
24
+
25
+ import { View } from 'react-native';
26
+ import { PdfRendererViewPropsType } from './PdfRendererView';
27
+
28
+ const PdfRendererViewMock = (props: PdfRendererViewPropsType) => {
29
+ return <View testID={props.testID} style={props.style} />;
30
+ };
31
+
32
+ export default PdfRendererViewMock;
@@ -0,0 +1,51 @@
1
+ // MIT License
2
+
3
+ // Copyright (c) 2025 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 type { HostComponent, ViewProps } from 'react-native';
24
+ import {
25
+ BubblingEventHandler,
26
+ Float,
27
+ Int32,
28
+ } from 'react-native/Libraries/Types/CodegenTypes';
29
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
30
+
31
+ export type NativeParams = {
32
+ source?: string;
33
+ singlePage: boolean;
34
+ maxZoom: Float;
35
+ };
36
+
37
+ type PageChangeEventPayload = {
38
+ position: Int32;
39
+ total: Int32;
40
+ };
41
+
42
+ export interface NativeProps extends ViewProps {
43
+ maxPageResolution: Float;
44
+ distanceBetweenPages: Float;
45
+ params: NativeParams;
46
+ onPageChange: BubblingEventHandler<PageChangeEventPayload>;
47
+ }
48
+
49
+ export default codegenNativeComponent<NativeProps>(
50
+ 'RNPdfRendererView',
51
+ ) as HostComponent<NativeProps>;
@@ -1,118 +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
-
113
- @ReactProp(name = "maxPageResolution")
114
- public void setMaxPageResolution(ViewGroup layout, @Nullable float maxPageResolution) {
115
- var recyclerView = (PdfRendererRecyclerView) layout.getChildAt(0);
116
- recyclerView.setMaxPageResolution(maxPageResolution);
117
- }
118
- }