react-native-pdf 6.3.0 → 6.4.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 +44 -70
- package/android/.gradle/5.6.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/5.6.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/5.6.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/src/main/java/org/wonday/pdf/PdfView.java +21 -2
- package/index.d.ts +1 -2
- package/index.js +20 -46
- package/index.js.flow +2 -2
- package/ios/RCTPdf/RCTPdfView.h +2 -0
- package/ios/RCTPdf/RCTPdfView.m +17 -4
- package/ios/RCTPdf/RCTPdfViewManager.m +1 -1
- package/ios/RCTPdf.xcodeproj/xcuserdata/wonday.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/package.json +21 -6
- package/windows/README.md +4 -8
- package/.babelrc +0 -3
- package/.github/workflows/windows-ci.yml +0 -39
- package/example/.eslintrc.js +0 -4
- package/example/PDFExample.js +0 -180
- package/example/__windows_tests__/TestPDF.js +0 -43
- package/example/android/app/BUCK +0 -55
- package/example/android/app/build.gradle +0 -210
- package/example/android/app/build_defs.bzl +0 -19
- package/example/android/app/proguard-rules.pro +0 -10
- package/example/android/app/src/debug/AndroidManifest.xml +0 -8
- package/example/android/app/src/main/AndroidManifest.xml +0 -26
- package/example/android/app/src/main/assets/test.pdf +0 -0
- package/example/android/app/src/main/java/com/pdfexample/MainActivity.java +0 -15
- package/example/android/app/src/main/java/com/pdfexample/MainApplication.java +0 -49
- package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/values/strings.xml +0 -3
- package/example/android/app/src/main/res/values/styles.xml +0 -9
- package/example/android/build.gradle +0 -38
- package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/example/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/example/android/gradle.properties +0 -21
- package/example/android/gradlew +0 -188
- package/example/android/gradlew.bat +0 -100
- package/example/android/settings.gradle +0 -3
- package/example/app.json +0 -4
- package/example/babel.config.js +0 -3
- package/example/index.js +0 -9
- package/example/ios/PDFExample/AppDelegate.h +0 -15
- package/example/ios/PDFExample/AppDelegate.m +0 -42
- package/example/ios/PDFExample/Base.lproj/LaunchScreen.xib +0 -42
- package/example/ios/PDFExample/Images.xcassets/AppIcon.appiconset/Contents.json +0 -38
- package/example/ios/PDFExample/Images.xcassets/Contents.json +0 -6
- package/example/ios/PDFExample/Info.plist +0 -57
- package/example/ios/PDFExample/main.m +0 -16
- package/example/ios/PDFExample-tvOS/Info.plist +0 -53
- package/example/ios/PDFExample-tvOSTests/Info.plist +0 -24
- package/example/ios/PDFExample.xcodeproj/project.pbxproj +0 -923
- package/example/ios/PDFExample.xcodeproj/xcshareddata/xcschemes/PDFExample-tvOS.xcscheme +0 -129
- package/example/ios/PDFExample.xcodeproj/xcshareddata/xcschemes/PDFExample.xcscheme +0 -129
- package/example/ios/PDFExample.xcworkspace/contents.xcworkspacedata +0 -10
- package/example/ios/PDFExampleTests/Info.plist +0 -24
- package/example/ios/PDFExampleTests/PDFExampleTests.m +0 -68
- package/example/ios/Podfile +0 -47
- package/example/ios/Podfile.lock +0 -205
- package/example/jest-windows/driver.setup.js +0 -12
- package/example/jest-windows/jest.setup.js +0 -1
- package/example/jest.windows.config.js +0 -4
- package/example/metro.config.js +0 -29
- package/example/package.json +0 -48
- package/example/test.pdf +0 -0
- package/example/windows/PDFExample/App.cpp +0 -80
- package/example/windows/PDFExample/App.h +0 -20
- package/example/windows/PDFExample/App.idl +0 -3
- package/example/windows/PDFExample/App.xaml +0 -10
- package/example/windows/PDFExample/Assets/LockScreenLogo.scale-200.png +0 -0
- package/example/windows/PDFExample/Assets/SplashScreen.scale-200.png +0 -0
- package/example/windows/PDFExample/Assets/Square150x150Logo.scale-200.png +0 -0
- package/example/windows/PDFExample/Assets/Square44x44Logo.scale-200.png +0 -0
- package/example/windows/PDFExample/Assets/Square44x44Logo.targetsize-24_altform-unplated.png +0 -0
- package/example/windows/PDFExample/Assets/StoreLogo.png +0 -0
- package/example/windows/PDFExample/Assets/Wide310x150Logo.scale-200.png +0 -0
- package/example/windows/PDFExample/AutolinkedNativeModules.g.cpp +0 -18
- package/example/windows/PDFExample/AutolinkedNativeModules.g.h +0 -10
- package/example/windows/PDFExample/AutolinkedNativeModules.g.props +0 -6
- package/example/windows/PDFExample/AutolinkedNativeModules.g.targets +0 -10
- package/example/windows/PDFExample/MainPage.cpp +0 -24
- package/example/windows/PDFExample/MainPage.h +0 -21
- package/example/windows/PDFExample/MainPage.idl +0 -8
- package/example/windows/PDFExample/MainPage.xaml +0 -16
- package/example/windows/PDFExample/PDFExample.vcxproj +0 -205
- package/example/windows/PDFExample/PDFExample.vcxproj.filters +0 -64
- package/example/windows/PDFExample/PDFExample_TemporaryKey.pfx +0 -0
- package/example/windows/PDFExample/Package.appxmanifest +0 -52
- package/example/windows/PDFExample/PropertySheet.props +0 -16
- package/example/windows/PDFExample/ReactPackageProvider.cpp +0 -18
- package/example/windows/PDFExample/ReactPackageProvider.h +0 -15
- package/example/windows/PDFExample/packages.config +0 -5
- package/example/windows/PDFExample/pch.cpp +0 -1
- package/example/windows/PDFExample/pch.h +0 -29
- package/example/windows/PDFExample.sln +0 -264
- package/issue_template.md +0 -13
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ A react native PDF view component (cross-platform support)
|
|
|
5
5
|
|
|
6
6
|
### Feature
|
|
7
7
|
|
|
8
|
-
* read a PDF from url
|
|
8
|
+
* read a PDF from url, blob, local file or asset and can cache it.
|
|
9
9
|
* display horizontally or vertically
|
|
10
10
|
* drag and zoom
|
|
11
11
|
* double tap for zoom
|
|
@@ -13,36 +13,24 @@ A react native PDF view component (cross-platform support)
|
|
|
13
13
|
* jump to a specific page in the pdf
|
|
14
14
|
|
|
15
15
|
### Supported versions
|
|
16
|
-
We use [`
|
|
17
|
-
So you should install react-native-pdf and
|
|
16
|
+
We use [`react-native-blob-util`](https://github.com/RonRadtke/react-native-blob-util) to handle file system access in this package,
|
|
17
|
+
So you should install react-native-pdf and react-native-blob-util
|
|
18
18
|
|
|
19
|
-
> The table below shows the supported versions of React Native and
|
|
19
|
+
> The table below shows the supported versions of React Native and react-native-blob-util for different versions of `react-native-pdf`.
|
|
20
20
|
|
|
21
|
-
| React Native | 0.4x - 0.56 | 0.57 | 0.60+ | 0.62+ |
|
|
22
|
-
| ------------------------- | --------------- | ------- | -------- | -------- |
|
|
23
|
-
| react-native-pdf | 4.x.x - 5.0.x | 5.0.9+ | 6.0.0+ | 6.2.0+ |
|
|
24
|
-
|
|
|
25
|
-
| progress-bar-android | | | | 1.0.3+ |
|
|
26
|
-
| progress-view | | | | 1.0.3+ |
|
|
27
|
-
|
|
28
|
-
Currently, Windows support is partial. For Windows, it's necessary to install `rn-fetch-blob` from the [PR that adds Windows support](https://github.com/joltup/rn-fetch-blob/pull/701):
|
|
29
|
-
```
|
|
30
|
-
yarn add github:joltup/rn-fetch-blob#pull/701/head
|
|
31
|
-
```
|
|
21
|
+
| React Native | 0.4x - 0.56 | 0.57 | 0.60+ | 0.62+ | 0.62+ |
|
|
22
|
+
| ------------------------- | --------------- | ------- | -------- | -------- | -------- |
|
|
23
|
+
| react-native-pdf | 4.x.x - 5.0.x | 5.0.9+ | 6.0.0+ | 6.2.0+ | 6.4.0+ |
|
|
24
|
+
| react-native-blob-util | | | | | 0.13.7+ |
|
|
32
25
|
|
|
33
26
|
### Installation
|
|
34
27
|
|
|
35
28
|
```bash
|
|
36
29
|
# Using npm
|
|
37
|
-
npm install react-native-pdf
|
|
30
|
+
npm install react-native-pdf react-native-blob-util fbjs --save
|
|
38
31
|
|
|
39
32
|
# or using yarn:
|
|
40
|
-
yarn add react-native-pdf
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
For Windows, it's necessary to install `rn-fetch-blob` from the [PR that adds Windows support](https://github.com/joltup/rn-fetch-blob/pull/701):
|
|
44
|
-
```
|
|
45
|
-
yarn add github:joltup/rn-fetch-blob#pull/701/head
|
|
33
|
+
yarn add react-native-pdf react-native-blob-util fbjs
|
|
46
34
|
```
|
|
47
35
|
|
|
48
36
|
Then follow the instructions for your platform to link react-native-pdf into your project:
|
|
@@ -58,9 +46,7 @@ Run `pod install` in the `ios` directory. Linking is not required in React Nativ
|
|
|
58
46
|
**React Native 0.59 and below**
|
|
59
47
|
|
|
60
48
|
```bash
|
|
61
|
-
react-native link
|
|
62
|
-
react-native link @react-native-community/progress-bar-android
|
|
63
|
-
react-native link @react-native-community/progress-view
|
|
49
|
+
react-native link react-native-blob-util
|
|
64
50
|
react-native link react-native-pdf
|
|
65
51
|
```
|
|
66
52
|
</details>
|
|
@@ -87,9 +73,7 @@ android {
|
|
|
87
73
|
|
|
88
74
|
**React Native 0.59.0 and below**
|
|
89
75
|
```bash
|
|
90
|
-
react-native link
|
|
91
|
-
react-native link @react-native-community/progress-bar-android
|
|
92
|
-
react-native link @react-native-community/progress-view
|
|
76
|
+
react-native link react-native-blob-util
|
|
93
77
|
react-native link react-native-pdf
|
|
94
78
|
```
|
|
95
79
|
|
|
@@ -102,16 +86,16 @@ react-native link react-native-pdf
|
|
|
102
86
|
|
|
103
87
|
- Open your solution in Visual Studio 2019 (eg. `windows\yourapp.sln`)
|
|
104
88
|
- Right-click Solution icon in Solution Explorer > Add > Existing Project...
|
|
105
|
-
- Add `node_modules\@react-native-community\progress-view\windows\progress-view\progress-view.vcxproj`
|
|
106
89
|
- If running RNW 0.62: add `node_modules\react-native-pdf\windows\RCTPdf\RCTPdf.vcxproj`
|
|
107
|
-
- If running RNW 0.62: add `node_modules\
|
|
90
|
+
- If running RNW 0.62: add `node_modules\react-native-blob-util\windows\ReactNativeBlobUtil\ReactNativeBlobUtil.vcxproj`
|
|
108
91
|
- Right-click main application project > Add > Reference...
|
|
109
|
-
|
|
110
|
-
- If running 0.62, also select `RCTPdf` and `
|
|
111
|
-
- In app `pch.h` add `#include "winrt/
|
|
112
|
-
- If running 0.62, also select `#include "winrt/
|
|
92
|
+
- Select `progress-view` and in Solution Projects
|
|
93
|
+
- If running 0.62, also select `RCTPdf` and `ReactNativeBlobUtil`
|
|
94
|
+
- In app `pch.h` add `#include "winrt/RCTPdf.h"`
|
|
95
|
+
- If running 0.62, also select `#include "winrt/ReactNativeBlobUtil.h"`
|
|
113
96
|
- In `App.cpp` add `PackageProviders().Append(winrt::progress_view::ReactPackageProvider());` before `InitializeComponent();`
|
|
114
|
-
- If running RNW 0.62, also add `PackageProviders().Append(winrt::RCTPdf::ReactPackageProvider());` and `PackageProviders().Append(winrt::
|
|
97
|
+
- If running RNW 0.62, also add `PackageProviders().Append(winrt::RCTPdf::ReactPackageProvider());` and `PackageProviders().Append(winrt::ReactNativeBlobUtil::ReactPackageProvider());`
|
|
98
|
+
|
|
115
99
|
|
|
116
100
|
#### Bundling PDFs with the app
|
|
117
101
|
To add a `test.pdf` like in the example add:
|
|
@@ -182,6 +166,13 @@ react-native run-ios
|
|
|
182
166
|
<details>
|
|
183
167
|
<summary>ChangeLog details</summary>
|
|
184
168
|
|
|
169
|
+
v6.4.0
|
|
170
|
+
1. Remove sample for reducing NPM package size
|
|
171
|
+
2. Add support for setting a filename for the cached pdf file
|
|
172
|
+
3. Use react-native-blob-util instead of rn-fetch-blob
|
|
173
|
+
4. Add blob support
|
|
174
|
+
5. remove progress-view dependency
|
|
175
|
+
|
|
185
176
|
v6.3.0
|
|
186
177
|
1. Add windows support
|
|
187
178
|
2. Fixed some bugs
|
|
@@ -221,25 +212,6 @@ v6.0.0
|
|
|
221
212
|
1. Add JS callback onPressLink for pdf link press listener
|
|
222
213
|
2. Fix calling setState while unmounted
|
|
223
214
|
|
|
224
|
-
v5.1.7
|
|
225
|
-
1. Downgraded to AndroidPdfViewer 3.1.0-beta.1
|
|
226
|
-
|
|
227
|
-
v5.1.6
|
|
228
|
-
1. Fixed componentWillReceiveProps and componentWillMount warnings
|
|
229
|
-
|
|
230
|
-
v5.1.5
|
|
231
|
-
1. Added setPage() method
|
|
232
|
-
2. Upgraded to AndroidPdfViewer to 3.2.0-beta.1
|
|
233
|
-
3. Fixed some codes ,readme and sample
|
|
234
|
-
|
|
235
|
-
v5.1.4
|
|
236
|
-
1. Updated example project to RN 0.60.4
|
|
237
|
-
2. Fixed blank view after native module got recycled in onDetachedFromWindow event
|
|
238
|
-
3. Restore singleTap, only callback, do not change scale
|
|
239
|
-
|
|
240
|
-
v5.1.3
|
|
241
|
-
1. Removed singleTap action from iOS, make the same with Android.
|
|
242
|
-
|
|
243
215
|
|
|
244
216
|
[[more]](https://github.com/wonday/react-native-pdf/releases)
|
|
245
217
|
|
|
@@ -258,38 +230,38 @@ v5.1.3
|
|
|
258
230
|
|
|
259
231
|
import React from 'react';
|
|
260
232
|
import { StyleSheet, Dimensions, View } from 'react-native';
|
|
261
|
-
|
|
262
233
|
import Pdf from 'react-native-pdf';
|
|
263
234
|
|
|
264
235
|
export default class PDFExample extends React.Component {
|
|
265
236
|
render() {
|
|
266
|
-
const source = {uri:'http://samples.leanpub.com/thereactnativebook-sample.pdf',cache:true};
|
|
237
|
+
const source = { uri: 'http://samples.leanpub.com/thereactnativebook-sample.pdf', cache: true };
|
|
267
238
|
//const source = require('./test.pdf'); // ios only
|
|
268
|
-
//const source = {uri:'bundle-assets://test.pdf'};
|
|
269
|
-
|
|
239
|
+
//const source = {uri:'bundle-assets://test.pdf' };
|
|
270
240
|
//const source = {uri:'file:///sdcard/test.pdf'};
|
|
271
241
|
//const source = {uri:"data:application/pdf;base64,JVBERi0xLjcKJc..."};
|
|
242
|
+
//const source = {uri:"content://com.example.blobs/xxxxxxxx-...?offset=0&size=xxx"};
|
|
243
|
+
//const source = {uri:"blob:xxxxxxxx-...?offset=0&size=xxx"};
|
|
272
244
|
|
|
273
245
|
return (
|
|
274
246
|
<View style={styles.container}>
|
|
275
247
|
<Pdf
|
|
276
248
|
source={source}
|
|
277
|
-
onLoadComplete={(numberOfPages,filePath)=>{
|
|
278
|
-
console.log(`
|
|
249
|
+
onLoadComplete={(numberOfPages,filePath) => {
|
|
250
|
+
console.log(`Number of pages: ${numberOfPages}`);
|
|
279
251
|
}}
|
|
280
|
-
onPageChanged={(page,numberOfPages)=>{
|
|
281
|
-
console.log(`
|
|
252
|
+
onPageChanged={(page,numberOfPages) => {
|
|
253
|
+
console.log(`Current page: ${page}`);
|
|
282
254
|
}}
|
|
283
|
-
onError={(error)=>{
|
|
255
|
+
onError={(error) => {
|
|
284
256
|
console.log(error);
|
|
285
257
|
}}
|
|
286
|
-
onPressLink={(uri)=>{
|
|
287
|
-
console.log(`Link
|
|
258
|
+
onPressLink={(uri) => {
|
|
259
|
+
console.log(`Link pressed: ${uri}`);
|
|
288
260
|
}}
|
|
289
261
|
style={styles.pdf}/>
|
|
290
262
|
</View>
|
|
291
263
|
)
|
|
292
|
-
|
|
264
|
+
}
|
|
293
265
|
}
|
|
294
266
|
|
|
295
267
|
const styles = StyleSheet.create({
|
|
@@ -324,14 +296,13 @@ const styles = StyleSheet.create({
|
|
|
324
296
|
| spacing | number | 10 | the breaker size between pages| ✔ | ✔ | ✔ | <3.0 |
|
|
325
297
|
| password | string | "" | pdf password, if password error, will call OnError() with message "Password required or incorrect password." | ✔ | ✔ | ✔ | <3.0 |
|
|
326
298
|
| style | object | {backgroundColor:"#eee"} | support normal view style, you can use this to set border/spacing color... | ✔ | ✔ | ✔ | <3.0 |
|
|
327
|
-
|
|
|
328
|
-
| activityIndicatorProps | object | {color:'#009900', progressTintColor:'#009900'} | activityIndicator props | ✔ | ✔ | ✖ | 3.1 |
|
|
299
|
+
| renderActivityIndicator | (progress) => Component | <ProgressBar/> | when loading show it as an indicator, you can use your component| ✔ | ✔ | ✖ | <3.0 |
|
|
329
300
|
| enableAntialiasing | bool | true | improve rendering a little bit on low-res screens, but maybe course some problem on Android 4.4, so add a switch | ✖ | ✔ | ✖ | <3.0 |
|
|
330
301
|
| enablePaging | bool | false | only show one page in screen | ✔ | ✔ | ✔ | 5.0.1 |
|
|
331
302
|
| enableRTL | bool | false | scroll page as "page3, page2, page1" | ✔ | ✖ | ✔ | 5.0.1 |
|
|
332
303
|
| enableAnnotationRendering | bool | true | enable rendering annotation, notice:iOS only support initial setting,not support realtime changing | ✔ | ✔ | ✖ | 5.0.3 |
|
|
333
304
|
| trustAllCerts | bool | true | Allow connections to servers with self-signed certification | ✔ | ✔ | ✖ | 6.0.? |
|
|
334
|
-
| singlePage | bool | false | Only show first page, useful for thumbnail views | ✔ | ✔ | ✔ | 6.1
|
|
305
|
+
| singlePage | bool | false | Only show first page, useful for thumbnail views | ✔ | ✔ | ✔ | 6.2.1 |
|
|
335
306
|
| onLoadProgress | function(percent) | null | callback when loading, return loading progress (0-1) | ✔ | ✔ | ✖ | <3.0 |
|
|
336
307
|
| onLoadComplete | function(numberOfPages, path, {width, height}, tableContents) | null | callback when pdf load completed, return total page count, pdf local/cache path, {width,height} and table of contents | ✔ | ✔ | ✔ but without tableContents | <3.0 |
|
|
337
308
|
| onPageChanged | function(page,numberOfPages) | null | callback when page changed ,return current page and total page count | ✔ | ✔ | ✔ | <3.0 |
|
|
@@ -346,6 +317,7 @@ const styles = StyleSheet.create({
|
|
|
346
317
|
| ------------ | ----------- | ------- | --- | ------- | ------- |
|
|
347
318
|
| uri | pdf source, see the forllowing for detail.| required | ✔ | ✔ | ✔ |
|
|
348
319
|
| cache | use cache or not | false | ✔ | ✔ | ✖ |
|
|
320
|
+
| cacheFileName | specific file name for cached pdf file | SHA1(uri) result | ✔ | ✔ | ✖ |
|
|
349
321
|
| expiration | cache file expired seconds (0 is not expired) | 0 | ✔ | ✔ | ✖ |
|
|
350
322
|
| method | request method when uri is a url | "GET" | ✔ | ✔ | ✖ |
|
|
351
323
|
| headers | request headers when uri is a url | {} | ✔ | ✔ | ✖ |
|
|
@@ -361,8 +333,10 @@ const styles = StyleSheet.create({
|
|
|
361
333
|
| `{uri:"data:application/pdf;base64,JVBERi0xLjcKJc..."}` | load pdf from base64 string | ✔ | ✔ | ✔ |
|
|
362
334
|
| `{uri:"file:///absolute/path/to/xxx.pdf"}` | load pdf from local file system | ✔ | ✔ | ✔ |
|
|
363
335
|
| `{uri:"ms-appx:///xxx.pdf"}}` | load pdf bundled with UWP app | ✖ | ✖ | ✔ |
|
|
336
|
+
| `{uri:"content://com.example.blobs/xxxxxxxx-...?offset=0&size=xxx"}` | load pdf from content URI | ✔* | ✖ | ✖ |
|
|
337
|
+
| `{uri:"blob:xxxxxxxx-...?offset=0&size=xxx"}` | load pdf from blob URL | ✖ | ✔ | ✖ |
|
|
364
338
|
|
|
365
|
-
|
|
339
|
+
\*) requires building React Native from source with [this patch](https://github.com/facebook/react-native/pull/31789)
|
|
366
340
|
### Methods
|
|
367
341
|
* [setPage](#setPage)
|
|
368
342
|
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
File without changes
|
|
@@ -10,6 +10,7 @@ package org.wonday.pdf;
|
|
|
10
10
|
|
|
11
11
|
import java.io.File;
|
|
12
12
|
|
|
13
|
+
import android.content.ContentResolver;
|
|
13
14
|
import android.content.Context;
|
|
14
15
|
import android.view.View;
|
|
15
16
|
import android.view.ViewGroup;
|
|
@@ -49,6 +50,9 @@ import com.facebook.common.logging.FLog;
|
|
|
49
50
|
import com.facebook.react.common.ReactConstants;
|
|
50
51
|
|
|
51
52
|
import static java.lang.String.format;
|
|
53
|
+
|
|
54
|
+
import java.io.FileNotFoundException;
|
|
55
|
+
import java.io.InputStream;
|
|
52
56
|
import java.lang.ClassCastException;
|
|
53
57
|
|
|
54
58
|
import com.shockwave.pdfium.PdfDocument;
|
|
@@ -222,8 +226,23 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
|
|
|
222
226
|
Constants.Pinch.MINIMUM_ZOOM = this.minScale;
|
|
223
227
|
Constants.Pinch.MAXIMUM_ZOOM = this.maxScale;
|
|
224
228
|
|
|
225
|
-
Configurator configurator
|
|
226
|
-
|
|
229
|
+
Configurator configurator;
|
|
230
|
+
|
|
231
|
+
if (this.path.startsWith("content://")) {
|
|
232
|
+
ContentResolver contentResolver = getContext().getContentResolver();
|
|
233
|
+
InputStream inputStream = null;
|
|
234
|
+
Uri uri = Uri.parse(this.path);
|
|
235
|
+
try {
|
|
236
|
+
inputStream = contentResolver.openInputStream(uri);
|
|
237
|
+
} catch (FileNotFoundException e) {
|
|
238
|
+
throw new RuntimeException(e.getMessage());
|
|
239
|
+
}
|
|
240
|
+
configurator = this.fromStream(inputStream);
|
|
241
|
+
} else {
|
|
242
|
+
configurator = this.fromUri(getURI(this.path));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
configurator.defaultPage(this.page-1)
|
|
227
246
|
.swipeHorizontal(this.horizontal)
|
|
228
247
|
.onPageChange(this)
|
|
229
248
|
.onLoad(this)
|
package/index.d.ts
CHANGED
|
@@ -26,8 +26,7 @@ interface Props {
|
|
|
26
26
|
horizontal?: boolean,
|
|
27
27
|
spacing?: number,
|
|
28
28
|
password?: string,
|
|
29
|
-
|
|
30
|
-
activityIndicatorProps?: object,
|
|
29
|
+
renderActivityIndicator?: (progress: number) => React.ReactElement,
|
|
31
30
|
enableAntialiasing?: boolean,
|
|
32
31
|
enablePaging?: boolean,
|
|
33
32
|
enableRTL?: boolean,
|
package/index.js
CHANGED
|
@@ -15,25 +15,11 @@ import {
|
|
|
15
15
|
Platform,
|
|
16
16
|
ViewPropTypes,
|
|
17
17
|
StyleSheet,
|
|
18
|
-
Image
|
|
18
|
+
Image,
|
|
19
|
+
Text
|
|
19
20
|
} from 'react-native';
|
|
20
21
|
|
|
21
|
-
import
|
|
22
|
-
import { ProgressView } from '@react-native-community/progress-view'
|
|
23
|
-
|
|
24
|
-
let RNFetchBlob;
|
|
25
|
-
try {
|
|
26
|
-
RNFetchBlob = require('rn-fetch-blob').default;
|
|
27
|
-
} catch(e) {
|
|
28
|
-
// For Windows, when not using rn-fetch-blob with Windows support.
|
|
29
|
-
RNFetchBlob = {
|
|
30
|
-
fs : {
|
|
31
|
-
dirs: {
|
|
32
|
-
CacheDir: ''
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
}
|
|
22
|
+
import ReactNativeBlobUtil from 'react-native-blob-util'
|
|
37
23
|
|
|
38
24
|
const SHA1 = require('crypto-js/sha1');
|
|
39
25
|
import PdfView from './PdfView';
|
|
@@ -46,6 +32,7 @@ export default class Pdf extends Component {
|
|
|
46
32
|
PropTypes.shape({
|
|
47
33
|
uri: PropTypes.string,
|
|
48
34
|
cache: PropTypes.bool,
|
|
35
|
+
cacheFileName: PropTypes.string,
|
|
49
36
|
expiration: PropTypes.number,
|
|
50
37
|
}),
|
|
51
38
|
// Opaque type returned by require('./test.pdf')
|
|
@@ -58,9 +45,7 @@ export default class Pdf extends Component {
|
|
|
58
45
|
horizontal: PropTypes.bool,
|
|
59
46
|
spacing: PropTypes.number,
|
|
60
47
|
password: PropTypes.string,
|
|
61
|
-
|
|
62
|
-
activityIndicator: PropTypes.any,
|
|
63
|
-
activityIndicatorProps: PropTypes.any,
|
|
48
|
+
renderActivityIndicator: PropTypes.func,
|
|
64
49
|
enableAntialiasing: PropTypes.bool,
|
|
65
50
|
enableAnnotationRendering: PropTypes.bool,
|
|
66
51
|
enablePaging: PropTypes.bool,
|
|
@@ -98,7 +83,6 @@ export default class Pdf extends Component {
|
|
|
98
83
|
enableAnnotationRendering: true,
|
|
99
84
|
enablePaging: false,
|
|
100
85
|
enableRTL: false,
|
|
101
|
-
activityIndicatorProps: {color: '#009900', progressTintColor: '#009900'},
|
|
102
86
|
trustAllCerts: true,
|
|
103
87
|
usePDFKit: true,
|
|
104
88
|
singlePage: false,
|
|
@@ -182,10 +166,11 @@ export default class Pdf extends Component {
|
|
|
182
166
|
if (this._mounted) {
|
|
183
167
|
this.setState({isDownloaded: false, path: '', progress: 0});
|
|
184
168
|
}
|
|
185
|
-
const
|
|
169
|
+
const filename = source.cacheFileName || SHA1(uri) + '.pdf';
|
|
170
|
+
const cacheFile = ReactNativeBlobUtil.fs.dirs.CacheDir + '/' + filename;
|
|
186
171
|
|
|
187
172
|
if (source.cache) {
|
|
188
|
-
|
|
173
|
+
ReactNativeBlobUtil.fs
|
|
189
174
|
.stat(cacheFile)
|
|
190
175
|
.then(stats => {
|
|
191
176
|
if (!Boolean(source.expiration) || (source.expiration * 1000 + stats.lastModified) > (new Date().getTime())) {
|
|
@@ -216,7 +201,8 @@ export default class Pdf extends Component {
|
|
|
216
201
|
const isAsset = !!(uri && uri.match(/^bundle-assets:\/\//));
|
|
217
202
|
const isBase64 = !!(uri && uri.match(/^data:application\/pdf;base64/));
|
|
218
203
|
|
|
219
|
-
const
|
|
204
|
+
const filename = source.cacheFileName || SHA1(uri) + '.pdf';
|
|
205
|
+
const cacheFile = ReactNativeBlobUtil.fs.dirs.CacheDir + '/' + filename;
|
|
220
206
|
|
|
221
207
|
// delete old cache file
|
|
222
208
|
this._unlinkFile(cacheFile);
|
|
@@ -224,7 +210,7 @@ export default class Pdf extends Component {
|
|
|
224
210
|
if (isNetwork) {
|
|
225
211
|
this._downloadFile(source, cacheFile);
|
|
226
212
|
} else if (isAsset) {
|
|
227
|
-
|
|
213
|
+
ReactNativeBlobUtil.fs
|
|
228
214
|
.cp(uri, cacheFile)
|
|
229
215
|
.then(() => {
|
|
230
216
|
if (this._mounted) {
|
|
@@ -237,7 +223,7 @@ export default class Pdf extends Component {
|
|
|
237
223
|
})
|
|
238
224
|
} else if (isBase64) {
|
|
239
225
|
let data = uri.replace(/data:application\/pdf;base64,/i, '');
|
|
240
|
-
|
|
226
|
+
ReactNativeBlobUtil.fs
|
|
241
227
|
.writeFile(cacheFile, data, 'base64')
|
|
242
228
|
.then(() => {
|
|
243
229
|
if (this._mounted) {
|
|
@@ -277,7 +263,7 @@ export default class Pdf extends Component {
|
|
|
277
263
|
const tempCacheFile = cacheFile + '.tmp';
|
|
278
264
|
this._unlinkFile(tempCacheFile);
|
|
279
265
|
|
|
280
|
-
this.lastRNBFTask =
|
|
266
|
+
this.lastRNBFTask = ReactNativeBlobUtil.config({
|
|
281
267
|
// response data will be saved to this path if it has access right.
|
|
282
268
|
path: tempCacheFile,
|
|
283
269
|
trusty: this.props.trustAllCerts,
|
|
@@ -292,7 +278,7 @@ export default class Pdf extends Component {
|
|
|
292
278
|
.progress((received, total) => {
|
|
293
279
|
this.props.onLoadProgress && this.props.onLoadProgress(received / total);
|
|
294
280
|
if (this._mounted) {
|
|
295
|
-
this.setState({progress: received / total});
|
|
281
|
+
this.setState({progress: Math.floor(received / total)});
|
|
296
282
|
}
|
|
297
283
|
});
|
|
298
284
|
|
|
@@ -306,7 +292,7 @@ export default class Pdf extends Component {
|
|
|
306
292
|
let actualContentLength;
|
|
307
293
|
|
|
308
294
|
try {
|
|
309
|
-
const fileStats = await
|
|
295
|
+
const fileStats = await ReactNativeBlobUtil.fs.stat(res.path());
|
|
310
296
|
|
|
311
297
|
if (!fileStats || !fileStats.size) {
|
|
312
298
|
throw new Error("FileNotFound:" + source.uri);
|
|
@@ -323,7 +309,7 @@ export default class Pdf extends Component {
|
|
|
323
309
|
}
|
|
324
310
|
|
|
325
311
|
this._unlinkFile(cacheFile);
|
|
326
|
-
|
|
312
|
+
ReactNativeBlobUtil.fs
|
|
327
313
|
.cp(tempCacheFile, cacheFile)
|
|
328
314
|
.then(() => {
|
|
329
315
|
if (this._mounted) {
|
|
@@ -345,7 +331,7 @@ export default class Pdf extends Component {
|
|
|
345
331
|
|
|
346
332
|
_unlinkFile = async (file) => {
|
|
347
333
|
try {
|
|
348
|
-
await
|
|
334
|
+
await ReactNativeBlobUtil.fs.unlink(file);
|
|
349
335
|
} catch (e) {
|
|
350
336
|
|
|
351
337
|
}
|
|
@@ -409,21 +395,9 @@ export default class Pdf extends Component {
|
|
|
409
395
|
(<View
|
|
410
396
|
style={styles.progressContainer}
|
|
411
397
|
>
|
|
412
|
-
{this.props.
|
|
413
|
-
? this.props.
|
|
414
|
-
:
|
|
415
|
-
? <ProgressBar
|
|
416
|
-
progress={this.state.progress}
|
|
417
|
-
indeterminate={false}
|
|
418
|
-
styleAttr="Horizontal"
|
|
419
|
-
style={styles.progressBar}
|
|
420
|
-
{...this.props.activityIndicatorProps}
|
|
421
|
-
/>
|
|
422
|
-
: <ProgressView
|
|
423
|
-
progress={this.state.progress}
|
|
424
|
-
style={styles.progressBar}
|
|
425
|
-
{...this.props.activityIndicatorProps}
|
|
426
|
-
/>}
|
|
398
|
+
{this.props.renderActivityIndicator
|
|
399
|
+
? this.props.renderActivityIndicator(this.state.progress)
|
|
400
|
+
: <Text>{`${this.state.progress}%`}</Text>}
|
|
427
401
|
</View>):(
|
|
428
402
|
Platform.OS === "android" || Platform.OS === "windows"?(
|
|
429
403
|
<PdfCustom
|
package/index.js.flow
CHANGED
|
@@ -17,6 +17,7 @@ export type FitBoth = 2;
|
|
|
17
17
|
export type Source = {
|
|
18
18
|
body?: string | FormField[],
|
|
19
19
|
cache?: boolean,
|
|
20
|
+
cacheFileName?: string,
|
|
20
21
|
expiration?: number,
|
|
21
22
|
headers?: { [key: string]: string },
|
|
22
23
|
method?: Methods,
|
|
@@ -31,8 +32,7 @@ export type TableContent = {
|
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
export type Props = {
|
|
34
|
-
|
|
35
|
-
activityIndicatorProps?: { [prop: string]: mixed },
|
|
35
|
+
renderActivityIndicator?: (progress: number) => Node,
|
|
36
36
|
enableAnnotationRendering?: boolean,
|
|
37
37
|
enableAntialiasing?: boolean,
|
|
38
38
|
enablePaging?: boolean,
|
package/ios/RCTPdf/RCTPdfView.h
CHANGED
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
|
|
23
23
|
NS_CLASS_AVAILABLE_IOS(11_0) @interface RCTPdfView : UIView <UIGestureRecognizerDelegate>
|
|
24
24
|
|
|
25
|
+
- (instancetype)initWithBridge:(RCTBridge *)bridge;
|
|
26
|
+
|
|
25
27
|
@property(nonatomic, strong) NSString *path;
|
|
26
28
|
@property(nonatomic) int page;
|
|
27
29
|
@property(nonatomic) float scale;
|
package/ios/RCTPdf/RCTPdfView.m
CHANGED
|
@@ -17,11 +17,13 @@
|
|
|
17
17
|
#import <React/RCTEventDispatcher.h>
|
|
18
18
|
#import <React/UIView+React.h>
|
|
19
19
|
#import <React/RCTLog.h>
|
|
20
|
+
#import <React/RCTBlobManager.h>
|
|
20
21
|
#else
|
|
21
22
|
#import "RCTBridgeModule.h"
|
|
22
23
|
#import "RCTEventDispatcher.h"
|
|
23
24
|
#import "UIView+React.h"
|
|
24
25
|
#import "RCTLog.h"
|
|
26
|
+
#import <RCTBlobManager.h">
|
|
25
27
|
#endif
|
|
26
28
|
|
|
27
29
|
#ifndef __OPTIMIZE__
|
|
@@ -39,6 +41,7 @@ const float MIN_SCALE = 1.0f;
|
|
|
39
41
|
|
|
40
42
|
@implementation RCTPdfView
|
|
41
43
|
{
|
|
44
|
+
RCTBridge *_bridge;
|
|
42
45
|
PDFDocument *_pdfDocument;
|
|
43
46
|
PDFView *_pdfView;
|
|
44
47
|
PDFOutline *root;
|
|
@@ -47,11 +50,12 @@ const float MIN_SCALE = 1.0f;
|
|
|
47
50
|
NSArray<NSString *> *_changedProps;
|
|
48
51
|
}
|
|
49
52
|
|
|
50
|
-
- (instancetype)
|
|
53
|
+
- (instancetype)initWithBridge:(RCTBridge *)bridge
|
|
51
54
|
{
|
|
52
55
|
self = [super init];
|
|
53
56
|
if (self) {
|
|
54
57
|
|
|
58
|
+
_bridge = bridge;
|
|
55
59
|
_page = 1;
|
|
56
60
|
_scale = 1;
|
|
57
61
|
_minScale = MIN_SCALE;
|
|
@@ -114,14 +118,23 @@ const float MIN_SCALE = 1.0f;
|
|
|
114
118
|
|
|
115
119
|
if ([changedProps containsObject:@"path"]) {
|
|
116
120
|
|
|
117
|
-
NSURL *fileURL = [NSURL fileURLWithPath:_path];
|
|
118
121
|
|
|
119
122
|
if (_pdfDocument != Nil) {
|
|
120
123
|
//Release old doc
|
|
121
124
|
_pdfDocument = Nil;
|
|
122
125
|
}
|
|
123
|
-
|
|
124
|
-
|
|
126
|
+
|
|
127
|
+
if ([_path hasPrefix:@"blob:"]) {
|
|
128
|
+
RCTBlobManager *blobManager = [_bridge moduleForName:@"BlobModule"];
|
|
129
|
+
NSURL *blobURL = [NSURL URLWithString:_path];
|
|
130
|
+
NSData *blobData = [blobManager resolveURL:blobURL];
|
|
131
|
+
if (blobData != nil) {
|
|
132
|
+
_pdfDocument = [[PDFDocument alloc] initWithData:blobData];
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
NSURL *fileURL = [NSURL fileURLWithPath:_path];
|
|
136
|
+
_pdfDocument = [[PDFDocument alloc] initWithURL:fileURL];
|
|
137
|
+
}
|
|
125
138
|
|
|
126
139
|
if (_pdfDocument) {
|
|
127
140
|
|
|
@@ -20,7 +20,7 @@ RCT_EXPORT_MODULE()
|
|
|
20
20
|
{
|
|
21
21
|
if([[[UIDevice currentDevice] systemVersion] compare:@"11.0" options:NSNumericSearch] == NSOrderedDescending
|
|
22
22
|
|| [[[UIDevice currentDevice] systemVersion] compare:@"11.0" options:NSNumericSearch] == NSOrderedSame) {
|
|
23
|
-
return [[RCTPdfView alloc]
|
|
23
|
+
return [[RCTPdfView alloc] initWithBridge:self.bridge];
|
|
24
24
|
} else {
|
|
25
25
|
return NULL;
|
|
26
26
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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>RCTPdf.xcscheme_^#shared#^_</key>
|
|
8
|
+
<dict>
|
|
9
|
+
<key>orderHint</key>
|
|
10
|
+
<integer>52</integer>
|
|
11
|
+
</dict>
|
|
12
|
+
</dict>
|
|
13
|
+
</dict>
|
|
14
|
+
</plist>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-pdf",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"summary": "A react native PDF view component",
|
|
5
5
|
"description": "A react native PDF view component, support ios and android platform",
|
|
6
6
|
"main": "index.js",
|
|
@@ -28,9 +28,24 @@
|
|
|
28
28
|
"url": "https://github.com/wonday/react-native-pdf/issues"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"crypto-js": "^3.2.0"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
}
|
|
31
|
+
"crypto-js": "^3.2.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"prop-types": "^15.7.2"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"android/",
|
|
38
|
+
"ios/",
|
|
39
|
+
"windows/",
|
|
40
|
+
"DoubleTapView.js",
|
|
41
|
+
"index.d.ts",
|
|
42
|
+
"index.js",
|
|
43
|
+
"index.js.flow",
|
|
44
|
+
"PdfManager.js",
|
|
45
|
+
"PdfPageView.js",
|
|
46
|
+
"PdfView.js",
|
|
47
|
+
"PdfViewFlatList.js",
|
|
48
|
+
"PinchZoomView.js",
|
|
49
|
+
"react-native-pdf.podspec"
|
|
50
|
+
]
|
|
36
51
|
}
|
package/windows/README.md
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
# react-native-pdf Windows Implementation
|
|
2
2
|
|
|
3
|
-
Since the module uses react-native-progress-view, it also needs to be referenced in the App:
|
|
4
3
|
- Open your solution in Visual Studio 2019 (eg. `windows\yourapp.sln`)
|
|
5
4
|
- Right-click Solution icon in Solution Explorer > Add > Existing Project...
|
|
6
|
-
-
|
|
7
|
-
- If running RNW 0.62: add `node_modules\
|
|
8
|
-
- If running RNW 0.62: add `node_modules\rn-fetch-blob\windows\RNFetchBlob\RNFetchBlob.vcxproj`
|
|
5
|
+
- If running RNW 0.62: add `node_modules\react-native-pdf\windows\RCTPdf\RCTPdf.vcxproj`
|
|
6
|
+
- If running RNW 0.62: add `node_modules\rn-fetch-blob\windows\RNFetchBlob\RNFetchBlob.vcxproj`
|
|
9
7
|
- Right-click main application project > Add > Reference...
|
|
10
|
-
- Select `progress-view` and in Solution Projects
|
|
11
8
|
- If running 0.62, also select `RCTPdf` and `RNFetchBlob`
|
|
12
|
-
- In app `pch.h` add `#include "winrt/
|
|
9
|
+
- In app `pch.h` add `#include "winrt/RCTPdf.h"`
|
|
13
10
|
- If running 0.62, also select `#include "winrt/RNFetchBlob.h"`
|
|
14
|
-
-
|
|
15
|
-
- If running RNW 0.62, also add `PackageProviders().Append(winrt::RCTPdf::ReactPackageProvider());` and `PackageProviders().Append(winrt::RNFetchBlob::ReactPackageProvider());`
|
|
11
|
+
- If running RNW 0.62, add `PackageProviders().Append(winrt::RCTPdf::ReactPackageProvider());` and `PackageProviders().Append(winrt::RNFetchBlob::ReactPackageProvider());` before `InitializeComponent();`
|
|
16
12
|
|
|
17
13
|
|
|
18
14
|
## Bundling PDFs with the app
|
package/.babelrc
DELETED