react-native-pdf 6.2.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.
Files changed (93) hide show
  1. package/PdfView.js +41 -13
  2. package/PinchZoomView.js +1 -1
  3. package/README.md +120 -87
  4. package/android/.gradle/5.6.1/fileChanges/last-build.bin +0 -0
  5. package/android/.gradle/5.6.1/fileHashes/fileHashes.lock +0 -0
  6. package/android/.gradle/5.6.1/gc.properties +0 -0
  7. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  8. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  9. package/android/.gradle/vcs-1/gc.properties +0 -0
  10. package/android/build.gradle +10 -1
  11. package/android/src/main/java/org/wonday/pdf/PdfView.java +67 -9
  12. package/android/src/main/java/org/wonday/pdf/RCTPdfManager.java +5 -0
  13. package/index.d.ts +11 -3
  14. package/index.js +30 -40
  15. package/index.js.flow +6 -3
  16. package/ios/RCTPdf/RCTPdfView.h +3 -1
  17. package/ios/RCTPdf/RCTPdfView.m +124 -97
  18. package/ios/RCTPdf/RCTPdfViewManager.m +2 -1
  19. package/ios/RCTPdf.xcodeproj/xcuserdata/wonday.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  20. package/package.json +21 -6
  21. package/react-native-pdf.podspec +1 -1
  22. package/windows/RCTPdf/PropertySheet.props +16 -0
  23. package/windows/RCTPdf/RCTPdf.def +3 -0
  24. package/windows/RCTPdf/RCTPdf.vcxproj +180 -0
  25. package/windows/RCTPdf/RCTPdf.vcxproj.filters +38 -0
  26. package/windows/RCTPdf/RCTPdfControl.cpp +667 -0
  27. package/windows/RCTPdf/RCTPdfControl.h +119 -0
  28. package/windows/RCTPdf/RCTPdfControl.idl +10 -0
  29. package/windows/RCTPdf/RCTPdfControl.xaml +34 -0
  30. package/windows/RCTPdf/RCTPdfViewManager.cpp +69 -0
  31. package/windows/RCTPdf/RCTPdfViewManager.h +51 -0
  32. package/windows/RCTPdf/ReactPackageProvider.cpp +15 -0
  33. package/windows/RCTPdf/ReactPackageProvider.h +16 -0
  34. package/windows/RCTPdf/ReactPackageProvider.idl +9 -0
  35. package/windows/RCTPdf/packages.config +4 -0
  36. package/windows/RCTPdf/pch.cpp +1 -0
  37. package/windows/RCTPdf/pch.h +29 -0
  38. package/windows/README.md +21 -0
  39. package/.babelrc +0 -3
  40. package/example/.eslintrc.js +0 -4
  41. package/example/PDFExample.js +0 -176
  42. package/example/android/app/BUCK +0 -55
  43. package/example/android/app/build.gradle +0 -210
  44. package/example/android/app/build_defs.bzl +0 -19
  45. package/example/android/app/proguard-rules.pro +0 -10
  46. package/example/android/app/src/debug/AndroidManifest.xml +0 -8
  47. package/example/android/app/src/main/AndroidManifest.xml +0 -26
  48. package/example/android/app/src/main/assets/test.pdf +0 -0
  49. package/example/android/app/src/main/java/com/pdfexample/MainActivity.java +0 -15
  50. package/example/android/app/src/main/java/com/pdfexample/MainApplication.java +0 -49
  51. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  52. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  53. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  54. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  55. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  56. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  57. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  58. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  59. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  60. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  61. package/example/android/app/src/main/res/values/strings.xml +0 -3
  62. package/example/android/app/src/main/res/values/styles.xml +0 -9
  63. package/example/android/build.gradle +0 -38
  64. package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  65. package/example/android/gradle/wrapper/gradle-wrapper.properties +0 -5
  66. package/example/android/gradle.properties +0 -21
  67. package/example/android/gradlew +0 -188
  68. package/example/android/gradlew.bat +0 -100
  69. package/example/android/settings.gradle +0 -3
  70. package/example/app.json +0 -4
  71. package/example/babel.config.js +0 -3
  72. package/example/index.js +0 -9
  73. package/example/ios/PDFExample/AppDelegate.h +0 -15
  74. package/example/ios/PDFExample/AppDelegate.m +0 -42
  75. package/example/ios/PDFExample/Base.lproj/LaunchScreen.xib +0 -42
  76. package/example/ios/PDFExample/Images.xcassets/AppIcon.appiconset/Contents.json +0 -38
  77. package/example/ios/PDFExample/Images.xcassets/Contents.json +0 -6
  78. package/example/ios/PDFExample/Info.plist +0 -57
  79. package/example/ios/PDFExample/main.m +0 -16
  80. package/example/ios/PDFExample-tvOS/Info.plist +0 -53
  81. package/example/ios/PDFExample-tvOSTests/Info.plist +0 -24
  82. package/example/ios/PDFExample.xcodeproj/project.pbxproj +0 -923
  83. package/example/ios/PDFExample.xcodeproj/xcshareddata/xcschemes/PDFExample-tvOS.xcscheme +0 -129
  84. package/example/ios/PDFExample.xcodeproj/xcshareddata/xcschemes/PDFExample.xcscheme +0 -129
  85. package/example/ios/PDFExample.xcworkspace/contents.xcworkspacedata +0 -10
  86. package/example/ios/PDFExampleTests/Info.plist +0 -24
  87. package/example/ios/PDFExampleTests/PDFExampleTests.m +0 -68
  88. package/example/ios/Podfile +0 -47
  89. package/example/ios/Podfile.lock +0 -205
  90. package/example/metro.config.js +0 -17
  91. package/example/package.json +0 -42
  92. package/example/test.pdf +0 -0
  93. package/issue_template.md +0 -13
package/PdfView.js CHANGED
@@ -37,6 +37,7 @@ export default class PdfView extends Component {
37
37
  horizontal: PropTypes.bool,
38
38
  page: PropTypes.number,
39
39
  currentPage: PropTypes.number,
40
+ singlePage: PropTypes.bool,
40
41
  onPageSingleTap: PropTypes.func,
41
42
  onScaleChanged: PropTypes.func,
42
43
  };
@@ -55,6 +56,7 @@ export default class PdfView extends Component {
55
56
  page: 1,
56
57
  currentPage: -1,
57
58
  enablePaging: false,
59
+ singlePage: false,
58
60
  onPageSingleTap: (page, x, y) => {
59
61
  },
60
62
  onScaleChanged: (scale) => {
@@ -160,7 +162,7 @@ export default class PdfView extends Component {
160
162
  let fitPolicy = this.props.fitPolicy;
161
163
 
162
164
  // if only one page, show whole page in center
163
- if (this.state.numberOfPages === 1) {
165
+ if (this.state.numberOfPages === 1 || this.props.singlePage) {
164
166
  fitPolicy = 2;
165
167
  }
166
168
 
@@ -187,7 +189,7 @@ export default class PdfView extends Component {
187
189
  let fitPolicy = this.props.fitPolicy;
188
190
 
189
191
  // if only one page, show whole page in center
190
- if (this.state.numberOfPages === 1) {
192
+ if (this.state.numberOfPages === 1 || this.props.singlePage) {
191
193
  fitPolicy = 2;
192
194
  }
193
195
 
@@ -257,6 +259,24 @@ export default class PdfView extends Component {
257
259
  };
258
260
 
259
261
  _renderItem = ({item, index}) => {
262
+ const pageView = (
263
+ <PdfPageView
264
+ accessible={true}
265
+ key={item.id}
266
+ fileNo={this.state.fileNo}
267
+ page={item.key + 1}
268
+ width={this._getPageWidth()}
269
+ height={this._getPageHeight()}
270
+ />
271
+ )
272
+
273
+ if (this.props.singlePage) {
274
+ return (
275
+ <View style={{flexDirection: this.props.horizontal ? 'row' : 'column'}} >
276
+ {pageView}
277
+ </View>
278
+ )
279
+ }
260
280
 
261
281
  return (
262
282
  <DoubleTapView style={{flexDirection: this.props.horizontal ? 'row' : 'column'}}
@@ -267,14 +287,7 @@ export default class PdfView extends Component {
267
287
  this._onItemDoubleTap(index);
268
288
  }}
269
289
  >
270
- <PdfPageView
271
- accessible={true}
272
- key={item.id}
273
- fileNo={this.state.fileNo}
274
- page={item.key + 1}
275
- width={this._getPageWidth()}
276
- height={this._getPageHeight()}
277
- />
290
+ {pageView}
278
291
  {(index !== this.state.numberOfPages - 1) && this._renderSeparator()}
279
292
  </DoubleTapView>
280
293
  );
@@ -318,10 +331,14 @@ export default class PdfView extends Component {
318
331
  };
319
332
 
320
333
  _renderList = () => {
321
-
322
334
  let data = [];
323
- for (let i = 0; i < this.state.numberOfPages; i++) {
324
- data[i] = {key: i};
335
+
336
+ if (this.props.singlePage) {
337
+ data[0] = {key: this.props.currentPage >= 0 ? this.props.currentPage : 0}
338
+ } else {
339
+ for (let i = 0; i < this.state.numberOfPages; i++) {
340
+ data[i] = {key: i};
341
+ }
325
342
  }
326
343
 
327
344
  return (
@@ -350,6 +367,7 @@ export default class PdfView extends Component {
350
367
  viewabilityConfig={VIEWABILITYCONFIG}
351
368
  onScroll={this._onScroll}
352
369
  onContentSizeChange={this._onListContentSizeChange}
370
+ scrollEnabled={!this.props.singlePage}
353
371
  />
354
372
  );
355
373
 
@@ -366,6 +384,16 @@ export default class PdfView extends Component {
366
384
 
367
385
 
368
386
  render() {
387
+ if (this.props.singlePage) {
388
+ return (
389
+ <View
390
+ style={styles.container}
391
+ onLayout={this._onLayout}
392
+ >
393
+ {this.state.pdfLoaded && this._renderList()}
394
+ </View>
395
+ )
396
+ }
369
397
 
370
398
  return (
371
399
  <PinchZoomView
package/PinchZoomView.js CHANGED
@@ -108,7 +108,7 @@ export default class PinchZoomView extends Component {
108
108
  return (
109
109
  <View
110
110
  {...this.props}
111
- {...this.gestureHandlers.panHandlers}
111
+ {...this.gestureHandlers?.panHandlers}
112
112
  style={[styles.container, this.props.style]}>
113
113
  {this.props.children}
114
114
  </View>
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/local file/asset and can cache it.
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,24 +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 [`rn-fetch-blob`](https://github.com/joltup/rn-fetch-blob) to handle file system access in this package,
17
- So you should install react-native-pdf and rn-fetch-blob
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 rn-fetch-blob for different versions of `react-native-pdf`.
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
- | rn-fetch-blob | 0.10.15 | 0.10.15 | 0.11.0+ | 0.11.0+ |
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+ |
25
25
 
26
26
  ### Installation
27
27
 
28
28
  ```bash
29
29
  # Using npm
30
- npm install react-native-pdf rn-fetch-blob --save
30
+ npm install react-native-pdf react-native-blob-util fbjs --save
31
31
 
32
32
  # or using yarn:
33
- yarn add react-native-pdf rn-fetch-blob
33
+ yarn add react-native-pdf react-native-blob-util fbjs
34
34
  ```
35
35
 
36
36
  Then follow the instructions for your platform to link react-native-pdf into your project:
@@ -46,7 +46,7 @@ Run `pod install` in the `ios` directory. Linking is not required in React Nativ
46
46
  **React Native 0.59 and below**
47
47
 
48
48
  ```bash
49
- react-native link rn-fetch-blob
49
+ react-native link react-native-blob-util
50
50
  react-native link react-native-pdf
51
51
  ```
52
52
  </details>
@@ -73,13 +73,40 @@ android {
73
73
 
74
74
  **React Native 0.59.0 and below**
75
75
  ```bash
76
- react-native link rn-fetch-blob
76
+ react-native link react-native-blob-util
77
77
  react-native link react-native-pdf
78
78
  ```
79
79
 
80
80
 
81
81
  </details>
82
82
 
83
+ ### Windows installation
84
+ <details>
85
+ <sumary>Windows details</summary>
86
+
87
+ - Open your solution in Visual Studio 2019 (eg. `windows\yourapp.sln`)
88
+ - Right-click Solution icon in Solution Explorer > Add > Existing Project...
89
+ - If running RNW 0.62: add `node_modules\react-native-pdf\windows\RCTPdf\RCTPdf.vcxproj`
90
+ - If running RNW 0.62: add `node_modules\react-native-blob-util\windows\ReactNativeBlobUtil\ReactNativeBlobUtil.vcxproj`
91
+ - Right-click main application project > Add > Reference...
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"`
96
+ - In `App.cpp` add `PackageProviders().Append(winrt::progress_view::ReactPackageProvider());` before `InitializeComponent();`
97
+ - If running RNW 0.62, also add `PackageProviders().Append(winrt::RCTPdf::ReactPackageProvider());` and `PackageProviders().Append(winrt::ReactNativeBlobUtil::ReactPackageProvider());`
98
+
99
+
100
+ #### Bundling PDFs with the app
101
+ To add a `test.pdf` like in the example add:
102
+ ```
103
+ <None Include="..\..\test.pdf">
104
+ <DeploymentContent>true</DeploymentContent>
105
+ </None>
106
+ ```
107
+ in the app `.vcxproj` file, before `<None Include="packages.config" />`.
108
+ </details>
109
+
83
110
  ### FAQ
84
111
  <details>
85
112
  <summary>FAQ details</summary>
@@ -139,6 +166,27 @@ react-native run-ios
139
166
  <details>
140
167
  <summary>ChangeLog details</summary>
141
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
+
176
+ v6.3.0
177
+ 1. Add windows support
178
+ 2. Fixed some bugs
179
+
180
+ v6.2.2
181
+ 1. Fixed incorrect type of onPageSingleTap and onScaleChanged argument
182
+ 2. Fixed included missing setPage method in TypeScript and Flow types
183
+ 3. fixed Xcode 12 compatibility
184
+
185
+ v6.2.1
186
+ 1. Fixed typescript `onLoadComplete()` definition
187
+ 2. Switched the AndroidPdfViewer dependency from Barteksc repo to TalbotGooday
188
+ 3. Add singlePage property
189
+
142
190
  v6.2.0
143
191
  1. Fixed ReferenceError, url should be source.uri
144
192
  2. Dependency bump to support React-Native >= 0.62
@@ -164,25 +212,6 @@ v6.0.0
164
212
  1. Add JS callback onPressLink for pdf link press listener
165
213
  2. Fix calling setState while unmounted
166
214
 
167
- v5.1.7
168
- 1. Downgraded to AndroidPdfViewer 3.1.0-beta.1
169
-
170
- v5.1.6
171
- 1. Fixed componentWillReceiveProps and componentWillMount warnings
172
-
173
- v5.1.5
174
- 1. Added setPage() method
175
- 2. Upgraded to AndroidPdfViewer to 3.2.0-beta.1
176
- 3. Fixed some codes ,readme and sample
177
-
178
- v5.1.4
179
- 1. Updated example project to RN 0.60.4
180
- 2. Fixed blank view after native module got recycled in onDetachedFromWindow event
181
- 3. Restore singleTap, only callback, do not change scale
182
-
183
- v5.1.3
184
- 1. Removed singleTap action from iOS, make the same with Android.
185
-
186
215
 
187
216
  [[more]](https://github.com/wonday/react-native-pdf/releases)
188
217
 
@@ -201,38 +230,38 @@ v5.1.3
201
230
 
202
231
  import React from 'react';
203
232
  import { StyleSheet, Dimensions, View } from 'react-native';
204
-
205
233
  import Pdf from 'react-native-pdf';
206
234
 
207
235
  export default class PDFExample extends React.Component {
208
236
  render() {
209
- 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 };
210
238
  //const source = require('./test.pdf'); // ios only
211
- //const source = {uri:'bundle-assets://test.pdf'};
212
-
239
+ //const source = {uri:'bundle-assets://test.pdf' };
213
240
  //const source = {uri:'file:///sdcard/test.pdf'};
214
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"};
215
244
 
216
245
  return (
217
246
  <View style={styles.container}>
218
247
  <Pdf
219
248
  source={source}
220
- onLoadComplete={(numberOfPages,filePath)=>{
221
- console.log(`number of pages: ${numberOfPages}`);
249
+ onLoadComplete={(numberOfPages,filePath) => {
250
+ console.log(`Number of pages: ${numberOfPages}`);
222
251
  }}
223
- onPageChanged={(page,numberOfPages)=>{
224
- console.log(`current page: ${page}`);
252
+ onPageChanged={(page,numberOfPages) => {
253
+ console.log(`Current page: ${page}`);
225
254
  }}
226
- onError={(error)=>{
255
+ onError={(error) => {
227
256
  console.log(error);
228
257
  }}
229
- onPressLink={(uri)=>{
230
- console.log(`Link presse: ${uri}`)
258
+ onPressLink={(uri) => {
259
+ console.log(`Link pressed: ${uri}`);
231
260
  }}
232
261
  style={styles.pdf}/>
233
262
  </View>
234
263
  )
235
- }
264
+ }
236
265
  }
237
266
 
238
267
  const styles = StyleSheet.create({
@@ -254,56 +283,60 @@ const styles = StyleSheet.create({
254
283
 
255
284
  ### Configuration
256
285
 
257
- | Property | Type | Default | Description | iOS | Android | FirstRelease |
258
- | ------------- |:-------------:|:----------------:| ------------------- | ------| ------- | ------------ |
259
- | source | object | not null | PDF source like {uri:xxx, cache:false}. see the following for detail.| ✔ | ✔ | <3.0 |
260
- | page | number | 1 | initial page index | ✔ | ✔ | <3.0 |
261
- | scale | number | 1.0 | should minScale<=scale<=maxScale| ✔ | ✔ | <3.0 |
262
- | minScale | number | 1.0 | min scale| ✔ | ✔ | 5.0.5 |
263
- | maxScale | number | 3.0 | max scale| ✔ | ✔ | 5.0.5 |
264
- | horizontal | bool | false | draw page direction, if you want to listen the orientation change, you can use [[react-native-orientation-locker]](https://github.com/wonday/react-native-orientation-locker)| ✔ | ✔ | <3.0 |
265
- | fitWidth | bool | false | if true fit the width of view, can not use fitWidth=true together with scale| ✔ | ✔ | <3.0, abandoned from 3.0 |
266
- | fitPolicy | number | 2 | 0:fit width, 1:fit height, 2:fit both(default)| ✔ | ✔ | 3.0 |
267
- | spacing | number | 10 | the breaker size between pages| ✔ | ✔ | <3.0 |
268
- | password | string | "" | pdf password, if password error, will call OnError() with message "Password required or incorrect password." | ✔ | ✔ | <3.0 |
269
- | style | object | {backgroundColor:"#eee"} | support normal view style, you can use this to set border/spacing color... | ✔ | ✔ | <3.0 |
270
- | activityIndicator | Component | <ProgressBar/> | when loading show it as an indicator, you can use your component| ✔ | ✔ | <3.0 |
271
- | activityIndicatorProps | object | {color:'#009900', progressTintColor:'#009900'} | activityIndicator props | ✔ | | 3.1 |
272
- | 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 |
273
- | enablePaging | bool | false | only show one page in screen | ✔ | ✔ | 5.0.1 |
274
- | enableRTL | bool | false | scroll page as "page3, page2, page1" | ✔ | ✖ | 5.0.1 |
275
- | enableAnnotationRendering | bool | true | enable rendering annotation, notice:iOS only support initial setting,not support realtime changing | ✔ | ✔ | 5.0.3 |
276
- | trustAllCerts | bool | true | Allow connections to servers with self-signed certification | ✔ | ✔ | 6.0.? |
277
- | onLoadProgress | function(percent) | null | callback when loading, return loading progress (0-1) | ✔ | ✔ | <3.0 |
278
- | 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 | ✔ | ✔ | <3.0 |
279
- | onPageChanged | function(page,numberOfPages) | null | callback when page changed ,return current page and total page count | ✔ | ✔ | <3.0 |
280
- | onError | function(error) | null | callback when error happened | ✔ | ✔ | <3.0 |
281
- | onPageSingleTap | function(page) | null | callback when page was single tapped | ✔ | ✔ | 3.0 |
282
- | onScaleChanged | function(scale) | null | callback when scale page | ✔ | ✔ | 3.0 |
283
- | onPressLink | function(uri) | null | callback when link tapped | ✔ | ✔ | 6.0.0 |
286
+ | Property | Type | Default | Description | iOS | Android | Windows | FirstRelease |
287
+ | ------------- |:-------------:|:----------------:| ------------------- | ------| ------- | ------- | ------------ |
288
+ | source | object | not null | PDF source like {uri:xxx, cache:false}. see the following for detail.| ✔ | ✔ | ✔ | <3.0 |
289
+ | page | number | 1 | initial page index | ✔ | ✔ | ✔ | <3.0 |
290
+ | scale | number | 1.0 | should minScale<=scale<=maxScale| ✔ | ✔ | ✔ | <3.0 |
291
+ | minScale | number | 1.0 | min scale| ✔ | ✔ | ✔ | 5.0.5 |
292
+ | maxScale | number | 3.0 | max scale| ✔ | ✔ | ✔ | 5.0.5 |
293
+ | horizontal | bool | false | draw page direction, if you want to listen the orientation change, you can use [[react-native-orientation-locker]](https://github.com/wonday/react-native-orientation-locker)| ✔ | ✔ | ✔ | <3.0 |
294
+ | fitWidth | bool | false | if true fit the width of view, can not use fitWidth=true together with scale| ✔ | ✔ | ✔ | <3.0, abandoned from 3.0 |
295
+ | fitPolicy | number | 2 | 0:fit width, 1:fit height, 2:fit both(default)| ✔ | ✔ | ✔ | 3.0 |
296
+ | spacing | number | 10 | the breaker size between pages| ✔ | ✔ | ✔ | <3.0 |
297
+ | password | string | "" | pdf password, if password error, will call OnError() with message "Password required or incorrect password." | ✔ | ✔ | ✔ | <3.0 |
298
+ | style | object | {backgroundColor:"#eee"} | support normal view style, you can use this to set border/spacing color... | ✔ | ✔ | ✔ | <3.0 |
299
+ | renderActivityIndicator | (progress) => Component | <ProgressBar/> | when loading show it as an indicator, you can use your component| ✔ | ✔ | ✖ | <3.0 |
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 |
301
+ | enablePaging | bool | false | only show one page in screen | | | ✔ | 5.0.1 |
302
+ | enableRTL | bool | false | scroll page as "page3, page2, page1" | ✔ | | ✔ | 5.0.1 |
303
+ | enableAnnotationRendering | bool | true | enable rendering annotation, notice:iOS only support initial setting,not support realtime changing | ✔ | ✔ | ✖ | 5.0.3 |
304
+ | trustAllCerts | bool | true | Allow connections to servers with self-signed certification | ✔ | ✔ | ✖ | 6.0.? |
305
+ | singlePage | bool | false | Only show first page, useful for thumbnail views | ✔ | ✔ | ✔ | 6.2.1 |
306
+ | onLoadProgress | function(percent) | null | callback when loading, return loading progress (0-1) | ✔ | ✔ | ✖ | <3.0 |
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 |
308
+ | onPageChanged | function(page,numberOfPages) | null | callback when page changed ,return current page and total page count | ✔ | ✔ | ✔ | <3.0 |
309
+ | onError | function(error) | null | callback when error happened | ✔ | ✔ | ✔ | <3.0 |
310
+ | onPageSingleTap | function(page) | null | callback when page was single tapped | ✔ | ✔ | ✔ | 3.0 |
311
+ | onScaleChanged | function(scale) | null | callback when scale page | ✔ | ✔ | ✔ | 3.0 |
312
+ | onPressLink | function(uri) | null | callback when link tapped | ✔ | ✔ | ✖ | 6.0.0 |
284
313
 
285
314
  #### parameters of source
286
315
 
287
- | parameter | Description | default | iOS | Android |
288
- | ------------ | ----------- | ------- | --- | ------- |
289
- | uri | pdf source, see the forllowing for detail.| required | ✔ | ✔ |
290
- | cache | use cache or not | false | ✔ | ✔ |
291
- | expiration | cache file expired seconds (0 is not expired) | 0 | ✔ | |
292
- | method | request method when uri is a url | "GET" | ✔ | ✔ |
293
- | headers | request headers when uri is a url | {} | ✔ | ✔ |
316
+ | parameter | Description | default | iOS | Android | Windows |
317
+ | ------------ | ----------- | ------- | --- | ------- | ------- |
318
+ | uri | pdf source, see the forllowing for detail.| required | ✔ | ✔ | ✔ |
319
+ | cache | use cache or not | false | ✔ | ✔ | ✖ |
320
+ | cacheFileName | specific file name for cached pdf file | SHA1(uri) result | | ✔ | |
321
+ | expiration | cache file expired seconds (0 is not expired) | 0 | ✔ | ✔ | ✖ |
322
+ | method | request method when uri is a url | "GET" | ✔ | ✔ | ✖ |
323
+ | headers | request headers when uri is a url | {} | ✔ | ✔ | ✖ |
294
324
 
295
325
  #### types of source.uri
296
326
 
297
- | Usage | Description | iOS | Android |
298
- | ------------ | ----------- | --- | ------- |
299
- | `{uri:"http://xxx/xxx.pdf"}` | load pdf from a url | ✔ | ✔ |
300
- | `{require("./test.pdf")}` | load pdf relate to js file (do not need add by xcode) | ✔ | ✖ |
301
- | `{uri:"bundle-assets://path/to/xxx.pdf"}` | load pdf from assets, the file should be at android/app/src/main/assets/path/to/xxx.pdf | ✖ | ✔ |
302
- | `{uri:"bundle-assets://xxx.pdf"}` | load pdf from assets, you must add pdf to project by xcode. this does not support folder. | ✔ | ✖ |
303
- | `{uri:"data:application/pdf;base64,JVBERi0xLjcKJc..."}` | load pdf from base64 string | ✔ | ✔ |
304
- | `{uri:"file:///absolute/path/to/xxx.pdf"}` | load pdf from local file system | ✔ | ✔ |
305
-
306
-
327
+ | Usage | Description | iOS | Android | Windows |
328
+ | ------------ | ----------- | --- | ------- | ------- |
329
+ | `{uri:"http://xxx/xxx.pdf"}` | load pdf from a url | ✔ | ✔ | ✔ |
330
+ | `{require("./test.pdf")}` | load pdf relate to js file (do not need add by xcode) | ✔ | ✖ | ✖ |
331
+ | `{uri:"bundle-assets://path/to/xxx.pdf"}` | load pdf from assets, the file should be at android/app/src/main/assets/path/to/xxx.pdf | ✖ | ✔ | ✖ |
332
+ | `{uri:"bundle-assets://xxx.pdf"}` | load pdf from assets, you must add pdf to project by xcode. this does not support folder. | ✔ | ✖ | ✖ |
333
+ | `{uri:"data:application/pdf;base64,JVBERi0xLjcKJc..."}` | load pdf from base64 string | ✔ | ✔ | ✔ |
334
+ | `{uri:"file:///absolute/path/to/xxx.pdf"}` | load pdf from local file system | ✔ | ✔ | ✔ |
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 | ✖ | ✔ | ✖ |
338
+
339
+ \*) requires building React Native from source with [this patch](https://github.com/facebook/react-native/pull/31789)
307
340
  ### Methods
308
341
  * [setPage](#setPage)
309
342
 
File without changes
@@ -0,0 +1,2 @@
1
+ #Sat Oct 12 21:44:37 CST 2019
2
+ gradle.version=5.6.1
File without changes
@@ -13,6 +13,13 @@ buildscript {
13
13
 
14
14
  repositories {
15
15
  jcenter()
16
+ maven {
17
+ url 'https://jitpack.io'
18
+ content {
19
+ // Use Jitpack only for AndroidPdfViewer; the rest is hosted at jcenter.
20
+ includeGroup "com.github.TalbotGooday"
21
+ }
22
+ }
16
23
  }
17
24
 
18
25
  apply plugin: 'com.android.library'
@@ -52,6 +59,8 @@ android {
52
59
 
53
60
  dependencies {
54
61
  implementation "com.facebook.react:react-native:${_reactNativeVersion}"
55
- implementation 'com.github.barteksc:android-pdf-viewer:3.1.0-beta.1'
62
+ // NOTE: The original repo at com.github.barteksc is abandoned by the maintainer; there will be no more updates coming from that repo.
63
+ // It was taken over by com.github.TalbotGooday; from now on please use this repo until (if ever) the Barteksc repo is resumed.
64
+ implementation 'com.github.TalbotGooday:AndroidPdfViewer:3.1.0-beta.3'
56
65
  implementation 'com.google.code.gson:gson:2.8.5'
57
66
  }
@@ -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,11 +50,15 @@ 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;
55
59
  import com.google.gson.Gson;
56
60
  import com.google.gson.GsonBuilder;
61
+ import com.shockwave.pdfium.util.SizeF;
57
62
 
58
63
  public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompleteListener,OnErrorListener,OnTapListener,OnDrawListener,OnPageScrollListener, LinkHandler {
59
64
  private ThemedReactContext context;
@@ -74,6 +79,7 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
74
79
  private boolean pageFling = false;
75
80
  private boolean pageSnap = false;
76
81
  private FitPolicy fitPolicy = FitPolicy.WIDTH;
82
+ private boolean singlePage = false;
77
83
 
78
84
  private static PdfView instance = null;
79
85
 
@@ -106,14 +112,14 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
106
112
 
107
113
  @Override
108
114
  public void loadComplete(int numberOfPages) {
109
-
110
- float width = this.getWidth();
111
- float height = this.getHeight();
115
+ SizeF pageSize = getPageSize(0);
116
+ float width = pageSize.getWidth();
117
+ float height = pageSize.getHeight();
112
118
 
113
119
  this.zoomTo(this.scale);
114
120
  WritableMap event = Arguments.createMap();
115
121
 
116
- //create a new jason Object for the TableofContents
122
+ //create a new json Object for the TableOfContents
117
123
  Gson gson = new Gson();
118
124
  event.putString("message", "loadComplete|"+numberOfPages+"|"+width+"|"+height+"|"+gson.toJson(this.getTableOfContents()));
119
125
  ReactContext reactContext = (ReactContext)this.getContext();
@@ -220,13 +226,27 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
220
226
  Constants.Pinch.MINIMUM_ZOOM = this.minScale;
221
227
  Constants.Pinch.MAXIMUM_ZOOM = this.maxScale;
222
228
 
223
- this.fromUri(getURI(this.path))
224
- .defaultPage(this.page-1)
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)
225
246
  .swipeHorizontal(this.horizontal)
226
247
  .onPageChange(this)
227
248
  .onLoad(this)
228
249
  .onError(this)
229
- .onTap(this)
230
250
  .onDraw(this)
231
251
  .onPageScroll(this)
232
252
  .spacing(this.spacing)
@@ -236,10 +256,19 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
236
256
  .pageSnap(this.pageSnap)
237
257
  .autoSpacing(this.autoSpacing)
238
258
  .pageFling(this.pageFling)
259
+ .enableSwipe(!this.singlePage)
260
+ .enableDoubletap(!this.singlePage)
239
261
  .enableAnnotationRendering(this.enableAnnotationRendering)
240
- .linkHandler(this)
241
- .load();
262
+ .linkHandler(this);
242
263
 
264
+ if (this.singlePage) {
265
+ configurator.pages(this.page-1);
266
+ setTouchesEnabled(false);
267
+ } else {
268
+ configurator.onTap(this);
269
+ }
270
+
271
+ configurator.load();
243
272
  }
244
273
  }
245
274
 
@@ -315,6 +344,10 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
315
344
 
316
345
  }
317
346
 
347
+ public void setSinglePage(boolean singlePage) {
348
+ this.singlePage = singlePage;
349
+ }
350
+
318
351
  /**
319
352
  * @see https://github.com/barteksc/AndroidPdfViewer/blob/master/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/link/DefaultLinkHandler.java
320
353
  */
@@ -362,4 +395,29 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
362
395
  }
363
396
  return parsed;
364
397
  }
398
+
399
+ private void setTouchesEnabled(final boolean enabled) {
400
+ setTouchesEnabled(this, enabled);
401
+ }
402
+
403
+ private static void setTouchesEnabled(View v, final boolean enabled) {
404
+ if (enabled) {
405
+ v.setOnTouchListener(null);
406
+ } else {
407
+ v.setOnTouchListener(new View.OnTouchListener() {
408
+ @Override
409
+ public boolean onTouch(View v, MotionEvent event) {
410
+ return true;
411
+ }
412
+ });
413
+ }
414
+
415
+ if (v instanceof ViewGroup) {
416
+ ViewGroup vg = (ViewGroup) v;
417
+ for (int i = 0; i < vg.getChildCount(); i++) {
418
+ View child = vg.getChildAt(i);
419
+ setTouchesEnabled(child, enabled);
420
+ }
421
+ }
422
+ }
365
423
  }
@@ -120,6 +120,11 @@ public class RCTPdfManager extends SimpleViewManager<PdfView> {
120
120
  pdfView.setFitPolicy(fitPolicy);
121
121
  }
122
122
 
123
+ @ReactProp(name = "singlePage")
124
+ public void setSinglePage(PdfView pdfView, boolean singlePage) {
125
+ pdfView.setSinglePage(singlePage);
126
+ }
127
+
123
128
  @Override
124
129
  public void onAfterUpdateTransaction(PdfView pdfView) {
125
130
  super.onAfterUpdateTransaction(pdfView);