@react-native-ohos/react-native-pdf 6.7.7-rc.1 → 6.8.0-rc.2
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 +417 -417
- package/README.md +1 -1
- package/fabric/RNPDFPdfNativeComponent.js +48 -48
- package/harmony/pdfview/BuildProfile.ets +16 -16
- package/harmony/pdfview/oh-package.json5 +1 -1
- package/harmony/pdfview/src/main/ets/components/mainpage/RTNPdfView.ets +1 -0
- package/harmony/pdfview.har +0 -0
- package/index.d.ts +72 -72
- package/index.js +491 -491
- package/index.js.flow +67 -67
- package/package.json +57 -61
- package/harmony/pdfview/oh-package-lock.json5 +0 -18
package/index.js
CHANGED
|
@@ -1,491 +1,491 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2017-present, Wonday (@wonday.org)
|
|
3
|
-
* All rights reserved.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT-style license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
'use strict';
|
|
10
|
-
import React, { Component } from 'react';
|
|
11
|
-
import PropTypes from 'prop-types';
|
|
12
|
-
import {
|
|
13
|
-
View,
|
|
14
|
-
Platform,
|
|
15
|
-
StyleSheet,
|
|
16
|
-
Image,
|
|
17
|
-
Text,
|
|
18
|
-
requireNativeComponent
|
|
19
|
-
} from 'react-native';
|
|
20
|
-
import PdfViewNativeComponent, {
|
|
21
|
-
Commands as PdfViewCommands,
|
|
22
|
-
} from './fabric/RNPDFPdfNativeComponent';
|
|
23
|
-
// import ReactNativeBlobUtil from 'react-native-blob-util';
|
|
24
|
-
import RNPDFPdfView, { Commands as RNPDFCommands } from "./fabric/RTNPdfViewNativeComponent";
|
|
25
|
-
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
|
|
26
|
-
const SHA1 = require('crypto-js/sha1');
|
|
27
|
-
import PdfView from './PdfView';
|
|
28
|
-
|
|
29
|
-
export default class Pdf extends Component {
|
|
30
|
-
|
|
31
|
-
static propTypes = {
|
|
32
|
-
...ViewPropTypes,
|
|
33
|
-
source: PropTypes.oneOfType([
|
|
34
|
-
PropTypes.shape({
|
|
35
|
-
uri: PropTypes.string,
|
|
36
|
-
cache: PropTypes.bool,
|
|
37
|
-
cacheFileName: PropTypes.string,
|
|
38
|
-
expiration: PropTypes.number,
|
|
39
|
-
}),
|
|
40
|
-
// Opaque type returned by require('./test.pdf')
|
|
41
|
-
PropTypes.number,
|
|
42
|
-
]).isRequired,
|
|
43
|
-
page: PropTypes.number,
|
|
44
|
-
scale: PropTypes.number,
|
|
45
|
-
minScale: PropTypes.number,
|
|
46
|
-
maxScale: PropTypes.number,
|
|
47
|
-
horizontal: PropTypes.bool,
|
|
48
|
-
spacing: PropTypes.number,
|
|
49
|
-
password: PropTypes.string,
|
|
50
|
-
renderActivityIndicator: PropTypes.func,
|
|
51
|
-
enableAntialiasing: PropTypes.bool,
|
|
52
|
-
enableAnnotationRendering: PropTypes.bool,
|
|
53
|
-
showsHorizontalScrollIndicator: PropTypes.bool,
|
|
54
|
-
showsVerticalScrollIndicator: PropTypes.bool,
|
|
55
|
-
scrollEnabled: PropTypes.bool,
|
|
56
|
-
enablePaging: PropTypes.bool,
|
|
57
|
-
enableRTL: PropTypes.bool,
|
|
58
|
-
fitPolicy: PropTypes.number,
|
|
59
|
-
trustAllCerts: PropTypes.bool,
|
|
60
|
-
singlePage: PropTypes.bool,
|
|
61
|
-
onLoadComplete: PropTypes.func,
|
|
62
|
-
onPageChanged: PropTypes.func,
|
|
63
|
-
onError: PropTypes.func,
|
|
64
|
-
onPageSingleTap: PropTypes.func,
|
|
65
|
-
onScaleChanged: PropTypes.func,
|
|
66
|
-
onPressLink: PropTypes.func,
|
|
67
|
-
|
|
68
|
-
// Props that are not available in the earlier react native version, added to prevent crashed on android
|
|
69
|
-
accessibilityLabel: PropTypes.string,
|
|
70
|
-
importantForAccessibility: PropTypes.string,
|
|
71
|
-
renderToHardwareTextureAndroid: PropTypes.string,
|
|
72
|
-
testID: PropTypes.string,
|
|
73
|
-
onLayout: PropTypes.bool,
|
|
74
|
-
accessibilityLiveRegion: PropTypes.string,
|
|
75
|
-
accessibilityComponentType: PropTypes.string,
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
static defaultProps = {
|
|
79
|
-
password: "",
|
|
80
|
-
scale: 1,
|
|
81
|
-
minScale: 1,
|
|
82
|
-
maxScale: 3,
|
|
83
|
-
spacing: 10,
|
|
84
|
-
fitPolicy: 2, //fit both
|
|
85
|
-
horizontal: false,
|
|
86
|
-
page: 1,
|
|
87
|
-
enableAntialiasing: true,
|
|
88
|
-
enableAnnotationRendering: true,
|
|
89
|
-
showsHorizontalScrollIndicator: true,
|
|
90
|
-
showsVerticalScrollIndicator: true,
|
|
91
|
-
scrollEnabled: true,
|
|
92
|
-
enablePaging: false,
|
|
93
|
-
enableRTL: false,
|
|
94
|
-
trustAllCerts: true,
|
|
95
|
-
usePDFKit: true,
|
|
96
|
-
singlePage: false,
|
|
97
|
-
onLoadProgress: (percent) => {
|
|
98
|
-
},
|
|
99
|
-
onLoadComplete: (numberOfPages, path) => {
|
|
100
|
-
},
|
|
101
|
-
onPageChanged: (page, numberOfPages) => {
|
|
102
|
-
},
|
|
103
|
-
onError: (error) => {
|
|
104
|
-
},
|
|
105
|
-
onPageSingleTap: (page, x, y) => {
|
|
106
|
-
},
|
|
107
|
-
onScaleChanged: (scale) => {
|
|
108
|
-
},
|
|
109
|
-
onPressLink: (url) => {
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
constructor(props) {
|
|
114
|
-
|
|
115
|
-
super(props);
|
|
116
|
-
this.state = {
|
|
117
|
-
path: '',
|
|
118
|
-
isDownloaded: false,
|
|
119
|
-
progress: 0,
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
this.lastRNBFTask = null;
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
componentDidUpdate(prevProps) {
|
|
127
|
-
|
|
128
|
-
const nextSource = Image.resolveAssetSource(this.props.source);
|
|
129
|
-
const curSource = Image.resolveAssetSource(prevProps.source);
|
|
130
|
-
|
|
131
|
-
if ((nextSource.uri !== curSource.uri)) {
|
|
132
|
-
// if has download task, then cancel it.
|
|
133
|
-
if (this.lastRNBFTask && this.lastRNBFTask.cancel) {
|
|
134
|
-
this.lastRNBFTask.cancel(err => {
|
|
135
|
-
this._loadFromSource(this.props.source);
|
|
136
|
-
});
|
|
137
|
-
this.lastRNBFTask = null;
|
|
138
|
-
} else {
|
|
139
|
-
this._loadFromSource(this.props.source);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
componentDidMount() {
|
|
145
|
-
this._mounted = true;
|
|
146
|
-
this._loadFromSource(this.props.source);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
componentWillUnmount() {
|
|
150
|
-
this._mounted = false;
|
|
151
|
-
if (this.lastRNBFTask) {
|
|
152
|
-
// this.lastRNBFTask.cancel(err => {
|
|
153
|
-
// });
|
|
154
|
-
this.lastRNBFTask = null;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
_loadFromSource = (newSource) => {
|
|
160
|
-
|
|
161
|
-
const source = Image.resolveAssetSource(newSource) || {};
|
|
162
|
-
|
|
163
|
-
let uri = source.uri || '';
|
|
164
|
-
// first set to initial state
|
|
165
|
-
if (this._mounted) {
|
|
166
|
-
this.setState({ isDownloaded: false, path: '', progress: 0 });
|
|
167
|
-
}
|
|
168
|
-
const filename = source.cacheFileName || SHA1(uri) + '.pdf';
|
|
169
|
-
console.log('=== _loadFromSource uri: ' + uri);
|
|
170
|
-
// const cacheFile = ReactNativeBlobUtil.fs.dirs.CacheDir + '/' + filename;
|
|
171
|
-
|
|
172
|
-
this.setState({ path: uri});
|
|
173
|
-
|
|
174
|
-
if (source.cache) {
|
|
175
|
-
// ReactNativeBlobUtil.fs
|
|
176
|
-
// .stat(cacheFile)
|
|
177
|
-
// .then(stats => {
|
|
178
|
-
// if (!Boolean(source.expiration) || (source.expiration * 1000 + stats.lastModified) > (new Date().getTime())) {
|
|
179
|
-
// if (this._mounted) {
|
|
180
|
-
// this.setState({ path: cacheFile, isDownloaded: true });
|
|
181
|
-
// }
|
|
182
|
-
// } else {
|
|
183
|
-
// // cache expirated then reload it
|
|
184
|
-
// this._prepareFile(source);
|
|
185
|
-
// }
|
|
186
|
-
// })
|
|
187
|
-
// .catch(() => {
|
|
188
|
-
// this._prepareFile(source);
|
|
189
|
-
// })
|
|
190
|
-
|
|
191
|
-
} else {
|
|
192
|
-
this._prepareFile(source);
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
_prepareFile = async (source) => {
|
|
197
|
-
|
|
198
|
-
try {
|
|
199
|
-
if (source.uri) {
|
|
200
|
-
let uri = source.uri || '';
|
|
201
|
-
|
|
202
|
-
const isNetwork = !!(uri && uri.match(/^https?:\/\//));
|
|
203
|
-
const isAsset = !!(uri && uri.match(/^bundle-assets:\/\//));
|
|
204
|
-
const isBase64 = !!(uri && uri.match(/^data:application\/pdf;base64/));
|
|
205
|
-
|
|
206
|
-
const filename = source.cacheFileName || SHA1(uri) + '.pdf';
|
|
207
|
-
console.log('=== _prepareFile filename: ' + filename);
|
|
208
|
-
const cacheFile = ''
|
|
209
|
-
|
|
210
|
-
// delete old cache file
|
|
211
|
-
this._unlinkFile(cacheFile);
|
|
212
|
-
|
|
213
|
-
if (isNetwork) {
|
|
214
|
-
this._downloadFile(source, cacheFile);
|
|
215
|
-
} else if (isAsset) {
|
|
216
|
-
} else if (isBase64) {
|
|
217
|
-
let data = uri.replace(/data:application\/pdf;base64,/i, '');
|
|
218
|
-
} else {
|
|
219
|
-
if (this._mounted) {
|
|
220
|
-
this.setState({
|
|
221
|
-
path: decodeURIComponent(uri.replace(/file:\/\//i, '')),
|
|
222
|
-
isDownloaded: true,
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
} else {
|
|
227
|
-
this._onError(new Error('no pdf source!'));
|
|
228
|
-
}
|
|
229
|
-
} catch (e) {
|
|
230
|
-
this._onError(e)
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
_downloadFile = async (source, cacheFile) => {
|
|
235
|
-
|
|
236
|
-
if (this.lastRNBFTask) {
|
|
237
|
-
this.lastRNBFTask.cancel(err => {
|
|
238
|
-
});
|
|
239
|
-
this.lastRNBFTask = null;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const tempCacheFile = cacheFile + '.tmp';
|
|
243
|
-
this._unlinkFile(tempCacheFile);
|
|
244
|
-
|
|
245
|
-
// this.lastRNBFTask = ReactNativeBlobUtil.config({
|
|
246
|
-
// // response data will be saved to this path if it has access right.
|
|
247
|
-
// path: tempCacheFile,
|
|
248
|
-
// trusty: this.props.trustAllCerts,
|
|
249
|
-
// })
|
|
250
|
-
// .fetch(
|
|
251
|
-
// source.method ? source.method : 'GET',
|
|
252
|
-
// source.uri,
|
|
253
|
-
// source.headers ? source.headers : {},
|
|
254
|
-
// source.body ? source.body : ""
|
|
255
|
-
// )
|
|
256
|
-
// // listen to download progress event
|
|
257
|
-
// .progress((received, total) => {
|
|
258
|
-
// this.props.onLoadProgress && this.props.onLoadProgress(received / total);
|
|
259
|
-
// if (this._mounted) {
|
|
260
|
-
// this.setState({ progress: received / total });
|
|
261
|
-
// }
|
|
262
|
-
// })
|
|
263
|
-
// .catch(async (error) => {
|
|
264
|
-
// this._onError(error);
|
|
265
|
-
// });
|
|
266
|
-
|
|
267
|
-
// this.lastRNBFTask
|
|
268
|
-
// .then(async (res) => {
|
|
269
|
-
|
|
270
|
-
// this.lastRNBFTask = null;
|
|
271
|
-
|
|
272
|
-
// if (res && res.respInfo && res.respInfo.headers && !res.respInfo.headers["Content-Encoding"] && !res.respInfo.headers["Transfer-Encoding"] && res.respInfo.headers["Content-Length"]) {
|
|
273
|
-
// const expectedContentLength = res.respInfo.headers["Content-Length"];
|
|
274
|
-
// let actualContentLength;
|
|
275
|
-
|
|
276
|
-
// try {
|
|
277
|
-
// const fileStats = await ReactNativeBlobUtil.fs.stat(res.path());
|
|
278
|
-
|
|
279
|
-
// if (!fileStats || !fileStats.size) {
|
|
280
|
-
// throw new Error("FileNotFound:" + source.uri);
|
|
281
|
-
// }
|
|
282
|
-
|
|
283
|
-
// actualContentLength = fileStats.size;
|
|
284
|
-
// } catch (error) {
|
|
285
|
-
// throw new Error("DownloadFailed:" + source.uri);
|
|
286
|
-
// }
|
|
287
|
-
|
|
288
|
-
// if (expectedContentLength != actualContentLength) {
|
|
289
|
-
// throw new Error("DownloadFailed:" + source.uri);
|
|
290
|
-
// }
|
|
291
|
-
// }
|
|
292
|
-
|
|
293
|
-
// this._unlinkFile(cacheFile);
|
|
294
|
-
// ReactNativeBlobUtil.fs
|
|
295
|
-
// .cp(tempCacheFile, cacheFile)
|
|
296
|
-
// .then(() => {
|
|
297
|
-
// if (this._mounted) {
|
|
298
|
-
// this.setState({ path: cacheFile, isDownloaded: true, progress: 1 });
|
|
299
|
-
// }
|
|
300
|
-
// this._unlinkFile(tempCacheFile);
|
|
301
|
-
// })
|
|
302
|
-
// .catch(async (error) => {
|
|
303
|
-
// throw error;
|
|
304
|
-
// });
|
|
305
|
-
// })
|
|
306
|
-
// .catch(async (error) => {
|
|
307
|
-
// this._unlinkFile(tempCacheFile);
|
|
308
|
-
// this._unlinkFile(cacheFile);
|
|
309
|
-
// this._onError(error);
|
|
310
|
-
// });
|
|
311
|
-
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
_unlinkFile = async (file) => {
|
|
315
|
-
try {
|
|
316
|
-
// await ReactNativeBlobUtil.fs.unlink(file);
|
|
317
|
-
} catch (e) {
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
setNativeProps = nativeProps => {
|
|
323
|
-
if (this._root) {
|
|
324
|
-
this._root.setNativeProps(nativeProps);
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
setPage(pageNumber) {
|
|
329
|
-
if ((pageNumber === null) || (isNaN(pageNumber))) {
|
|
330
|
-
throw new Error('Specified pageNumber is not a number');
|
|
331
|
-
}
|
|
332
|
-
if (!!global?.nativeFabricUIManager) {
|
|
333
|
-
if (this._root) {
|
|
334
|
-
PdfViewCommands.setNativePage(
|
|
335
|
-
this._root,
|
|
336
|
-
pageNumber,
|
|
337
|
-
);
|
|
338
|
-
}
|
|
339
|
-
} else {
|
|
340
|
-
this.setNativeProps({
|
|
341
|
-
page: pageNumber
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
_onChange = (event) => {
|
|
348
|
-
|
|
349
|
-
let message = event.nativeEvent.message.split('|');
|
|
350
|
-
//__DEV__ && console.log("onChange: " + message);
|
|
351
|
-
if (message.length > 0) {
|
|
352
|
-
if (message.length > 5) {
|
|
353
|
-
message[4] = message.splice(4).join('|');
|
|
354
|
-
}
|
|
355
|
-
if (message[0] === 'loadComplete') {
|
|
356
|
-
let tableContents;
|
|
357
|
-
try {
|
|
358
|
-
tableContents = message[4] && JSON.parse(message[4]);
|
|
359
|
-
} catch (e) {
|
|
360
|
-
tableContents = message[4];
|
|
361
|
-
}
|
|
362
|
-
this.props.onLoadComplete && this.props.onLoadComplete(Number(message[1]), this.state.path, {
|
|
363
|
-
width: Number(message[2]),
|
|
364
|
-
height: Number(message[3]),
|
|
365
|
-
},
|
|
366
|
-
tableContents
|
|
367
|
-
);
|
|
368
|
-
} else if (message[0] === 'loadProgress') {
|
|
369
|
-
this.props.onLoadProgress && this.props.onLoadProgress(Number(message[1]));
|
|
370
|
-
} else if (message[0] === 'pageChanged') {
|
|
371
|
-
this.props.onPageChanged && this.props.onPageChanged(Number(message[1]), Number(message[2]));
|
|
372
|
-
} else if (message[0] === 'error') {
|
|
373
|
-
this._onError(new Error(message[1]));
|
|
374
|
-
} else if (message[0] === 'pageSingleTap') {
|
|
375
|
-
this.props.onPageSingleTap && this.props.onPageSingleTap(Number(message[1]), Number(message[2]), Number(message[3]));
|
|
376
|
-
} else if (message[0] === 'scaleChanged') {
|
|
377
|
-
this.props.onScaleChanged && this.props.onScaleChanged(Number(message[1]));
|
|
378
|
-
} else if (message[0] === 'linkPressed') {
|
|
379
|
-
this.props.onPressLink && this.props.onPressLink(message[1]);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
_onError = (error) => {
|
|
386
|
-
|
|
387
|
-
this.props.onError && this.props.onError(error);
|
|
388
|
-
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
normalizeSource = (source) => {
|
|
392
|
-
if (!source) return source;
|
|
393
|
-
if (typeof source === 'number') return source;
|
|
394
|
-
let { headers, ...rest } = source;
|
|
395
|
-
let normalizedHeaders = undefined;
|
|
396
|
-
if (headers && typeof headers === 'object' && !Array.isArray(headers)) {
|
|
397
|
-
normalizedHeaders = Object.entries(headers).map(([key, value]) => ({
|
|
398
|
-
key,
|
|
399
|
-
value
|
|
400
|
-
}));
|
|
401
|
-
} else if (Array.isArray(headers)) {
|
|
402
|
-
normalizedHeaders = headers;
|
|
403
|
-
}
|
|
404
|
-
return {
|
|
405
|
-
...rest,
|
|
406
|
-
uri: source.uri || '',
|
|
407
|
-
headers: normalizedHeaders
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
render() {
|
|
412
|
-
if (Platform.OS === "android" || Platform.OS === "ios" || Platform.OS === "windows") {
|
|
413
|
-
return (
|
|
414
|
-
<View style={[this.props.style, { overflow: 'hidden' }]}>
|
|
415
|
-
{!this.state.isDownloaded ?
|
|
416
|
-
(<View
|
|
417
|
-
style={[styles.progressContainer, this.props.progressContainerStyle]}
|
|
418
|
-
>
|
|
419
|
-
{this.props.renderActivityIndicator
|
|
420
|
-
? this.props.renderActivityIndicator(this.state.progress)
|
|
421
|
-
: <Text>{`${(this.state.progress * 100).toFixed(2)}%`}</Text>}
|
|
422
|
-
</View>) : (
|
|
423
|
-
Platform.OS === "android" || Platform.OS === "windows" ? (
|
|
424
|
-
<PdfCustom
|
|
425
|
-
ref={component => (this._root = component)}
|
|
426
|
-
{...this.props}
|
|
427
|
-
style={[{ flex: 1, backgroundColor: '#EEE' }, this.props.style]}
|
|
428
|
-
path={this.state.path}
|
|
429
|
-
onChange={this._onChange}
|
|
430
|
-
/>
|
|
431
|
-
) : (
|
|
432
|
-
this.props.usePDFKit ? (
|
|
433
|
-
<PdfCustom
|
|
434
|
-
ref={component => (this._root = component)}
|
|
435
|
-
{...this.props}
|
|
436
|
-
style={[{ backgroundColor: '#EEE', overflow: 'hidden' }, this.props.style]}
|
|
437
|
-
path={this.state.path}
|
|
438
|
-
onChange={this._onChange}
|
|
439
|
-
/>
|
|
440
|
-
) : (<PdfView
|
|
441
|
-
{...this.props}
|
|
442
|
-
style={[{ backgroundColor: '#EEE', overflow: 'hidden' }, this.props.style]}
|
|
443
|
-
path={this.state.path}
|
|
444
|
-
onLoadComplete={this.props.onLoadComplete}
|
|
445
|
-
onPageChanged={this.props.onPageChanged}
|
|
446
|
-
onError={this._onError}
|
|
447
|
-
onPageSingleTap={this.props.onPageSingleTap}
|
|
448
|
-
onScaleChanged={this.props.onScaleChanged}
|
|
449
|
-
onPressLink={this.props.onPressLink}
|
|
450
|
-
/>)
|
|
451
|
-
)
|
|
452
|
-
)}
|
|
453
|
-
</View>);
|
|
454
|
-
} else if (Platform.OS === "harmony") {
|
|
455
|
-
console.log("===react-native-pdf style: " + JSON.stringify(this.props.style));
|
|
456
|
-
return (
|
|
457
|
-
<View style={[{ overflow: 'hidden' }, this.props.style]}>
|
|
458
|
-
<RNPDFPdfView
|
|
459
|
-
key={this.state.path}
|
|
460
|
-
{...this.props}
|
|
461
|
-
source={this.normalizeSource(this.props.source)}
|
|
462
|
-
path={this.state.path}
|
|
463
|
-
onChange={this._onChange}
|
|
464
|
-
/>
|
|
465
|
-
</View>
|
|
466
|
-
);
|
|
467
|
-
} else {
|
|
468
|
-
return (null);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
if (Platform.OS === "android" || Platform.OS === "ios") {
|
|
474
|
-
var PdfCustom = PdfViewNativeComponent;
|
|
475
|
-
} else if (Platform.OS === "windows") {
|
|
476
|
-
var PdfCustom = requireNativeComponent('RCTPdf', Pdf, {
|
|
477
|
-
nativeOnly: { path: true, onChange: true },
|
|
478
|
-
})
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
const styles = StyleSheet.create({
|
|
482
|
-
progressContainer: {
|
|
483
|
-
flex: 1,
|
|
484
|
-
justifyContent: 'center',
|
|
485
|
-
alignItems: 'center'
|
|
486
|
-
},
|
|
487
|
-
progressBar: {
|
|
488
|
-
width: 200,
|
|
489
|
-
height: 2
|
|
490
|
-
}
|
|
491
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017-present, Wonday (@wonday.org)
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT-style license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict';
|
|
10
|
+
import React, { Component } from 'react';
|
|
11
|
+
import PropTypes from 'prop-types';
|
|
12
|
+
import {
|
|
13
|
+
View,
|
|
14
|
+
Platform,
|
|
15
|
+
StyleSheet,
|
|
16
|
+
Image,
|
|
17
|
+
Text,
|
|
18
|
+
requireNativeComponent
|
|
19
|
+
} from 'react-native';
|
|
20
|
+
import PdfViewNativeComponent, {
|
|
21
|
+
Commands as PdfViewCommands,
|
|
22
|
+
} from './fabric/RNPDFPdfNativeComponent';
|
|
23
|
+
// import ReactNativeBlobUtil from 'react-native-blob-util';
|
|
24
|
+
import RNPDFPdfView, { Commands as RNPDFCommands } from "./fabric/RTNPdfViewNativeComponent";
|
|
25
|
+
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
|
|
26
|
+
const SHA1 = require('crypto-js/sha1');
|
|
27
|
+
import PdfView from './PdfView';
|
|
28
|
+
|
|
29
|
+
export default class Pdf extends Component {
|
|
30
|
+
|
|
31
|
+
static propTypes = {
|
|
32
|
+
...ViewPropTypes,
|
|
33
|
+
source: PropTypes.oneOfType([
|
|
34
|
+
PropTypes.shape({
|
|
35
|
+
uri: PropTypes.string,
|
|
36
|
+
cache: PropTypes.bool,
|
|
37
|
+
cacheFileName: PropTypes.string,
|
|
38
|
+
expiration: PropTypes.number,
|
|
39
|
+
}),
|
|
40
|
+
// Opaque type returned by require('./test.pdf')
|
|
41
|
+
PropTypes.number,
|
|
42
|
+
]).isRequired,
|
|
43
|
+
page: PropTypes.number,
|
|
44
|
+
scale: PropTypes.number,
|
|
45
|
+
minScale: PropTypes.number,
|
|
46
|
+
maxScale: PropTypes.number,
|
|
47
|
+
horizontal: PropTypes.bool,
|
|
48
|
+
spacing: PropTypes.number,
|
|
49
|
+
password: PropTypes.string,
|
|
50
|
+
renderActivityIndicator: PropTypes.func,
|
|
51
|
+
enableAntialiasing: PropTypes.bool,
|
|
52
|
+
enableAnnotationRendering: PropTypes.bool,
|
|
53
|
+
showsHorizontalScrollIndicator: PropTypes.bool,
|
|
54
|
+
showsVerticalScrollIndicator: PropTypes.bool,
|
|
55
|
+
scrollEnabled: PropTypes.bool,
|
|
56
|
+
enablePaging: PropTypes.bool,
|
|
57
|
+
enableRTL: PropTypes.bool,
|
|
58
|
+
fitPolicy: PropTypes.number,
|
|
59
|
+
trustAllCerts: PropTypes.bool,
|
|
60
|
+
singlePage: PropTypes.bool,
|
|
61
|
+
onLoadComplete: PropTypes.func,
|
|
62
|
+
onPageChanged: PropTypes.func,
|
|
63
|
+
onError: PropTypes.func,
|
|
64
|
+
onPageSingleTap: PropTypes.func,
|
|
65
|
+
onScaleChanged: PropTypes.func,
|
|
66
|
+
onPressLink: PropTypes.func,
|
|
67
|
+
|
|
68
|
+
// Props that are not available in the earlier react native version, added to prevent crashed on android
|
|
69
|
+
accessibilityLabel: PropTypes.string,
|
|
70
|
+
importantForAccessibility: PropTypes.string,
|
|
71
|
+
renderToHardwareTextureAndroid: PropTypes.string,
|
|
72
|
+
testID: PropTypes.string,
|
|
73
|
+
onLayout: PropTypes.bool,
|
|
74
|
+
accessibilityLiveRegion: PropTypes.string,
|
|
75
|
+
accessibilityComponentType: PropTypes.string,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
static defaultProps = {
|
|
79
|
+
password: "",
|
|
80
|
+
scale: 1,
|
|
81
|
+
minScale: 1,
|
|
82
|
+
maxScale: 3,
|
|
83
|
+
spacing: 10,
|
|
84
|
+
fitPolicy: 2, //fit both
|
|
85
|
+
horizontal: false,
|
|
86
|
+
page: 1,
|
|
87
|
+
enableAntialiasing: true,
|
|
88
|
+
enableAnnotationRendering: true,
|
|
89
|
+
showsHorizontalScrollIndicator: true,
|
|
90
|
+
showsVerticalScrollIndicator: true,
|
|
91
|
+
scrollEnabled: true,
|
|
92
|
+
enablePaging: false,
|
|
93
|
+
enableRTL: false,
|
|
94
|
+
trustAllCerts: true,
|
|
95
|
+
usePDFKit: true,
|
|
96
|
+
singlePage: false,
|
|
97
|
+
onLoadProgress: (percent) => {
|
|
98
|
+
},
|
|
99
|
+
onLoadComplete: (numberOfPages, path) => {
|
|
100
|
+
},
|
|
101
|
+
onPageChanged: (page, numberOfPages) => {
|
|
102
|
+
},
|
|
103
|
+
onError: (error) => {
|
|
104
|
+
},
|
|
105
|
+
onPageSingleTap: (page, x, y) => {
|
|
106
|
+
},
|
|
107
|
+
onScaleChanged: (scale) => {
|
|
108
|
+
},
|
|
109
|
+
onPressLink: (url) => {
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
constructor(props) {
|
|
114
|
+
|
|
115
|
+
super(props);
|
|
116
|
+
this.state = {
|
|
117
|
+
path: '',
|
|
118
|
+
isDownloaded: false,
|
|
119
|
+
progress: 0,
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
this.lastRNBFTask = null;
|
|
123
|
+
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
componentDidUpdate(prevProps) {
|
|
127
|
+
|
|
128
|
+
const nextSource = Image.resolveAssetSource(this.props.source);
|
|
129
|
+
const curSource = Image.resolveAssetSource(prevProps.source);
|
|
130
|
+
|
|
131
|
+
if ((nextSource.uri !== curSource.uri)) {
|
|
132
|
+
// if has download task, then cancel it.
|
|
133
|
+
if (this.lastRNBFTask && this.lastRNBFTask.cancel) {
|
|
134
|
+
this.lastRNBFTask.cancel(err => {
|
|
135
|
+
this._loadFromSource(this.props.source);
|
|
136
|
+
});
|
|
137
|
+
this.lastRNBFTask = null;
|
|
138
|
+
} else {
|
|
139
|
+
this._loadFromSource(this.props.source);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
componentDidMount() {
|
|
145
|
+
this._mounted = true;
|
|
146
|
+
this._loadFromSource(this.props.source);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
componentWillUnmount() {
|
|
150
|
+
this._mounted = false;
|
|
151
|
+
if (this.lastRNBFTask) {
|
|
152
|
+
// this.lastRNBFTask.cancel(err => {
|
|
153
|
+
// });
|
|
154
|
+
this.lastRNBFTask = null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
_loadFromSource = (newSource) => {
|
|
160
|
+
|
|
161
|
+
const source = Image.resolveAssetSource(newSource) || {};
|
|
162
|
+
|
|
163
|
+
let uri = source.uri || '';
|
|
164
|
+
// first set to initial state
|
|
165
|
+
if (this._mounted) {
|
|
166
|
+
this.setState({ isDownloaded: false, path: '', progress: 0 });
|
|
167
|
+
}
|
|
168
|
+
const filename = source.cacheFileName || SHA1(uri) + '.pdf';
|
|
169
|
+
console.log('=== _loadFromSource uri: ' + uri);
|
|
170
|
+
// const cacheFile = ReactNativeBlobUtil.fs.dirs.CacheDir + '/' + filename;
|
|
171
|
+
|
|
172
|
+
this.setState({ path: uri});
|
|
173
|
+
|
|
174
|
+
if (source.cache) {
|
|
175
|
+
// ReactNativeBlobUtil.fs
|
|
176
|
+
// .stat(cacheFile)
|
|
177
|
+
// .then(stats => {
|
|
178
|
+
// if (!Boolean(source.expiration) || (source.expiration * 1000 + stats.lastModified) > (new Date().getTime())) {
|
|
179
|
+
// if (this._mounted) {
|
|
180
|
+
// this.setState({ path: cacheFile, isDownloaded: true });
|
|
181
|
+
// }
|
|
182
|
+
// } else {
|
|
183
|
+
// // cache expirated then reload it
|
|
184
|
+
// this._prepareFile(source);
|
|
185
|
+
// }
|
|
186
|
+
// })
|
|
187
|
+
// .catch(() => {
|
|
188
|
+
// this._prepareFile(source);
|
|
189
|
+
// })
|
|
190
|
+
|
|
191
|
+
} else {
|
|
192
|
+
this._prepareFile(source);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
_prepareFile = async (source) => {
|
|
197
|
+
|
|
198
|
+
try {
|
|
199
|
+
if (source.uri) {
|
|
200
|
+
let uri = source.uri || '';
|
|
201
|
+
|
|
202
|
+
const isNetwork = !!(uri && uri.match(/^https?:\/\//));
|
|
203
|
+
const isAsset = !!(uri && uri.match(/^bundle-assets:\/\//));
|
|
204
|
+
const isBase64 = !!(uri && uri.match(/^data:application\/pdf;base64/));
|
|
205
|
+
|
|
206
|
+
const filename = source.cacheFileName || SHA1(uri) + '.pdf';
|
|
207
|
+
console.log('=== _prepareFile filename: ' + filename);
|
|
208
|
+
const cacheFile = ''
|
|
209
|
+
|
|
210
|
+
// delete old cache file
|
|
211
|
+
this._unlinkFile(cacheFile);
|
|
212
|
+
|
|
213
|
+
if (isNetwork) {
|
|
214
|
+
this._downloadFile(source, cacheFile);
|
|
215
|
+
} else if (isAsset) {
|
|
216
|
+
} else if (isBase64) {
|
|
217
|
+
let data = uri.replace(/data:application\/pdf;base64,/i, '');
|
|
218
|
+
} else {
|
|
219
|
+
if (this._mounted) {
|
|
220
|
+
this.setState({
|
|
221
|
+
path: decodeURIComponent(uri.replace(/file:\/\//i, '')),
|
|
222
|
+
isDownloaded: true,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
} else {
|
|
227
|
+
this._onError(new Error('no pdf source!'));
|
|
228
|
+
}
|
|
229
|
+
} catch (e) {
|
|
230
|
+
this._onError(e)
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
_downloadFile = async (source, cacheFile) => {
|
|
235
|
+
|
|
236
|
+
if (this.lastRNBFTask) {
|
|
237
|
+
this.lastRNBFTask.cancel(err => {
|
|
238
|
+
});
|
|
239
|
+
this.lastRNBFTask = null;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const tempCacheFile = cacheFile + '.tmp';
|
|
243
|
+
this._unlinkFile(tempCacheFile);
|
|
244
|
+
|
|
245
|
+
// this.lastRNBFTask = ReactNativeBlobUtil.config({
|
|
246
|
+
// // response data will be saved to this path if it has access right.
|
|
247
|
+
// path: tempCacheFile,
|
|
248
|
+
// trusty: this.props.trustAllCerts,
|
|
249
|
+
// })
|
|
250
|
+
// .fetch(
|
|
251
|
+
// source.method ? source.method : 'GET',
|
|
252
|
+
// source.uri,
|
|
253
|
+
// source.headers ? source.headers : {},
|
|
254
|
+
// source.body ? source.body : ""
|
|
255
|
+
// )
|
|
256
|
+
// // listen to download progress event
|
|
257
|
+
// .progress((received, total) => {
|
|
258
|
+
// this.props.onLoadProgress && this.props.onLoadProgress(received / total);
|
|
259
|
+
// if (this._mounted) {
|
|
260
|
+
// this.setState({ progress: received / total });
|
|
261
|
+
// }
|
|
262
|
+
// })
|
|
263
|
+
// .catch(async (error) => {
|
|
264
|
+
// this._onError(error);
|
|
265
|
+
// });
|
|
266
|
+
|
|
267
|
+
// this.lastRNBFTask
|
|
268
|
+
// .then(async (res) => {
|
|
269
|
+
|
|
270
|
+
// this.lastRNBFTask = null;
|
|
271
|
+
|
|
272
|
+
// if (res && res.respInfo && res.respInfo.headers && !res.respInfo.headers["Content-Encoding"] && !res.respInfo.headers["Transfer-Encoding"] && res.respInfo.headers["Content-Length"]) {
|
|
273
|
+
// const expectedContentLength = res.respInfo.headers["Content-Length"];
|
|
274
|
+
// let actualContentLength;
|
|
275
|
+
|
|
276
|
+
// try {
|
|
277
|
+
// const fileStats = await ReactNativeBlobUtil.fs.stat(res.path());
|
|
278
|
+
|
|
279
|
+
// if (!fileStats || !fileStats.size) {
|
|
280
|
+
// throw new Error("FileNotFound:" + source.uri);
|
|
281
|
+
// }
|
|
282
|
+
|
|
283
|
+
// actualContentLength = fileStats.size;
|
|
284
|
+
// } catch (error) {
|
|
285
|
+
// throw new Error("DownloadFailed:" + source.uri);
|
|
286
|
+
// }
|
|
287
|
+
|
|
288
|
+
// if (expectedContentLength != actualContentLength) {
|
|
289
|
+
// throw new Error("DownloadFailed:" + source.uri);
|
|
290
|
+
// }
|
|
291
|
+
// }
|
|
292
|
+
|
|
293
|
+
// this._unlinkFile(cacheFile);
|
|
294
|
+
// ReactNativeBlobUtil.fs
|
|
295
|
+
// .cp(tempCacheFile, cacheFile)
|
|
296
|
+
// .then(() => {
|
|
297
|
+
// if (this._mounted) {
|
|
298
|
+
// this.setState({ path: cacheFile, isDownloaded: true, progress: 1 });
|
|
299
|
+
// }
|
|
300
|
+
// this._unlinkFile(tempCacheFile);
|
|
301
|
+
// })
|
|
302
|
+
// .catch(async (error) => {
|
|
303
|
+
// throw error;
|
|
304
|
+
// });
|
|
305
|
+
// })
|
|
306
|
+
// .catch(async (error) => {
|
|
307
|
+
// this._unlinkFile(tempCacheFile);
|
|
308
|
+
// this._unlinkFile(cacheFile);
|
|
309
|
+
// this._onError(error);
|
|
310
|
+
// });
|
|
311
|
+
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
_unlinkFile = async (file) => {
|
|
315
|
+
try {
|
|
316
|
+
// await ReactNativeBlobUtil.fs.unlink(file);
|
|
317
|
+
} catch (e) {
|
|
318
|
+
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
setNativeProps = nativeProps => {
|
|
323
|
+
if (this._root) {
|
|
324
|
+
this._root.setNativeProps(nativeProps);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
setPage(pageNumber) {
|
|
329
|
+
if ((pageNumber === null) || (isNaN(pageNumber))) {
|
|
330
|
+
throw new Error('Specified pageNumber is not a number');
|
|
331
|
+
}
|
|
332
|
+
if (!!global?.nativeFabricUIManager) {
|
|
333
|
+
if (this._root) {
|
|
334
|
+
PdfViewCommands.setNativePage(
|
|
335
|
+
this._root,
|
|
336
|
+
pageNumber,
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
} else {
|
|
340
|
+
this.setNativeProps({
|
|
341
|
+
page: pageNumber
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
_onChange = (event) => {
|
|
348
|
+
|
|
349
|
+
let message = event.nativeEvent.message.split('|');
|
|
350
|
+
//__DEV__ && console.log("onChange: " + message);
|
|
351
|
+
if (message.length > 0) {
|
|
352
|
+
if (message.length > 5) {
|
|
353
|
+
message[4] = message.splice(4).join('|');
|
|
354
|
+
}
|
|
355
|
+
if (message[0] === 'loadComplete') {
|
|
356
|
+
let tableContents;
|
|
357
|
+
try {
|
|
358
|
+
tableContents = message[4] && JSON.parse(message[4]);
|
|
359
|
+
} catch (e) {
|
|
360
|
+
tableContents = message[4];
|
|
361
|
+
}
|
|
362
|
+
this.props.onLoadComplete && this.props.onLoadComplete(Number(message[1]), this.state.path, {
|
|
363
|
+
width: Number(message[2]),
|
|
364
|
+
height: Number(message[3]),
|
|
365
|
+
},
|
|
366
|
+
tableContents
|
|
367
|
+
);
|
|
368
|
+
} else if (message[0] === 'loadProgress') {
|
|
369
|
+
this.props.onLoadProgress && this.props.onLoadProgress(Number(message[1]));
|
|
370
|
+
} else if (message[0] === 'pageChanged') {
|
|
371
|
+
this.props.onPageChanged && this.props.onPageChanged(Number(message[1]), Number(message[2]));
|
|
372
|
+
} else if (message[0] === 'error') {
|
|
373
|
+
this._onError(new Error(message[1]));
|
|
374
|
+
} else if (message[0] === 'pageSingleTap') {
|
|
375
|
+
this.props.onPageSingleTap && this.props.onPageSingleTap(Number(message[1]), Number(message[2]), Number(message[3]));
|
|
376
|
+
} else if (message[0] === 'scaleChanged') {
|
|
377
|
+
this.props.onScaleChanged && this.props.onScaleChanged(Number(message[1]));
|
|
378
|
+
} else if (message[0] === 'linkPressed') {
|
|
379
|
+
this.props.onPressLink && this.props.onPressLink(message[1]);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
_onError = (error) => {
|
|
386
|
+
|
|
387
|
+
this.props.onError && this.props.onError(error);
|
|
388
|
+
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
normalizeSource = (source) => {
|
|
392
|
+
if (!source) return source;
|
|
393
|
+
if (typeof source === 'number') return source;
|
|
394
|
+
let { headers, ...rest } = source;
|
|
395
|
+
let normalizedHeaders = undefined;
|
|
396
|
+
if (headers && typeof headers === 'object' && !Array.isArray(headers)) {
|
|
397
|
+
normalizedHeaders = Object.entries(headers).map(([key, value]) => ({
|
|
398
|
+
key,
|
|
399
|
+
value
|
|
400
|
+
}));
|
|
401
|
+
} else if (Array.isArray(headers)) {
|
|
402
|
+
normalizedHeaders = headers;
|
|
403
|
+
}
|
|
404
|
+
return {
|
|
405
|
+
...rest,
|
|
406
|
+
uri: source.uri || '',
|
|
407
|
+
headers: normalizedHeaders
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
render() {
|
|
412
|
+
if (Platform.OS === "android" || Platform.OS === "ios" || Platform.OS === "windows") {
|
|
413
|
+
return (
|
|
414
|
+
<View style={[this.props.style, { overflow: 'hidden' }]}>
|
|
415
|
+
{!this.state.isDownloaded ?
|
|
416
|
+
(<View
|
|
417
|
+
style={[styles.progressContainer, this.props.progressContainerStyle]}
|
|
418
|
+
>
|
|
419
|
+
{this.props.renderActivityIndicator
|
|
420
|
+
? this.props.renderActivityIndicator(this.state.progress)
|
|
421
|
+
: <Text>{`${(this.state.progress * 100).toFixed(2)}%`}</Text>}
|
|
422
|
+
</View>) : (
|
|
423
|
+
Platform.OS === "android" || Platform.OS === "windows" ? (
|
|
424
|
+
<PdfCustom
|
|
425
|
+
ref={component => (this._root = component)}
|
|
426
|
+
{...this.props}
|
|
427
|
+
style={[{ flex: 1, backgroundColor: '#EEE' }, this.props.style]}
|
|
428
|
+
path={this.state.path}
|
|
429
|
+
onChange={this._onChange}
|
|
430
|
+
/>
|
|
431
|
+
) : (
|
|
432
|
+
this.props.usePDFKit ? (
|
|
433
|
+
<PdfCustom
|
|
434
|
+
ref={component => (this._root = component)}
|
|
435
|
+
{...this.props}
|
|
436
|
+
style={[{ backgroundColor: '#EEE', overflow: 'hidden' }, this.props.style]}
|
|
437
|
+
path={this.state.path}
|
|
438
|
+
onChange={this._onChange}
|
|
439
|
+
/>
|
|
440
|
+
) : (<PdfView
|
|
441
|
+
{...this.props}
|
|
442
|
+
style={[{ backgroundColor: '#EEE', overflow: 'hidden' }, this.props.style]}
|
|
443
|
+
path={this.state.path}
|
|
444
|
+
onLoadComplete={this.props.onLoadComplete}
|
|
445
|
+
onPageChanged={this.props.onPageChanged}
|
|
446
|
+
onError={this._onError}
|
|
447
|
+
onPageSingleTap={this.props.onPageSingleTap}
|
|
448
|
+
onScaleChanged={this.props.onScaleChanged}
|
|
449
|
+
onPressLink={this.props.onPressLink}
|
|
450
|
+
/>)
|
|
451
|
+
)
|
|
452
|
+
)}
|
|
453
|
+
</View>);
|
|
454
|
+
} else if (Platform.OS === "harmony") {
|
|
455
|
+
console.log("===react-native-pdf style: " + JSON.stringify(this.props.style));
|
|
456
|
+
return (
|
|
457
|
+
<View style={[{ overflow: 'hidden' }, this.props.style]}>
|
|
458
|
+
<RNPDFPdfView
|
|
459
|
+
key={this.state.path}
|
|
460
|
+
{...this.props}
|
|
461
|
+
source={this.normalizeSource(this.props.source)}
|
|
462
|
+
path={this.state.path}
|
|
463
|
+
onChange={this._onChange}
|
|
464
|
+
/>
|
|
465
|
+
</View>
|
|
466
|
+
);
|
|
467
|
+
} else {
|
|
468
|
+
return (null);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
if (Platform.OS === "android" || Platform.OS === "ios") {
|
|
474
|
+
var PdfCustom = PdfViewNativeComponent;
|
|
475
|
+
} else if (Platform.OS === "windows") {
|
|
476
|
+
var PdfCustom = requireNativeComponent('RCTPdf', Pdf, {
|
|
477
|
+
nativeOnly: { path: true, onChange: true },
|
|
478
|
+
})
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
const styles = StyleSheet.create({
|
|
482
|
+
progressContainer: {
|
|
483
|
+
flex: 1,
|
|
484
|
+
justifyContent: 'center',
|
|
485
|
+
alignItems: 'center'
|
|
486
|
+
},
|
|
487
|
+
progressBar: {
|
|
488
|
+
width: 200,
|
|
489
|
+
height: 2
|
|
490
|
+
}
|
|
491
|
+
});
|