react-native-pdf-jsi 4.2.2 → 4.3.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
@@ -9,6 +9,7 @@
9
9
  ---
10
10
 
11
11
  [![npm version](https://img.shields.io/npm/v/react-native-pdf-jsi?style=flat-square&logo=npm&color=cb3837)](https://www.npmjs.com/package/react-native-pdf-jsi)
12
+ [![Expo Compatible](https://img.shields.io/badge/Expo-Compatible-4630EB?style=flat-square&logo=expo)](https://expo.dev)
12
13
  [![total downloads](https://img.shields.io/npm/dt/react-native-pdf-jsi?style=flat-square&logo=npm&color=cb3837)](https://www.npmjs.com/package/react-native-pdf-jsi)
13
14
  [![weekly downloads](https://img.shields.io/npm/dw/react-native-pdf-jsi?style=flat-square&logo=npm&color=cb3837)](https://www.npmjs.com/package/react-native-pdf-jsi)
14
15
  [![GitHub stars](https://img.shields.io/github/stars/126punith/react-native-pdf-jsi?style=flat-square&logo=github&color=181717)](https://github.com/126punith/react-native-pdf-jsi)
@@ -111,6 +112,51 @@ react-native link react-native-blob-util
111
112
  react-native link react-native-pdf-jsi
112
113
  ```
113
114
 
115
+ ### Expo Installation
116
+
117
+ This package works with **Expo development builds** (not Expo Go, as it requires native code).
118
+
119
+ **1. Install the package and peer dependencies:**
120
+
121
+ ```bash
122
+ npx expo install react-native-pdf-jsi react-native-blob-util @react-native-async-storage/async-storage
123
+ ```
124
+
125
+ **2. Add the config plugin to your `app.json` or `app.config.js`:**
126
+
127
+ ```json
128
+ {
129
+ "expo": {
130
+ "plugins": ["react-native-pdf-jsi"]
131
+ }
132
+ }
133
+ ```
134
+
135
+ **3. Rebuild your development build:**
136
+
137
+ ```bash
138
+ # Generate native projects
139
+ npx expo prebuild
140
+
141
+ # Run on iOS
142
+ npx expo run:ios
143
+
144
+ # Run on Android
145
+ npx expo run:android
146
+ ```
147
+
148
+ > **Note:** The config plugin automatically configures:
149
+ > - Android: Adds Jitpack repository for PDF rendering dependencies
150
+ > - iOS: Ensures PDFKit framework is properly linked
151
+
152
+ **For EAS Build users:**
153
+
154
+ ```bash
155
+ # Build development client
156
+ eas build --profile development --platform ios
157
+ eas build --profile development --platform android
158
+ ```
159
+
114
160
  ### Windows Installation
115
161
 
116
162
  1. Open your solution in Visual Studio 2019 (e.g., `windows\yourapp.sln`)
@@ -410,6 +456,25 @@ MIT License - see [LICENSE](LICENSE) file for details.
410
456
 
411
457
  ## Recent Fixes
412
458
 
459
+ ### Expo Support (v4.3.0)
460
+ Added Expo config plugin for seamless integration with Expo development builds. The package now works with `npx expo prebuild` and `npx expo run:ios/android`.
461
+
462
+ **Installation:**
463
+ ```bash
464
+ npx expo install react-native-pdf-jsi react-native-blob-util @react-native-async-storage/async-storage
465
+ ```
466
+
467
+ **Configuration (app.json):**
468
+ ```json
469
+ {
470
+ "expo": {
471
+ "plugins": ["react-native-pdf-jsi"]
472
+ }
473
+ }
474
+ ```
475
+
476
+ **Note:** Expo Go is NOT supported (requires native code). Use Expo development builds.
477
+
413
478
  ### PDFCompressor Module Fix (v4.2.2)
414
479
  Fixed "Unable to resolve module react-native-pdf-jsi/src/PDFCompressor" error ([#17](https://github.com/126punith/react-native-pdf-jsi/issues/17)). The PDFCompressor module is now properly exported and accessible. Also fixed iOS compilation error for missing `RCTLogInfo` import. The compression feature now works correctly with accurate size estimates (~15-18% compression using native zlib deflate).
415
480
 
package/app.plugin.js ADDED
@@ -0,0 +1,2 @@
1
+ // Expo config plugin entry point
2
+ module.exports = require('./plugin/build').default;
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "react-native-pdf-jsi",
3
- "version": "4.2.2",
3
+ "version": "4.3.0",
4
4
  "summary": "High-performance React Native PDF viewer with JSI acceleration - up to 80x faster than traditional bridge",
5
5
  "description": "🚀 Ultra-fast React Native PDF viewer with JSI (JavaScript Interface) integration for maximum performance. Features lazy loading, smart caching, progressive loading, and zero-bridge overhead operations. Perfect for large PDF files with 30-day persistent cache and advanced memory optimization. Google Play 16KB page size compliant for Android 15+. Supports iOS, Android, and Windows platforms.",
6
6
  "main": "index.js",
7
7
  "typings": "./index.d.ts",
8
+ "app": {
9
+ "plugin": "./plugin/build"
10
+ },
8
11
  "repository": {
9
12
  "type": "git",
10
13
  "url": "git+https://github.com/126punith/react-native-pdf-jsi.git"
@@ -50,7 +53,9 @@
50
53
  "optimization",
51
54
  "caching",
52
55
  "persistent-cache",
53
- "react-native-pdf-jsi-enhanced"
56
+ "react-native-pdf-jsi-enhanced",
57
+ "expo",
58
+ "expo-plugin"
54
59
  ],
55
60
  "author": {
56
61
  "name": "Punith M",
@@ -69,7 +74,13 @@
69
74
  "devDependencies": {
70
75
  "@babel/core": "^7.20.2",
71
76
  "@babel/runtime": "^7.20.1",
72
- "prop-types": "^15.7.2"
77
+ "@expo/config-plugins": "^9.0.0",
78
+ "prop-types": "^15.7.2",
79
+ "typescript": "^5.0.0"
80
+ },
81
+ "scripts": {
82
+ "build:plugin": "tsc -p plugin/tsconfig.json",
83
+ "prepublishOnly": "npm run build:plugin"
73
84
  },
74
85
  "peerDependencies": {
75
86
  "@react-native-async-storage/async-storage": ">=1.17.0",
@@ -82,6 +93,8 @@
82
93
  "ios/",
83
94
  "windows/",
84
95
  "src/",
96
+ "plugin/",
97
+ "app.plugin.js",
85
98
  "DoubleTapView.js",
86
99
  "index.d.ts",
87
100
  "index.js",
@@ -0,0 +1,3 @@
1
+ import { ConfigPlugin } from '@expo/config-plugins';
2
+ declare const _default: ConfigPlugin<void>;
3
+ export default _default;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const config_plugins_1 = require("@expo/config-plugins");
4
+ const withPdfJsiAndroid_1 = require("./withPdfJsiAndroid");
5
+ const withPdfJsiIos_1 = require("./withPdfJsiIos");
6
+ const pkg = require('../../package.json');
7
+ /**
8
+ * Expo config plugin for react-native-pdf-jsi
9
+ *
10
+ * This plugin configures the native projects for Expo development builds.
11
+ * It handles:
12
+ * - Android: Jitpack repository for AndroidPdfViewer, NDK configuration
13
+ * - iOS: PDFKit framework linking
14
+ *
15
+ * Note: This package requires development builds and won't work with Expo Go.
16
+ */
17
+ const withPdfJsi = (config) => {
18
+ // Warn about peer dependencies
19
+ console.log('[react-native-pdf-jsi] Remember to install peer dependencies:\n' +
20
+ ' - react-native-blob-util\n' +
21
+ ' - @react-native-async-storage/async-storage');
22
+ config = (0, withPdfJsiAndroid_1.withPdfJsiAndroid)(config);
23
+ config = (0, withPdfJsiIos_1.withPdfJsiIos)(config);
24
+ return config;
25
+ };
26
+ exports.default = (0, config_plugins_1.createRunOncePlugin)(withPdfJsi, pkg.name, pkg.version);
@@ -0,0 +1,8 @@
1
+ import { ConfigPlugin } from '@expo/config-plugins';
2
+ /**
3
+ * Android config plugin for react-native-pdf-jsi
4
+ *
5
+ * Configures the Android project to support the PDF library:
6
+ * - Adds Jitpack repository for AndroidPdfViewer dependency
7
+ */
8
+ export declare const withPdfJsiAndroid: ConfigPlugin;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withPdfJsiAndroid = void 0;
4
+ const config_plugins_1 = require("@expo/config-plugins");
5
+ /**
6
+ * Android config plugin for react-native-pdf-jsi
7
+ *
8
+ * Configures the Android project to support the PDF library:
9
+ * - Adds Jitpack repository for AndroidPdfViewer dependency
10
+ */
11
+ const withPdfJsiAndroid = (config) => {
12
+ return (0, config_plugins_1.withProjectBuildGradle)(config, (config) => {
13
+ if (config.modResults.language === 'groovy') {
14
+ config.modResults.contents = addJitpackRepository(config.modResults.contents);
15
+ }
16
+ return config;
17
+ });
18
+ };
19
+ exports.withPdfJsiAndroid = withPdfJsiAndroid;
20
+ /**
21
+ * Add Jitpack repository to the project's build.gradle if not already present.
22
+ * This is required for the AndroidPdfViewer dependency.
23
+ */
24
+ function addJitpackRepository(buildGradle) {
25
+ const jitpackUrl = "maven { url 'https://jitpack.io' }";
26
+ // Check if Jitpack is already added
27
+ if (buildGradle.includes('jitpack.io')) {
28
+ return buildGradle;
29
+ }
30
+ // Find the allprojects { repositories { ... } } block and add Jitpack
31
+ const allProjectsPattern = /allprojects\s*\{[\s\S]*?repositories\s*\{/;
32
+ const match = buildGradle.match(allProjectsPattern);
33
+ if (match) {
34
+ // Add Jitpack after the opening of repositories block
35
+ const insertPosition = match.index + match[0].length;
36
+ return (buildGradle.slice(0, insertPosition) +
37
+ `\n ${jitpackUrl}` +
38
+ buildGradle.slice(insertPosition));
39
+ }
40
+ // If allprojects block exists but repositories block doesn't have the expected format,
41
+ // try to add it in a different way
42
+ if (buildGradle.includes('allprojects')) {
43
+ // Look for maven { url pattern in allprojects section
44
+ const mavenCentralPattern = /(allprojects\s*\{[\s\S]*?repositories\s*\{[\s\S]*?)(mavenCentral\(\)|google\(\))/;
45
+ const mavenMatch = buildGradle.match(mavenCentralPattern);
46
+ if (mavenMatch) {
47
+ return buildGradle.replace(mavenCentralPattern, `$1$2\n ${jitpackUrl}`);
48
+ }
49
+ }
50
+ // If we couldn't find a good place, add a comment for manual addition
51
+ console.warn('[react-native-pdf-jsi] Could not automatically add Jitpack repository.\n' +
52
+ 'Please manually add the following to your android/build.gradle:\n' +
53
+ "maven { url 'https://jitpack.io' }");
54
+ return buildGradle;
55
+ }
@@ -0,0 +1,11 @@
1
+ import { ConfigPlugin } from '@expo/config-plugins';
2
+ /**
3
+ * iOS config plugin for react-native-pdf-jsi
4
+ *
5
+ * Configures the iOS project to support the PDF library:
6
+ * - Ensures PDFKit framework is properly linked (handled automatically by CocoaPods)
7
+ *
8
+ * Note: Most iOS configuration is handled by the podspec file.
9
+ * This plugin exists for any additional Xcode project modifications if needed.
10
+ */
11
+ export declare const withPdfJsiIos: ConfigPlugin;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withPdfJsiIos = void 0;
4
+ const config_plugins_1 = require("@expo/config-plugins");
5
+ /**
6
+ * iOS config plugin for react-native-pdf-jsi
7
+ *
8
+ * Configures the iOS project to support the PDF library:
9
+ * - Ensures PDFKit framework is properly linked (handled automatically by CocoaPods)
10
+ *
11
+ * Note: Most iOS configuration is handled by the podspec file.
12
+ * This plugin exists for any additional Xcode project modifications if needed.
13
+ */
14
+ const withPdfJsiIos = (config) => {
15
+ return (0, config_plugins_1.withXcodeProject)(config, async (config) => {
16
+ const xcodeProject = config.modResults;
17
+ // PDFKit framework is automatically linked through the podspec's s.framework = "PDFKit"
18
+ // This plugin hook is here for any future iOS-specific configurations
19
+ // Ensure the project has the PDFKit framework if needed
20
+ // (This is typically handled by CocoaPods, but we can add it explicitly if necessary)
21
+ const frameworks = xcodeProject.pbxFrameworksBuildPhaseObj(xcodeProject.getFirstTarget().uuid);
22
+ if (frameworks) {
23
+ // Check if PDFKit is already linked
24
+ const pdfKitLinked = Object.values(frameworks.files || {}).some((file) => { var _a; return (_a = file === null || file === void 0 ? void 0 : file.comment) === null || _a === void 0 ? void 0 : _a.includes('PDFKit'); });
25
+ if (!pdfKitLinked) {
26
+ // PDFKit is a system framework, it will be linked via the podspec
27
+ // No manual linking required in most cases
28
+ console.log('[react-native-pdf-jsi] iOS: PDFKit will be linked via CocoaPods');
29
+ }
30
+ }
31
+ return config;
32
+ });
33
+ };
34
+ exports.withPdfJsiIos = withPdfJsiIos;
@@ -0,0 +1,31 @@
1
+ import { ConfigPlugin, createRunOncePlugin } from '@expo/config-plugins';
2
+ import { withPdfJsiAndroid } from './withPdfJsiAndroid';
3
+ import { withPdfJsiIos } from './withPdfJsiIos';
4
+
5
+ const pkg = require('../../package.json');
6
+
7
+ /**
8
+ * Expo config plugin for react-native-pdf-jsi
9
+ *
10
+ * This plugin configures the native projects for Expo development builds.
11
+ * It handles:
12
+ * - Android: Jitpack repository for AndroidPdfViewer, NDK configuration
13
+ * - iOS: PDFKit framework linking
14
+ *
15
+ * Note: This package requires development builds and won't work with Expo Go.
16
+ */
17
+ const withPdfJsi: ConfigPlugin = (config) => {
18
+ // Warn about peer dependencies
19
+ console.log(
20
+ '[react-native-pdf-jsi] Remember to install peer dependencies:\n' +
21
+ ' - react-native-blob-util\n' +
22
+ ' - @react-native-async-storage/async-storage'
23
+ );
24
+
25
+ config = withPdfJsiAndroid(config);
26
+ config = withPdfJsiIos(config);
27
+
28
+ return config;
29
+ };
30
+
31
+ export default createRunOncePlugin(withPdfJsi, pkg.name, pkg.version);
@@ -0,0 +1,67 @@
1
+ import { ConfigPlugin, withProjectBuildGradle } from '@expo/config-plugins';
2
+
3
+ /**
4
+ * Android config plugin for react-native-pdf-jsi
5
+ *
6
+ * Configures the Android project to support the PDF library:
7
+ * - Adds Jitpack repository for AndroidPdfViewer dependency
8
+ */
9
+ export const withPdfJsiAndroid: ConfigPlugin = (config) => {
10
+ return withProjectBuildGradle(config, (config) => {
11
+ if (config.modResults.language === 'groovy') {
12
+ config.modResults.contents = addJitpackRepository(config.modResults.contents);
13
+ }
14
+ return config;
15
+ });
16
+ };
17
+
18
+ /**
19
+ * Add Jitpack repository to the project's build.gradle if not already present.
20
+ * This is required for the AndroidPdfViewer dependency.
21
+ */
22
+ function addJitpackRepository(buildGradle: string): string {
23
+ const jitpackUrl = "maven { url 'https://jitpack.io' }";
24
+
25
+ // Check if Jitpack is already added
26
+ if (buildGradle.includes('jitpack.io')) {
27
+ return buildGradle;
28
+ }
29
+
30
+ // Find the allprojects { repositories { ... } } block and add Jitpack
31
+ const allProjectsPattern = /allprojects\s*\{[\s\S]*?repositories\s*\{/;
32
+ const match = buildGradle.match(allProjectsPattern);
33
+
34
+ if (match) {
35
+ // Add Jitpack after the opening of repositories block
36
+ const insertPosition = match.index! + match[0].length;
37
+ return (
38
+ buildGradle.slice(0, insertPosition) +
39
+ `\n ${jitpackUrl}` +
40
+ buildGradle.slice(insertPosition)
41
+ );
42
+ }
43
+
44
+ // If allprojects block exists but repositories block doesn't have the expected format,
45
+ // try to add it in a different way
46
+ if (buildGradle.includes('allprojects')) {
47
+ // Look for maven { url pattern in allprojects section
48
+ const mavenCentralPattern = /(allprojects\s*\{[\s\S]*?repositories\s*\{[\s\S]*?)(mavenCentral\(\)|google\(\))/;
49
+ const mavenMatch = buildGradle.match(mavenCentralPattern);
50
+
51
+ if (mavenMatch) {
52
+ return buildGradle.replace(
53
+ mavenCentralPattern,
54
+ `$1$2\n ${jitpackUrl}`
55
+ );
56
+ }
57
+ }
58
+
59
+ // If we couldn't find a good place, add a comment for manual addition
60
+ console.warn(
61
+ '[react-native-pdf-jsi] Could not automatically add Jitpack repository.\n' +
62
+ 'Please manually add the following to your android/build.gradle:\n' +
63
+ "maven { url 'https://jitpack.io' }"
64
+ );
65
+
66
+ return buildGradle;
67
+ }
@@ -0,0 +1,40 @@
1
+ import { ConfigPlugin, withXcodeProject } from '@expo/config-plugins';
2
+
3
+ /**
4
+ * iOS config plugin for react-native-pdf-jsi
5
+ *
6
+ * Configures the iOS project to support the PDF library:
7
+ * - Ensures PDFKit framework is properly linked (handled automatically by CocoaPods)
8
+ *
9
+ * Note: Most iOS configuration is handled by the podspec file.
10
+ * This plugin exists for any additional Xcode project modifications if needed.
11
+ */
12
+ export const withPdfJsiIos: ConfigPlugin = (config) => {
13
+ return withXcodeProject(config, async (config) => {
14
+ const xcodeProject = config.modResults;
15
+
16
+ // PDFKit framework is automatically linked through the podspec's s.framework = "PDFKit"
17
+ // This plugin hook is here for any future iOS-specific configurations
18
+
19
+ // Ensure the project has the PDFKit framework if needed
20
+ // (This is typically handled by CocoaPods, but we can add it explicitly if necessary)
21
+ const frameworks = xcodeProject.pbxFrameworksBuildPhaseObj(
22
+ xcodeProject.getFirstTarget().uuid
23
+ );
24
+
25
+ if (frameworks) {
26
+ // Check if PDFKit is already linked
27
+ const pdfKitLinked = Object.values(frameworks.files || {}).some(
28
+ (file: any) => file?.comment?.includes('PDFKit')
29
+ );
30
+
31
+ if (!pdfKitLinked) {
32
+ // PDFKit is a system framework, it will be linked via the podspec
33
+ // No manual linking required in most cases
34
+ console.log('[react-native-pdf-jsi] iOS: PDFKit will be linked via CocoaPods');
35
+ }
36
+ }
37
+
38
+ return config;
39
+ });
40
+ };
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "./build",
4
+ "rootDir": "./src",
5
+ "module": "commonjs",
6
+ "target": "ES2019",
7
+ "declaration": true,
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "resolveJsonModule": true
12
+ },
13
+ "include": ["src/**/*"]
14
+ }