react-native-pdf 6.6.1 → 6.7.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 (31) hide show
  1. package/DoubleTapView.js +125 -0
  2. package/PdfManager.js +26 -0
  3. package/PdfPageView.js +53 -0
  4. package/PdfView.js +416 -0
  5. package/PdfViewFlatList.js +31 -0
  6. package/PinchZoomView.js +125 -0
  7. package/README.md +25 -46
  8. package/android/build.gradle +71 -13
  9. package/android/src/main/java/org/wonday/pdf/{RCTPdfManager.java → PdfManager.java} +57 -21
  10. package/android/src/main/java/org/wonday/pdf/PdfView.java +25 -0
  11. package/android/src/main/java/org/wonday/pdf/{RCTPdfView.java → RNPDFPackage.java} +2 -3
  12. package/android/src/paper/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.java +86 -0
  13. package/android/src/paper/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.java +33 -0
  14. package/fabric/RNPDFPdfNativeComponent.js +46 -0
  15. package/index.d.ts +11 -67
  16. package/index.js +464 -0
  17. package/index.js.flow +2 -0
  18. package/ios/{RCTPdf/PdfManager.m → RNPDFPdf/PdfManager.mm} +1 -1
  19. package/ios/{RCTPdf/RCTPdfPageView.h → RNPDFPdf/RNPDFPdfPageView.h} +1 -1
  20. package/ios/{RCTPdf/RCTPdfPageView.m → RNPDFPdf/RNPDFPdfPageView.mm} +5 -5
  21. package/ios/{RCTPdf/RCTPdfPageViewManager.h → RNPDFPdf/RNPDFPdfPageViewManager.h} +1 -1
  22. package/ios/{RCTPdf/RCTPdfPageViewManager.m → RNPDFPdf/RNPDFPdfPageViewManager.mm} +4 -4
  23. package/ios/{RCTPdf/RCTPdfView.h → RNPDFPdf/RNPDFPdfView.h} +15 -5
  24. package/ios/{RCTPdf/RCTPdfView.m → RNPDFPdf/RNPDFPdfView.mm} +321 -54
  25. package/ios/{RCTPdf/RCTPdfViewManager.h → RNPDFPdf/RNPDFPdfViewManager.h} +1 -1
  26. package/ios/{RCTPdf/RCTPdfViewManager.m → RNPDFPdf/RNPDFPdfViewManager.mm} +7 -5
  27. package/ios/{RCTPdf.xcodeproj → RNPDFPdf.xcodeproj}/project.pbxproj +38 -38
  28. package/package.json +22 -11
  29. package/react-native-pdf.podspec +28 -3
  30. package/windows/RCTPdf/pch.h +2 -0
  31. /package/ios/{RCTPdf → RNPDFPdf}/PdfManager.h +0 -0
@@ -0,0 +1,125 @@
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 {
12
+ View,
13
+ PanResponder
14
+ } from 'react-native';
15
+ import PropTypes from 'prop-types';
16
+ import {ViewPropTypes} from 'deprecated-react-native-prop-types';
17
+ export default class DoubleTapView extends Component {
18
+
19
+ static propTypes = {
20
+ ...ViewPropTypes,
21
+ delay: PropTypes.number,
22
+ radius: PropTypes.number,
23
+ onSingleTap: PropTypes.func,
24
+ onDoubleTap: PropTypes.func,
25
+ };
26
+
27
+ static defaultProps = {
28
+ delay: 300,
29
+ radius: 50,
30
+ onSingleTap: () => {
31
+ },
32
+ onDoubleTap: () => {
33
+ },
34
+ };
35
+
36
+ constructor() {
37
+ super();
38
+
39
+ this.gestureHandlers = PanResponder.create({
40
+ onStartShouldSetPanResponder: (evt, gestureState) => (gestureState.numberActiveTouches === 1),
41
+ onStartShouldSetResponderCapture: (evt, gestureState) => (gestureState.numberActiveTouches === 1),
42
+ onMoveShouldSetPanResponder: (evt, gestureState) => (false),
43
+ onMoveShouldSetResponderCapture: (evt, gestureState) => (false),
44
+ onPanResponderTerminationRequest: (evt, gestureState) => false,
45
+ onPanResponderRelease: this.handlePanResponderRelease,
46
+
47
+ });
48
+
49
+ this.prevTouchInfo = {
50
+ prevTouchX: 0,
51
+ prevTouchY: 0,
52
+ prevTouchTimeStamp: 0,
53
+ };
54
+
55
+ this.timer = null;
56
+
57
+ }
58
+
59
+
60
+ distance = (x0, y0, x1, y1) => {
61
+ return Math.sqrt(Math.pow((x1 - x0), 2) + Math.pow((y1 - y0), 2)).toFixed(1);
62
+ };
63
+
64
+ isDoubleTap = (currentTouchTimeStamp, {x0, y0}) => {
65
+ const {prevTouchX, prevTouchY, prevTouchTimeStamp} = this.prevTouchInfo;
66
+ const dt = currentTouchTimeStamp - prevTouchTimeStamp;
67
+ const {delay, radius} = this.props;
68
+
69
+ return (prevTouchTimeStamp > 0 && dt < delay && this.distance(prevTouchX, prevTouchY, x0, y0) < radius);
70
+ };
71
+
72
+ handlePanResponderRelease = (evt, gestureState) => {
73
+
74
+ const currentTouchTimeStamp = Date.now();
75
+ const x = evt.nativeEvent.locationX;
76
+ const y = evt.nativeEvent.locationY;
77
+
78
+ if (this.timer) {
79
+
80
+ if (this.isDoubleTap(currentTouchTimeStamp, gestureState)) {
81
+
82
+ clearTimeout(this.timer);
83
+ this.timer = null;
84
+ this.props.onDoubleTap();
85
+
86
+ } else {
87
+
88
+ const {prevTouchX, prevTouchY, prevTouchTimeStamp} = this.prevTouchInfo;
89
+ const {radius} = this.props;
90
+
91
+ // if not in radius, it's a move
92
+ if (this.distance(prevTouchX, prevTouchY, gestureState.x0, gestureState.y0) < radius) {
93
+ this.timer = null;
94
+ this.props.onSingleTap(x, y);
95
+ }
96
+
97
+ }
98
+ } else {
99
+ // do not count scroll gestures as taps
100
+ if (this.distance(0, gestureState.dx, 0, gestureState.dy) < 10) {
101
+
102
+ this.timer = setTimeout(() => {
103
+ this.props.onSingleTap(x, y);
104
+ this.timer = null;
105
+ }, this.props.delay);
106
+ }
107
+ }
108
+
109
+
110
+ this.prevTouchInfo = {
111
+ prevTouchX: gestureState.x0,
112
+ prevTouchY: gestureState.y0,
113
+ prevTouchTimeStamp: currentTouchTimeStamp,
114
+ };
115
+
116
+ };
117
+
118
+ render() {
119
+ return (
120
+ <View {...this.props} {...this.gestureHandlers.panHandlers}>
121
+ {this.props.children}
122
+ </View>
123
+ );
124
+ }
125
+ }
package/PdfManager.js ADDED
@@ -0,0 +1,26 @@
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
+
11
+ const PdfManagerNative = require('react-native').NativeModules.PdfManager;
12
+
13
+ export default class PdfManager {
14
+
15
+ static loadFile(path, password) {
16
+ if (typeof path !== 'string') {
17
+ throw new TypeError('path must be a valid string.');
18
+ }
19
+
20
+ if (password === undefined) {
21
+ password = "";
22
+ }
23
+
24
+ return PdfManagerNative.loadFile(path, password);
25
+ }
26
+ }
package/PdfPageView.js ADDED
@@ -0,0 +1,53 @@
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
+
10
+ 'use strict';
11
+ import React, {PureComponent} from 'react';
12
+ import PropTypes from 'prop-types';
13
+ import {
14
+ requireNativeComponent,
15
+ } from 'react-native';
16
+ import {ViewPropTypes} from 'deprecated-react-native-prop-types';
17
+ export default class PdfPageView extends PureComponent {
18
+ _getStylePropsProps = () => {
19
+ const {width, height} = this.props;
20
+ if (width || height) {
21
+ return {width, height};
22
+ }
23
+ return {};
24
+ };
25
+
26
+ render() {
27
+ const {
28
+ style,
29
+ ...restProps
30
+ } = this.props;
31
+ return (
32
+ <PdfPageViewCustom
33
+ {...restProps}
34
+ style={[style, this._getStylePropsProps()]}
35
+ />
36
+ );
37
+
38
+ }
39
+ }
40
+
41
+ PdfPageView.propTypes = {
42
+ ...ViewPropTypes,
43
+ fileNo: PropTypes.number,
44
+ page: PropTypes.number,
45
+ width: PropTypes.number,
46
+ height: PropTypes.number
47
+ };
48
+
49
+ PdfPageView.defaultProps = {
50
+ style: {}
51
+ };
52
+
53
+ let PdfPageViewCustom = requireNativeComponent('RCTPdfPageView', PdfPageView, {nativeOnly: {}});
package/PdfView.js ADDED
@@ -0,0 +1,416 @@
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 {ScrollView, FlatList, View, StyleSheet} from 'react-native';
12
+ import {ViewPropTypes} from 'deprecated-react-native-prop-types';
13
+ import PropTypes from 'prop-types';
14
+
15
+ import PdfManager from './PdfManager';
16
+ import PdfPageView from './PdfPageView';
17
+ import DoubleTapView from './DoubleTapView';
18
+ import PinchZoomView from './PinchZoomView';
19
+ import PdfViewFlatList from './PdfViewFlatList';
20
+
21
+ const MIN_SCALE = 1;
22
+ const MAX_SCALE = 3;
23
+
24
+ const VIEWABILITYCONFIG = {minimumViewTime: 500, itemVisiblePercentThreshold: 10, waitForInteraction: false};
25
+
26
+ export default class PdfView extends Component {
27
+
28
+ static propTypes = {
29
+ ...ViewPropTypes,
30
+ path: PropTypes.string,
31
+ password: PropTypes.string,
32
+ scale: PropTypes.number,
33
+ minScale: PropTypes.number,
34
+ maxScale: PropTypes.number,
35
+ spacing: PropTypes.number,
36
+ fitPolicy: PropTypes.number,
37
+ horizontal: PropTypes.bool,
38
+ page: PropTypes.number,
39
+ currentPage: PropTypes.number,
40
+ singlePage: PropTypes.bool,
41
+ onPageSingleTap: PropTypes.func,
42
+ onScaleChanged: PropTypes.func,
43
+ };
44
+
45
+ static defaultProps = {
46
+ path: "",
47
+ password: "",
48
+ scale: 1,
49
+ minScale: MIN_SCALE,
50
+ maxScale: MAX_SCALE,
51
+ spacing: 10,
52
+ style: {},
53
+ fitPolicy: 2,
54
+ horizontal: false,
55
+ centerContent: false,
56
+ page: 1,
57
+ currentPage: -1,
58
+ enablePaging: false,
59
+ singlePage: false,
60
+ onPageSingleTap: (page, x, y) => {
61
+ },
62
+ onScaleChanged: (scale) => {
63
+ },
64
+ };
65
+
66
+ constructor(props) {
67
+
68
+ super(props);
69
+ this.state = {
70
+ pdfLoaded: false,
71
+ fileNo: -1,
72
+ numberOfPages: 0,
73
+ page: -1,
74
+ currentPage: -1,
75
+ pageAspectRate: 0.5,
76
+ pdfPageSize: {width: 0, height: 0},
77
+ contentContainerSize: {width: 0, height: 0},
78
+ scale: this.props.scale,
79
+ contentOffset: {x: 0, y: 0},
80
+ newContentOffset: {x: 0, y: 0},
81
+ };
82
+
83
+ this._flatList = null;
84
+ this._scaleTimer = null;
85
+ this._scrollTimer = null;
86
+ this._mounted = false;
87
+
88
+ }
89
+
90
+ componentDidMount() {
91
+ this._mounted = true;
92
+ PdfManager.loadFile(this.props.path, this.props.password)
93
+ .then((pdfInfo) => {
94
+ if (this._mounted) {
95
+ const fileNo = pdfInfo[0];
96
+ const numberOfPages = pdfInfo[1];
97
+ const width = pdfInfo[2];
98
+ const height = pdfInfo[3];
99
+ const pageAspectRatio = height === 0 ? 1 : width / height;
100
+
101
+ this.setState({
102
+ pdfLoaded: true,
103
+ fileNo,
104
+ numberOfPages,
105
+ pageAspectRate: pageAspectRatio,
106
+ pdfPageSize: {width, height},
107
+ centerContent: numberOfPages > 1 ? false : true
108
+ });
109
+ if (this.props.onLoadComplete) {
110
+ this.props.onLoadComplete(numberOfPages, this.props.path, {width, height});
111
+ }
112
+ }
113
+
114
+ })
115
+ .catch((error) => {
116
+ this.props.onError(error);
117
+ });
118
+
119
+ clearTimeout(this._scrollTimer);
120
+ this._scrollTimer = setTimeout(() => {
121
+ if (this._flatList) {
122
+ this._flatList.scrollToIndex({animated: false, index: this.props.page < 1 ? 0 : this.props.page - 1});
123
+ }
124
+ }, 200);
125
+ }
126
+
127
+ componentDidUpdate(prevProps) {
128
+
129
+ if (this.props.scale !== this.state.scale) {
130
+ this._onScaleChanged({
131
+ scale: this.props.scale / this.state.scale,
132
+ pageX: this.state.contentContainerSize.width / 2,
133
+ pageY: this.state.contentContainerSize.height / 2
134
+ });
135
+ }
136
+
137
+ if (this.props.horizontal !== prevProps.horizontal || this.props.page !== prevProps.page) {
138
+ let page = (this.props.page) < 1 ? 1 : this.props.page;
139
+ page = page > this.state.numberOfPages ? this.state.numberOfPages : page;
140
+
141
+ if (this._flatList) {
142
+ clearTimeout(this._scrollTimer);
143
+ this._scrollTimer = setTimeout(() => {
144
+ this._flatList.scrollToIndex({animated: false, index: page - 1});
145
+ }, 200);
146
+ }
147
+ }
148
+
149
+ }
150
+
151
+ componentWillUnmount() {
152
+ this._mounted = false;
153
+ clearTimeout(this._scaleTimer);
154
+ clearTimeout(this._scrollTimer);
155
+
156
+ }
157
+
158
+ _keyExtractor = (item, index) => "pdf-page-" + index;
159
+
160
+ _getPageWidth = () => {
161
+
162
+ let fitPolicy = this.props.fitPolicy;
163
+
164
+ // if only one page, show whole page in center
165
+ if (this.state.numberOfPages === 1 || this.props.singlePage) {
166
+ fitPolicy = 2;
167
+ }
168
+
169
+
170
+ switch (fitPolicy) {
171
+ case 0: //fit width
172
+ return this.state.contentContainerSize.width * this.state.scale;
173
+ case 1: //fit height
174
+ return this.state.contentContainerSize.height * this.state.pageAspectRate * this.state.scale;
175
+ case 2: //fit both
176
+ default: {
177
+ if (this.state.contentContainerSize.width/this.state.contentContainerSize.height<this.state.pageAspectRate) {
178
+ return this.state.contentContainerSize.width * this.state.scale;
179
+ } else {
180
+ return this.state.contentContainerSize.height * this.state.pageAspectRate * this.state.scale;
181
+ }
182
+ }
183
+ }
184
+
185
+ };
186
+
187
+ _getPageHeight = () => {
188
+
189
+ let fitPolicy = this.props.fitPolicy;
190
+
191
+ // if only one page, show whole page in center
192
+ if (this.state.numberOfPages === 1 || this.props.singlePage) {
193
+ fitPolicy = 2;
194
+ }
195
+
196
+ switch (fitPolicy) {
197
+ case 0: //fit width
198
+ return this.state.contentContainerSize.width * (1 / this.state.pageAspectRate) * this.state.scale;
199
+ case 1: //fit height
200
+ return this.state.contentContainerSize.height * this.state.scale;
201
+ case 2: //fit both
202
+ default: {
203
+ if (this.state.contentContainerSize.width/this.state.contentContainerSize.height<this.state.pageAspectRate) {
204
+ return this.state.contentContainerSize.width * (1 / this.state.pageAspectRate) * this.state.scale;
205
+ } else {
206
+ return this.state.contentContainerSize.height * this.state.scale;
207
+ }
208
+ }
209
+ }
210
+
211
+ };
212
+
213
+ _renderSeparator = () => (
214
+ <View style={this.props.horizontal ? {
215
+ width: this.props.spacing * this.state.scale,
216
+ backgroundColor: 'transparent'
217
+ } : {
218
+ height: this.props.spacing * this.state.scale,
219
+ backgroundColor: 'transparent'
220
+ }}/>
221
+ );
222
+
223
+ _onItemSingleTap = (index, x, y) => {
224
+
225
+ this.props.onPageSingleTap(index + 1, x, y);
226
+
227
+ };
228
+
229
+ _onItemDoubleTap = (index) => {
230
+
231
+ if (this.state.scale >= this.props.maxScale) {
232
+ this._onScaleChanged({
233
+ scale: 1 / this.state.scale,
234
+ pageX: this.state.contentContainerSize.width / 2,
235
+ pageY: this.state.contentContainerSize.height / 2
236
+ });
237
+ } else {
238
+ this._onScaleChanged({
239
+ scale: 1.2,
240
+ pageX: this.state.contentContainerSize.width / 2,
241
+ pageY: this.state.contentContainerSize.height / 2
242
+ });
243
+ }
244
+
245
+ };
246
+
247
+ _onScaleChanged = (pinchInfo) => {
248
+
249
+ let newScale = pinchInfo.scale * this.state.scale;
250
+ newScale = newScale > this.props.maxScale ? this.props.maxScale : newScale;
251
+ newScale = newScale < this.props.minScale ? this.props.minScale : newScale;
252
+ let newContentOffset = {
253
+ x: (this.state.contentOffset.x + pinchInfo.pageX) * (newScale / this.state.scale) - pinchInfo.pageX,
254
+ y: (this.state.contentOffset.y + pinchInfo.pageY) * (newScale / this.state.scale) - pinchInfo.pageY
255
+ }
256
+ this.setState({scale: newScale, newContentOffset: newContentOffset});
257
+ this.props.onScaleChanged(newScale);
258
+
259
+ };
260
+
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
+ }
280
+
281
+ return (
282
+ <DoubleTapView style={{flexDirection: this.props.horizontal ? 'row' : 'column'}}
283
+ onSingleTap={(x, y) => {
284
+ this._onItemSingleTap(index, x, y);
285
+ }}
286
+ onDoubleTap={() => {
287
+ this._onItemDoubleTap(index);
288
+ }}
289
+ >
290
+ {pageView}
291
+ {(index !== this.state.numberOfPages - 1) && this._renderSeparator()}
292
+ </DoubleTapView>
293
+ );
294
+
295
+ };
296
+
297
+ _onViewableItemsChanged = (viewableInfo) => {
298
+
299
+ for (let i = 0; i < viewableInfo.viewableItems.length; i++) {
300
+ this._onPageChanged(viewableInfo.viewableItems[i].index + 1, this.state.numberOfPages);
301
+ if (viewableInfo.viewableItems.length + viewableInfo.viewableItems[0].index < this.state.numberOfPages) break;
302
+ }
303
+
304
+ };
305
+
306
+ _onPageChanged = (page, numberOfPages) => {
307
+ if (this.props.onPageChanged && this.state.currentPage !== page) {
308
+ this.props.onPageChanged(page, numberOfPages);
309
+ this.setState({currentPage: page});
310
+ }
311
+ };
312
+
313
+
314
+ _getRef = (ref) => this._flatList = ref;
315
+
316
+ _getItemLayout = (data, index) => ({
317
+ length: this.props.horizontal ? this._getPageWidth() : this._getPageHeight(),
318
+ offset: ((this.props.horizontal ? this._getPageWidth() : this._getPageHeight()) + this.props.spacing * this.state.scale) * index,
319
+ index
320
+ });
321
+
322
+ _onScroll = (e) => {
323
+ this.setState({contentOffset: e.nativeEvent.contentOffset, newContentOffset: e.nativeEvent.contentOffset});
324
+ };
325
+
326
+ _onListContentSizeChange = (contentWidth, contentHeight) => {
327
+ if (this.state.contentOffset.x != this.state.newContentOffset.x
328
+ || this.state.contentOffset.y != this.state.newContentOffset.y) {
329
+ this._flatList.scrollToXY(this.state.newContentOffset.x, this.state.newContentOffset.y);
330
+ }
331
+ };
332
+
333
+ _renderList = () => {
334
+ let data = [];
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
+ }
342
+ }
343
+
344
+ return (
345
+ <PdfViewFlatList
346
+ ref={this._getRef}
347
+ style={[styles.container, this.props.style]}
348
+ pagingEnabled={this.props.enablePaging}
349
+ contentContainerStyle={[{
350
+ justifyContent: 'center',
351
+ alignItems: 'center'
352
+ }, this.props.horizontal ? {height: this.state.contentContainerSize.height * this.state.scale} : {width: this.state.contentContainerSize.width * this.state.scale}]}
353
+ horizontal={this.props.horizontal}
354
+ data={data}
355
+ renderItem={this._renderItem}
356
+ keyExtractor={this._keyExtractor}
357
+ windowSize={11}
358
+ getItemLayout={this._getItemLayout}
359
+ maxToRenderPerBatch={1}
360
+ renderScrollComponent={(props) => <ScrollView
361
+ {...props}
362
+ centerContent={this.state.centerContent}
363
+ pinchGestureEnabled={false}
364
+ />}
365
+ initialScrollIndex={this.props.page < 1 ? 0 : this.props.page - 1}
366
+ onViewableItemsChanged={this._onViewableItemsChanged}
367
+ viewabilityConfig={VIEWABILITYCONFIG}
368
+ onScroll={this._onScroll}
369
+ onContentSizeChange={this._onListContentSizeChange}
370
+ scrollEnabled={!this.props.singlePage}
371
+ />
372
+ );
373
+
374
+ };
375
+
376
+ _onLayout = (event) => {
377
+ this.setState({
378
+ contentContainerSize: {
379
+ width: event.nativeEvent.layout.width,
380
+ height: event.nativeEvent.layout.height
381
+ }
382
+ });
383
+ };
384
+
385
+
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
+ }
397
+
398
+ return (
399
+ <PinchZoomView
400
+ style={styles.container}
401
+ onLayout={this._onLayout}
402
+ onScaleChanged={this._onScaleChanged}
403
+ >
404
+ {this.state.pdfLoaded && this._renderList()}
405
+ </PinchZoomView>
406
+ );
407
+
408
+ }
409
+
410
+ }
411
+
412
+ const styles = StyleSheet.create({
413
+ container: {
414
+ flex: 1
415
+ }
416
+ });
@@ -0,0 +1,31 @@
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 {
12
+ FlatList,
13
+ } from 'react-native';
14
+
15
+ export default class PdfViewFlatList extends FlatList {
16
+ /**
17
+ * Scrolls to a given x, y offset, either immediately or with a smooth animation.
18
+ *
19
+ * Example:
20
+ *
21
+ * `scrollTo({x: 0, y: 0, animated: true})`
22
+ *
23
+ * Note: The weird function signature is due to the fact that, for historical reasons,
24
+ * the function also accepts separate arguments as an alternative to the options object.
25
+ * This is deprecated due to ambiguity (y before x), and SHOULD NOT BE USED.
26
+ */
27
+ scrollToXY = (x, y) => {
28
+ this._listRef._scrollRef.scrollTo({x: x, y: y, animated: false});
29
+ }
30
+
31
+ }