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.
- package/PdfView.js +41 -13
- package/PinchZoomView.js +1 -1
- package/README.md +120 -87
- 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/build.gradle +10 -1
- package/android/src/main/java/org/wonday/pdf/PdfView.java +67 -9
- package/android/src/main/java/org/wonday/pdf/RCTPdfManager.java +5 -0
- package/index.d.ts +11 -3
- package/index.js +30 -40
- package/index.js.flow +6 -3
- package/ios/RCTPdf/RCTPdfView.h +3 -1
- package/ios/RCTPdf/RCTPdfView.m +124 -97
- package/ios/RCTPdf/RCTPdfViewManager.m +2 -1
- package/ios/RCTPdf.xcodeproj/xcuserdata/wonday.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/package.json +21 -6
- package/react-native-pdf.podspec +1 -1
- package/windows/RCTPdf/PropertySheet.props +16 -0
- package/windows/RCTPdf/RCTPdf.def +3 -0
- package/windows/RCTPdf/RCTPdf.vcxproj +180 -0
- package/windows/RCTPdf/RCTPdf.vcxproj.filters +38 -0
- package/windows/RCTPdf/RCTPdfControl.cpp +667 -0
- package/windows/RCTPdf/RCTPdfControl.h +119 -0
- package/windows/RCTPdf/RCTPdfControl.idl +10 -0
- package/windows/RCTPdf/RCTPdfControl.xaml +34 -0
- package/windows/RCTPdf/RCTPdfViewManager.cpp +69 -0
- package/windows/RCTPdf/RCTPdfViewManager.h +51 -0
- package/windows/RCTPdf/ReactPackageProvider.cpp +15 -0
- package/windows/RCTPdf/ReactPackageProvider.h +16 -0
- package/windows/RCTPdf/ReactPackageProvider.idl +9 -0
- package/windows/RCTPdf/packages.config +4 -0
- package/windows/RCTPdf/pch.cpp +1 -0
- package/windows/RCTPdf/pch.h +29 -0
- package/windows/README.md +21 -0
- package/.babelrc +0 -3
- package/example/.eslintrc.js +0 -4
- package/example/PDFExample.js +0 -176
- 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/metro.config.js +0 -17
- package/example/package.json +0 -42
- package/example/test.pdf +0 -0
- package/issue_template.md +0 -13
package/index.d.ts
CHANGED
|
@@ -9,6 +9,13 @@
|
|
|
9
9
|
import * as React from 'react';
|
|
10
10
|
import * as ReactNative from 'react-native';
|
|
11
11
|
|
|
12
|
+
export type TableContent = {
|
|
13
|
+
children: TableContent[],
|
|
14
|
+
mNativePtr: number,
|
|
15
|
+
pageIdx: number,
|
|
16
|
+
title: string,
|
|
17
|
+
};
|
|
18
|
+
|
|
12
19
|
interface Props {
|
|
13
20
|
style?: ReactNative.StyleProp<ReactNative.ViewStyle>,
|
|
14
21
|
source: object,
|
|
@@ -19,16 +26,16 @@ interface Props {
|
|
|
19
26
|
horizontal?: boolean,
|
|
20
27
|
spacing?: number,
|
|
21
28
|
password?: string,
|
|
22
|
-
|
|
23
|
-
activityIndicatorProps?: object,
|
|
29
|
+
renderActivityIndicator?: (progress: number) => React.ReactElement,
|
|
24
30
|
enableAntialiasing?: boolean,
|
|
25
31
|
enablePaging?: boolean,
|
|
26
32
|
enableRTL?: boolean,
|
|
27
33
|
enableAnnotationRendering?: boolean,
|
|
28
34
|
fitPolicy?: number,
|
|
29
35
|
trustAllCerts?: boolean,
|
|
36
|
+
singlePage?: boolean,
|
|
30
37
|
onLoadProgress?: (percent: number,) => void,
|
|
31
|
-
onLoadComplete?: (numberOfPages: number, path: string) => void,
|
|
38
|
+
onLoadComplete?: (numberOfPages: number, path: string, size: {height: number, width: number}, tableContents?: TableContent[]) => void,
|
|
32
39
|
onPageChanged?: (page: number, numberOfPages: number) => void,
|
|
33
40
|
onError?: (error: object) => void,
|
|
34
41
|
onPageSingleTap?: (page: number, x: number, y: number) => void,
|
|
@@ -37,6 +44,7 @@ interface Props {
|
|
|
37
44
|
}
|
|
38
45
|
|
|
39
46
|
declare class Pdf extends React.Component<Props, any> {
|
|
47
|
+
setPage: (pageNumber: number) => void;
|
|
40
48
|
}
|
|
41
49
|
|
|
42
50
|
export default Pdf;
|
package/index.js
CHANGED
|
@@ -15,13 +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
|
-
import RNFetchBlob from 'rn-fetch-blob';
|
|
22
|
+
import ReactNativeBlobUtil from 'react-native-blob-util'
|
|
25
23
|
|
|
26
24
|
const SHA1 = require('crypto-js/sha1');
|
|
27
25
|
import PdfView from './PdfView';
|
|
@@ -34,6 +32,7 @@ export default class Pdf extends Component {
|
|
|
34
32
|
PropTypes.shape({
|
|
35
33
|
uri: PropTypes.string,
|
|
36
34
|
cache: PropTypes.bool,
|
|
35
|
+
cacheFileName: PropTypes.string,
|
|
37
36
|
expiration: PropTypes.number,
|
|
38
37
|
}),
|
|
39
38
|
// Opaque type returned by require('./test.pdf')
|
|
@@ -46,15 +45,14 @@ export default class Pdf extends Component {
|
|
|
46
45
|
horizontal: PropTypes.bool,
|
|
47
46
|
spacing: PropTypes.number,
|
|
48
47
|
password: PropTypes.string,
|
|
49
|
-
|
|
50
|
-
activityIndicator: PropTypes.any,
|
|
51
|
-
activityIndicatorProps: PropTypes.any,
|
|
48
|
+
renderActivityIndicator: PropTypes.func,
|
|
52
49
|
enableAntialiasing: PropTypes.bool,
|
|
53
50
|
enableAnnotationRendering: PropTypes.bool,
|
|
54
51
|
enablePaging: PropTypes.bool,
|
|
55
52
|
enableRTL: PropTypes.bool,
|
|
56
53
|
fitPolicy: PropTypes.number,
|
|
57
54
|
trustAllCerts: PropTypes.bool,
|
|
55
|
+
singlePage: PropTypes.bool,
|
|
58
56
|
onLoadComplete: PropTypes.func,
|
|
59
57
|
onPageChanged: PropTypes.func,
|
|
60
58
|
onError: PropTypes.func,
|
|
@@ -85,9 +83,9 @@ export default class Pdf extends Component {
|
|
|
85
83
|
enableAnnotationRendering: true,
|
|
86
84
|
enablePaging: false,
|
|
87
85
|
enableRTL: false,
|
|
88
|
-
activityIndicatorProps: {color: '#009900', progressTintColor: '#009900'},
|
|
89
86
|
trustAllCerts: true,
|
|
90
87
|
usePDFKit: true,
|
|
88
|
+
singlePage: false,
|
|
91
89
|
onLoadProgress: (percent) => {
|
|
92
90
|
},
|
|
93
91
|
onLoadComplete: (numberOfPages, path) => {
|
|
@@ -164,16 +162,15 @@ export default class Pdf extends Component {
|
|
|
164
162
|
const source = Image.resolveAssetSource(newSource) || {};
|
|
165
163
|
|
|
166
164
|
let uri = source.uri || '';
|
|
167
|
-
|
|
168
165
|
// first set to initial state
|
|
169
166
|
if (this._mounted) {
|
|
170
167
|
this.setState({isDownloaded: false, path: '', progress: 0});
|
|
171
168
|
}
|
|
172
|
-
|
|
173
|
-
const cacheFile =
|
|
169
|
+
const filename = source.cacheFileName || SHA1(uri) + '.pdf';
|
|
170
|
+
const cacheFile = ReactNativeBlobUtil.fs.dirs.CacheDir + '/' + filename;
|
|
174
171
|
|
|
175
172
|
if (source.cache) {
|
|
176
|
-
|
|
173
|
+
ReactNativeBlobUtil.fs
|
|
177
174
|
.stat(cacheFile)
|
|
178
175
|
.then(stats => {
|
|
179
176
|
if (!Boolean(source.expiration) || (source.expiration * 1000 + stats.lastModified) > (new Date().getTime())) {
|
|
@@ -204,7 +201,8 @@ export default class Pdf extends Component {
|
|
|
204
201
|
const isAsset = !!(uri && uri.match(/^bundle-assets:\/\//));
|
|
205
202
|
const isBase64 = !!(uri && uri.match(/^data:application\/pdf;base64/));
|
|
206
203
|
|
|
207
|
-
const
|
|
204
|
+
const filename = source.cacheFileName || SHA1(uri) + '.pdf';
|
|
205
|
+
const cacheFile = ReactNativeBlobUtil.fs.dirs.CacheDir + '/' + filename;
|
|
208
206
|
|
|
209
207
|
// delete old cache file
|
|
210
208
|
this._unlinkFile(cacheFile);
|
|
@@ -212,7 +210,7 @@ export default class Pdf extends Component {
|
|
|
212
210
|
if (isNetwork) {
|
|
213
211
|
this._downloadFile(source, cacheFile);
|
|
214
212
|
} else if (isAsset) {
|
|
215
|
-
|
|
213
|
+
ReactNativeBlobUtil.fs
|
|
216
214
|
.cp(uri, cacheFile)
|
|
217
215
|
.then(() => {
|
|
218
216
|
if (this._mounted) {
|
|
@@ -225,7 +223,7 @@ export default class Pdf extends Component {
|
|
|
225
223
|
})
|
|
226
224
|
} else if (isBase64) {
|
|
227
225
|
let data = uri.replace(/data:application\/pdf;base64,/i, '');
|
|
228
|
-
|
|
226
|
+
ReactNativeBlobUtil.fs
|
|
229
227
|
.writeFile(cacheFile, data, 'base64')
|
|
230
228
|
.then(() => {
|
|
231
229
|
if (this._mounted) {
|
|
@@ -265,7 +263,7 @@ export default class Pdf extends Component {
|
|
|
265
263
|
const tempCacheFile = cacheFile + '.tmp';
|
|
266
264
|
this._unlinkFile(tempCacheFile);
|
|
267
265
|
|
|
268
|
-
this.lastRNBFTask =
|
|
266
|
+
this.lastRNBFTask = ReactNativeBlobUtil.config({
|
|
269
267
|
// response data will be saved to this path if it has access right.
|
|
270
268
|
path: tempCacheFile,
|
|
271
269
|
trusty: this.props.trustAllCerts,
|
|
@@ -280,7 +278,7 @@ export default class Pdf extends Component {
|
|
|
280
278
|
.progress((received, total) => {
|
|
281
279
|
this.props.onLoadProgress && this.props.onLoadProgress(received / total);
|
|
282
280
|
if (this._mounted) {
|
|
283
|
-
this.setState({progress: received / total});
|
|
281
|
+
this.setState({progress: Math.floor(received / total)});
|
|
284
282
|
}
|
|
285
283
|
});
|
|
286
284
|
|
|
@@ -294,7 +292,7 @@ export default class Pdf extends Component {
|
|
|
294
292
|
let actualContentLength;
|
|
295
293
|
|
|
296
294
|
try {
|
|
297
|
-
const fileStats = await
|
|
295
|
+
const fileStats = await ReactNativeBlobUtil.fs.stat(res.path());
|
|
298
296
|
|
|
299
297
|
if (!fileStats || !fileStats.size) {
|
|
300
298
|
throw new Error("FileNotFound:" + source.uri);
|
|
@@ -311,7 +309,7 @@ export default class Pdf extends Component {
|
|
|
311
309
|
}
|
|
312
310
|
|
|
313
311
|
this._unlinkFile(cacheFile);
|
|
314
|
-
|
|
312
|
+
ReactNativeBlobUtil.fs
|
|
315
313
|
.cp(tempCacheFile, cacheFile)
|
|
316
314
|
.then(() => {
|
|
317
315
|
if (this._mounted) {
|
|
@@ -333,7 +331,7 @@ export default class Pdf extends Component {
|
|
|
333
331
|
|
|
334
332
|
_unlinkFile = async (file) => {
|
|
335
333
|
try {
|
|
336
|
-
await
|
|
334
|
+
await ReactNativeBlobUtil.fs.unlink(file);
|
|
337
335
|
} catch (e) {
|
|
338
336
|
|
|
339
337
|
}
|
|
@@ -373,9 +371,9 @@ export default class Pdf extends Component {
|
|
|
373
371
|
} else if (message[0] === 'error') {
|
|
374
372
|
this._onError(new Error(message[1]));
|
|
375
373
|
} else if (message[0] === 'pageSingleTap') {
|
|
376
|
-
this.props.onPageSingleTap && this.props.onPageSingleTap(message[1], message[2], message[3]);
|
|
374
|
+
this.props.onPageSingleTap && this.props.onPageSingleTap(Number(message[1]), Number(message[2]), Number(message[3]));
|
|
377
375
|
} else if (message[0] === 'scaleChanged') {
|
|
378
|
-
this.props.onScaleChanged && this.props.onScaleChanged(message[1]);
|
|
376
|
+
this.props.onScaleChanged && this.props.onScaleChanged(Number(message[1]));
|
|
379
377
|
} else if (message[0] === 'linkPressed') {
|
|
380
378
|
this.props.onPressLink && this.props.onPressLink(message[1]);
|
|
381
379
|
}
|
|
@@ -390,30 +388,18 @@ export default class Pdf extends Component {
|
|
|
390
388
|
};
|
|
391
389
|
|
|
392
390
|
render() {
|
|
393
|
-
if (Platform.OS === "android" || Platform.OS === "ios") {
|
|
391
|
+
if (Platform.OS === "android" || Platform.OS === "ios" || Platform.OS === "windows") {
|
|
394
392
|
return (
|
|
395
393
|
<View style={[this.props.style,{overflow: 'hidden'}]}>
|
|
396
394
|
{!this.state.isDownloaded?
|
|
397
395
|
(<View
|
|
398
396
|
style={styles.progressContainer}
|
|
399
397
|
>
|
|
400
|
-
{this.props.
|
|
401
|
-
? this.props.
|
|
402
|
-
:
|
|
403
|
-
? <ProgressBar
|
|
404
|
-
progress={this.state.progress}
|
|
405
|
-
indeterminate={false}
|
|
406
|
-
styleAttr="Horizontal"
|
|
407
|
-
style={styles.progressBar}
|
|
408
|
-
{...this.props.activityIndicatorProps}
|
|
409
|
-
/>
|
|
410
|
-
: <ProgressView
|
|
411
|
-
progress={this.state.progress}
|
|
412
|
-
style={styles.progressBar}
|
|
413
|
-
{...this.props.activityIndicatorProps}
|
|
414
|
-
/>}
|
|
398
|
+
{this.props.renderActivityIndicator
|
|
399
|
+
? this.props.renderActivityIndicator(this.state.progress)
|
|
400
|
+
: <Text>{`${this.state.progress}%`}</Text>}
|
|
415
401
|
</View>):(
|
|
416
|
-
Platform.OS === "android"?(
|
|
402
|
+
Platform.OS === "android" || Platform.OS === "windows"?(
|
|
417
403
|
<PdfCustom
|
|
418
404
|
ref={component => (this._root = component)}
|
|
419
405
|
{...this.props}
|
|
@@ -461,6 +447,10 @@ if (Platform.OS === "android") {
|
|
|
461
447
|
var PdfCustom = requireNativeComponent('RCTPdfView', Pdf, {
|
|
462
448
|
nativeOnly: {path: true, onChange: true},
|
|
463
449
|
})
|
|
450
|
+
} else if (Platform.OS === "windows") {
|
|
451
|
+
var PdfCustom = requireNativeComponent('RCTPdf', Pdf, {
|
|
452
|
+
nativeOnly: {path: true, onChange: true},
|
|
453
|
+
})
|
|
464
454
|
}
|
|
465
455
|
|
|
466
456
|
|
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,
|
|
@@ -41,6 +41,7 @@ export type Props = {
|
|
|
41
41
|
horizontal?: boolean,
|
|
42
42
|
maxScale?: number,
|
|
43
43
|
minScale?: number,
|
|
44
|
+
singlePage?: boolean,
|
|
44
45
|
onError?: (error: Error) => void,
|
|
45
46
|
onLoadComplete?: (numberOfPages: number, path: string, size: { height: number, width: number }, tableContents: ?TableContent[]) => void,
|
|
46
47
|
onLoadProgress?: (percent: number) => void,
|
|
@@ -57,4 +58,6 @@ export type Props = {
|
|
|
57
58
|
testID?: string
|
|
58
59
|
};
|
|
59
60
|
|
|
60
|
-
declare export default class Pdf extends Component<Props> {
|
|
61
|
+
declare export default class Pdf extends Component<Props> {
|
|
62
|
+
setPage: (pageNumber: number) => void;
|
|
63
|
+
}
|
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;
|
|
@@ -34,7 +36,7 @@ NS_CLASS_AVAILABLE_IOS(11_0) @interface RCTPdfView : UIView <UIGestureRecognizer
|
|
|
34
36
|
@property(nonatomic) int fitPolicy;
|
|
35
37
|
@property(nonatomic) int spacing;
|
|
36
38
|
@property(nonatomic, strong) NSString *password;
|
|
37
|
-
|
|
39
|
+
@property(nonatomic) BOOL singlePage;
|
|
38
40
|
|
|
39
41
|
@property(nonatomic, copy) RCTBubblingEventBlock onChange;
|
|
40
42
|
|