@react-native-ohos/react-native-pdf 6.7.7-rc.1

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 (65) hide show
  1. package/DoubleTapView.js +125 -0
  2. package/LICENSE +21 -0
  3. package/PdfManager.js +26 -0
  4. package/PdfPageView.js +53 -0
  5. package/PdfView.js +417 -0
  6. package/PdfViewFlatList.js +30 -0
  7. package/PinchZoomView.js +125 -0
  8. package/README.OpenSource +11 -0
  9. package/README.md +13 -0
  10. package/fabric/RNPDFPdfNativeComponent.js +48 -0
  11. package/fabric/RTNPdfViewNativeComponent.ts +57 -0
  12. package/harmony/pdfview/BuildProfile.ets +17 -0
  13. package/harmony/pdfview/Index.ets +7 -0
  14. package/harmony/pdfview/build-profile.json5 +28 -0
  15. package/harmony/pdfview/consumer-rules.txt +0 -0
  16. package/harmony/pdfview/hvigorfile.ts +6 -0
  17. package/harmony/pdfview/obfuscation-rules.txt +18 -0
  18. package/harmony/pdfview/oh-package-lock.json5 +18 -0
  19. package/harmony/pdfview/oh-package.json5 +11 -0
  20. package/harmony/pdfview/src/main/cpp/CMakeLists.txt +8 -0
  21. package/harmony/pdfview/src/main/cpp/ComponentDescriptors.h +36 -0
  22. package/harmony/pdfview/src/main/cpp/EventEmitters.cpp +39 -0
  23. package/harmony/pdfview/src/main/cpp/EventEmitters.h +47 -0
  24. package/harmony/pdfview/src/main/cpp/PdfEventEmitRequestHandler.h +50 -0
  25. package/harmony/pdfview/src/main/cpp/PdfViewJSIBinder.h +71 -0
  26. package/harmony/pdfview/src/main/cpp/PdfViewPackage.h +55 -0
  27. package/harmony/pdfview/src/main/cpp/Props.cpp +58 -0
  28. package/harmony/pdfview/src/main/cpp/Props.h +61 -0
  29. package/harmony/pdfview/src/main/cpp/RTNPdfViewSpecsJSI-generated.cpp +34 -0
  30. package/harmony/pdfview/src/main/cpp/RTNPdfViewSpecsJSI.h +36 -0
  31. package/harmony/pdfview/src/main/cpp/ShadowNodes.cpp +33 -0
  32. package/harmony/pdfview/src/main/cpp/ShadowNodes.h +47 -0
  33. package/harmony/pdfview/src/main/cpp/States.cpp +33 -0
  34. package/harmony/pdfview/src/main/cpp/States.h +52 -0
  35. package/harmony/pdfview/src/main/ets/Logger.ets +64 -0
  36. package/harmony/pdfview/src/main/ets/components/mainpage/RTNPdfView.ets +513 -0
  37. package/harmony/pdfview/src/main/ets/components/mainpage/types.ts +15 -0
  38. package/harmony/pdfview/src/main/module.json5 +11 -0
  39. package/harmony/pdfview/src/main/resources/base/element/string.json +8 -0
  40. package/harmony/pdfview/src/main/resources/en_US/element/string.json +8 -0
  41. package/harmony/pdfview/src/main/resources/zh_CN/element/string.json +8 -0
  42. package/harmony/pdfview/src/test/List.test.ets +29 -0
  43. package/harmony/pdfview/src/test/LocalUnit.test.ets +57 -0
  44. package/harmony/pdfview.har +0 -0
  45. package/index.d.ts +72 -0
  46. package/index.js +491 -0
  47. package/index.js.flow +67 -0
  48. package/package.json +61 -0
  49. package/windows/RCTPdf/PropertySheet.props +16 -0
  50. package/windows/RCTPdf/RCTPdf.def +3 -0
  51. package/windows/RCTPdf/RCTPdf.vcxproj +180 -0
  52. package/windows/RCTPdf/RCTPdf.vcxproj.filters +38 -0
  53. package/windows/RCTPdf/RCTPdfControl.cpp +667 -0
  54. package/windows/RCTPdf/RCTPdfControl.h +119 -0
  55. package/windows/RCTPdf/RCTPdfControl.idl +10 -0
  56. package/windows/RCTPdf/RCTPdfControl.xaml +33 -0
  57. package/windows/RCTPdf/RCTPdfViewManager.cpp +69 -0
  58. package/windows/RCTPdf/RCTPdfViewManager.h +51 -0
  59. package/windows/RCTPdf/ReactPackageProvider.cpp +15 -0
  60. package/windows/RCTPdf/ReactPackageProvider.h +16 -0
  61. package/windows/RCTPdf/ReactPackageProvider.idl +9 -0
  62. package/windows/RCTPdf/packages.config +4 -0
  63. package/windows/RCTPdf/pch.cpp +1 -0
  64. package/windows/RCTPdf/pch.h +31 -0
  65. package/windows/README.md +21 -0
package/index.d.ts ADDED
@@ -0,0 +1,72 @@
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
+ import * as React from 'react';
10
+ import * as ReactNative from 'react-native';
11
+
12
+ export type TableContent = {
13
+ children: TableContent[],
14
+ mNativePtr: number,
15
+ pageIdx: number,
16
+ title: string,
17
+ };
18
+
19
+ export type Source = {
20
+ uri?: string;
21
+ headers?: {
22
+ [key: string]: string;
23
+ };
24
+ cache?: boolean;
25
+ cacheFileName?: string;
26
+ expiration?: number;
27
+ method?: string;
28
+ };
29
+
30
+ export interface PdfProps {
31
+ style?: ReactNative.StyleProp<ReactNative.ViewStyle>,
32
+ progressContainerStyle?: ReactNative.StyleProp<ReactNative.ViewStyle>,
33
+ source: Source | number,
34
+ page?: number,
35
+ scale?: number,
36
+ minScale?: number,
37
+ maxScale?: number,
38
+ horizontal?: boolean,
39
+ showsHorizontalScrollIndicator?: boolean,
40
+ showsVerticalScrollIndicator?: boolean,
41
+ scrollEnabled?: boolean,
42
+ spacing?: number,
43
+ password?: string,
44
+ renderActivityIndicator?: (progress: number) => React.ReactElement,
45
+ enableAntialiasing?: boolean,
46
+ enablePaging?: boolean,
47
+ enableRTL?: boolean,
48
+ enableAnnotationRendering?: boolean,
49
+ enableDoubleTapZoom?: boolean;
50
+ /**
51
+ * Fit policy. This will adjust the initial zoom of the PDF based on the initial size of the view and the scale factor.
52
+ * 0 = fit width
53
+ * 1 = fit height
54
+ * 2 = fit both
55
+ */
56
+ fitPolicy?: 0 | 1 | 2,
57
+ trustAllCerts?: boolean,
58
+ singlePage?: boolean,
59
+ onLoadProgress?: (percent: number,) => void,
60
+ onLoadComplete?: (numberOfPages: number, path: string, size: {height: number, width: number}, tableContents?: TableContent[]) => void,
61
+ onPageChanged?: (page: number, numberOfPages: number) => void,
62
+ onError?: (error: object) => void,
63
+ onPageSingleTap?: (page: number, x: number, y: number) => void,
64
+ onScaleChanged?: (scale: number) => void,
65
+ onPressLink?: (url: string) => void,
66
+ }
67
+
68
+ declare class Pdf extends React.Component<PdfProps, any> {
69
+ setPage: (pageNumber: number) => void;
70
+ }
71
+
72
+ export default Pdf;
package/index.js ADDED
@@ -0,0 +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
+ });
package/index.js.flow ADDED
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @flow strict
3
+ */
4
+
5
+ import { Component } from 'react';
6
+
7
+ import type { Node } from 'react';
8
+ import type { FormField, Methods } from 'rn-fetch-blob';
9
+ import type { ViewStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet'
10
+
11
+ export type AssetId = number;
12
+
13
+ export type FitWidth = 0;
14
+ export type FitHeight = 1;
15
+ export type FitBoth = 2;
16
+
17
+ export type Source = {
18
+ body?: string | FormField[],
19
+ cache?: boolean,
20
+ cacheFileName?: string,
21
+ expiration?: number,
22
+ headers?: { [key: string]: string },
23
+ method?: Methods,
24
+ uri: string
25
+ };
26
+
27
+ export type TableContent = {
28
+ children: TableContent[],
29
+ mNativePtr: number,
30
+ pageIdx: number,
31
+ title: string,
32
+ };
33
+
34
+ export type Props = {
35
+ renderActivityIndicator?: (progress: number) => Node,
36
+ enableAnnotationRendering?: boolean,
37
+ enableAntialiasing?: boolean,
38
+ enablePaging?: boolean,
39
+ enableRTL?: boolean,
40
+ fitPolicy?: FitWidth | FitHeight | FitBoth,
41
+ horizontal?: boolean,
42
+ showsHorizontalScrollIndicator?: boolean,
43
+ showsVerticalScrollIndicator?: boolean,
44
+ scrollEnabled?: boolean,
45
+ maxScale?: number,
46
+ minScale?: number,
47
+ singlePage?: boolean,
48
+ onError?: (error: Error) => void,
49
+ onLoadComplete?: (numberOfPages: number, path: string, size: { height: number, width: number }, tableContents: ?TableContent[]) => void,
50
+ onLoadProgress?: (percent: number) => void,
51
+ onPageChanged?: (page: number, numberOfPages: number) => void,
52
+ onPageSingleTap?: (page: number, x: number, y: number) => void,
53
+ onScaleChanged?: (scale: number) => void,
54
+ onPressLink?: (url: string) => void,
55
+ page?: number,
56
+ password?: string,
57
+ progressContainerStyle?: ViewStyleProp,
58
+ scale?: number,
59
+ source: AssetId | Source,
60
+ spacing?: number,
61
+ style?: ViewStyleProp,
62
+ testID?: string
63
+ };
64
+
65
+ declare export default class Pdf extends Component<Props> {
66
+ setPage: (pageNumber: number) => void;
67
+ }
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@react-native-ohos/react-native-pdf",
3
+ "version": "6.7.7-rc.1",
4
+ "summary": "A react native PDF view component",
5
+ "description": "A react native PDF view component, support ios and android platform",
6
+ "main": "index.js",
7
+ "typings": "./index.d.ts",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/react-native-oh-library/react-native-pdf.git"
11
+ },
12
+ "harmony": {
13
+ "alias": "react-native-pdf"
14
+ },
15
+ "keywords": [
16
+ "react-component",
17
+ "react-native",
18
+ "pdf",
19
+ "view",
20
+ "viewer"
21
+ ],
22
+ "author": {
23
+ "name": "Wonday",
24
+ "url": "https://github.com/wonday"
25
+ },
26
+ "license": "MIT",
27
+ "homepage": "https://github.com/react-native-oh-library/react-native-pdf",
28
+ "bugs": {
29
+ "url": "https://github.com/react-native-oh-library/react-native-pdf/issues"
30
+ },
31
+ "dependencies": {
32
+ "crypto-js": "4.2.0",
33
+ "deprecated-react-native-prop-types": "^2.3.0",
34
+ "react-native-pdf": "6.7.6"
35
+ },
36
+ "devDependencies": {
37
+ "@babel/core": "^7.20.2",
38
+ "@babel/runtime": "^7.20.1",
39
+ "prop-types": "^15.7.2"
40
+ },
41
+ "peerDependencies": {
42
+ "react": "*",
43
+ "react-native": "*",
44
+ "react-native-blob-util": ">=0.13.7"
45
+ },
46
+ "files": [
47
+ "harmony",
48
+ "windows/",
49
+ "DoubleTapView.js",
50
+ "index.d.ts",
51
+ "index.js",
52
+ "index.js.flow",
53
+ "PdfManager.js",
54
+ "PdfPageView.js",
55
+ "PdfView.js",
56
+ "PdfViewFlatList.js",
57
+ "PinchZoomView.js",
58
+ "react-native-pdf.podspec",
59
+ "fabric/"
60
+ ]
61
+ }