react-native-pdf-jsi 1.0.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 (91) hide show
  1. package/DoubleTapView.js +125 -0
  2. package/INTEGRATION_GUIDE.md +419 -0
  3. package/LICENSE +21 -0
  4. package/PdfManager.js +26 -0
  5. package/PdfPageView.js +53 -0
  6. package/PdfView.js +421 -0
  7. package/PdfViewFlatList.js +30 -0
  8. package/PinchZoomView.js +125 -0
  9. package/README.md +693 -0
  10. package/README_JSI.md +348 -0
  11. package/android/.gradle/5.6.1/fileChanges/last-build.bin +0 -0
  12. package/android/.gradle/5.6.1/fileHashes/fileHashes.lock +0 -0
  13. package/android/.gradle/5.6.1/gc.properties +0 -0
  14. package/android/.gradle/8.5/checksums/checksums.lock +0 -0
  15. package/android/.gradle/8.5/checksums/md5-checksums.bin +0 -0
  16. package/android/.gradle/8.5/checksums/sha1-checksums.bin +0 -0
  17. package/android/.gradle/8.5/dependencies-accessors/dependencies-accessors.lock +0 -0
  18. package/android/.gradle/8.5/dependencies-accessors/gc.properties +0 -0
  19. package/android/.gradle/8.5/executionHistory/executionHistory.lock +0 -0
  20. package/android/.gradle/8.5/fileChanges/last-build.bin +0 -0
  21. package/android/.gradle/8.5/fileHashes/fileHashes.lock +0 -0
  22. package/android/.gradle/8.5/gc.properties +0 -0
  23. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  24. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  25. package/android/.gradle/vcs-1/gc.properties +0 -0
  26. package/android/build.gradle +198 -0
  27. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  28. package/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  29. package/android/gradle.properties +2 -0
  30. package/android/gradlew +249 -0
  31. package/android/gradlew.bat +92 -0
  32. package/android/project.properties +12 -0
  33. package/android/src/main/AndroidManifest.xml +4 -0
  34. package/android/src/main/cpp/Android.mk +50 -0
  35. package/android/src/main/cpp/CMakeLists.txt +76 -0
  36. package/android/src/main/cpp/PDFJSI.cpp +190 -0
  37. package/android/src/main/cpp/PDFJSI.h +95 -0
  38. package/android/src/main/cpp/PDFJSIBridge.cpp +32 -0
  39. package/android/src/main/cpp/PDFJSIModule.cpp +31 -0
  40. package/android/src/main/java/org/wonday/pdf/EnhancedPdfJSIBridge.java +281 -0
  41. package/android/src/main/java/org/wonday/pdf/PDFJSIManager.java +317 -0
  42. package/android/src/main/java/org/wonday/pdf/PDFJSIModule.java +189 -0
  43. package/android/src/main/java/org/wonday/pdf/PdfManager.java +180 -0
  44. package/android/src/main/java/org/wonday/pdf/PdfView.java +505 -0
  45. package/android/src/main/java/org/wonday/pdf/RNPDFPackage.java +43 -0
  46. package/android/src/main/java/org/wonday/pdf/events/TopChangeEvent.java +26 -0
  47. package/android/src/main/jniLibs/arm64-v8a/libpdfjsi.so +0 -0
  48. package/android/src/main/jniLibs/armeabi-v7a/libpdfjsi.so +0 -0
  49. package/android/src/main/jniLibs/x86/libpdfjsi.so +0 -0
  50. package/android/src/main/jniLibs/x86_64/libpdfjsi.so +0 -0
  51. package/android/src/paper/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.java +92 -0
  52. package/android/src/paper/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.java +35 -0
  53. package/fabric/RNPDFPdfNativeComponent.js +48 -0
  54. package/index.d.ts +72 -0
  55. package/index.js +603 -0
  56. package/index.js.flow +67 -0
  57. package/ios/RNPDFPdf/PdfManager.h +23 -0
  58. package/ios/RNPDFPdf/PdfManager.mm +152 -0
  59. package/ios/RNPDFPdf/RNPDFPdfPageView.h +21 -0
  60. package/ios/RNPDFPdf/RNPDFPdfPageView.mm +185 -0
  61. package/ios/RNPDFPdf/RNPDFPdfPageViewManager.h +18 -0
  62. package/ios/RNPDFPdf/RNPDFPdfPageViewManager.mm +30 -0
  63. package/ios/RNPDFPdf/RNPDFPdfView.h +63 -0
  64. package/ios/RNPDFPdf/RNPDFPdfView.mm +1092 -0
  65. package/ios/RNPDFPdf/RNPDFPdfViewManager.h +18 -0
  66. package/ios/RNPDFPdf/RNPDFPdfViewManager.mm +68 -0
  67. package/ios/RNPDFPdf.xcodeproj/project.pbxproj +321 -0
  68. package/package.json +78 -0
  69. package/react-native-pdf.podspec +31 -0
  70. package/src/EnhancedPdfView.js +362 -0
  71. package/src/PDFJSI.js +519 -0
  72. package/src/examples/PDFJSIExample.js +296 -0
  73. package/src/hooks/usePDFJSI.js +346 -0
  74. package/src/index.js +32 -0
  75. package/windows/RCTPdf/PropertySheet.props +16 -0
  76. package/windows/RCTPdf/RCTPdf.def +3 -0
  77. package/windows/RCTPdf/RCTPdf.vcxproj +180 -0
  78. package/windows/RCTPdf/RCTPdf.vcxproj.filters +38 -0
  79. package/windows/RCTPdf/RCTPdfControl.cpp +667 -0
  80. package/windows/RCTPdf/RCTPdfControl.h +119 -0
  81. package/windows/RCTPdf/RCTPdfControl.idl +10 -0
  82. package/windows/RCTPdf/RCTPdfControl.xaml +33 -0
  83. package/windows/RCTPdf/RCTPdfViewManager.cpp +69 -0
  84. package/windows/RCTPdf/RCTPdfViewManager.h +51 -0
  85. package/windows/RCTPdf/ReactPackageProvider.cpp +15 -0
  86. package/windows/RCTPdf/ReactPackageProvider.h +16 -0
  87. package/windows/RCTPdf/ReactPackageProvider.idl +9 -0
  88. package/windows/RCTPdf/packages.config +4 -0
  89. package/windows/RCTPdf/pch.cpp +1 -0
  90. package/windows/RCTPdf/pch.h +31 -0
  91. package/windows/README.md +21 -0
package/PdfView.js ADDED
@@ -0,0 +1,421 @@
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, 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
+ showsHorizontalScrollIndicator: PropTypes.bool,
44
+ showsVerticalScrollIndicator: PropTypes.bool,
45
+ };
46
+
47
+ static defaultProps = {
48
+ path: "",
49
+ password: "",
50
+ scale: 1,
51
+ minScale: MIN_SCALE,
52
+ maxScale: MAX_SCALE,
53
+ spacing: 10,
54
+ style: {},
55
+ progressContainerStyle: {},
56
+ fitPolicy: 2,
57
+ horizontal: false,
58
+ centerContent: false,
59
+ page: 1,
60
+ currentPage: -1,
61
+ enablePaging: false,
62
+ singlePage: false,
63
+ onPageSingleTap: (page, x, y) => {
64
+ },
65
+ onScaleChanged: (scale) => {
66
+ },
67
+ showsHorizontalScrollIndicator: true,
68
+ showsVerticalScrollIndicator: true,
69
+ };
70
+
71
+ constructor(props) {
72
+
73
+ super(props);
74
+ this.state = {
75
+ pdfLoaded: false,
76
+ fileNo: -1,
77
+ numberOfPages: 0,
78
+ page: -1,
79
+ currentPage: -1,
80
+ pageAspectRate: 0.5,
81
+ pdfPageSize: {width: 0, height: 0},
82
+ contentContainerSize: {width: 0, height: 0},
83
+ scale: this.props.scale,
84
+ contentOffset: {x: 0, y: 0},
85
+ newContentOffset: {x: 0, y: 0},
86
+ };
87
+
88
+ this._flatList = null;
89
+ this._scaleTimer = null;
90
+ this._scrollTimer = null;
91
+ this._mounted = false;
92
+
93
+ }
94
+
95
+ componentDidMount() {
96
+ this._mounted = true;
97
+ PdfManager.loadFile(this.props.path, this.props.password)
98
+ .then((pdfInfo) => {
99
+ if (this._mounted) {
100
+ const fileNo = pdfInfo[0];
101
+ const numberOfPages = pdfInfo[1];
102
+ const width = pdfInfo[2];
103
+ const height = pdfInfo[3];
104
+ const pageAspectRatio = height === 0 ? 1 : width / height;
105
+
106
+ this.setState({
107
+ pdfLoaded: true,
108
+ fileNo,
109
+ numberOfPages,
110
+ pageAspectRate: pageAspectRatio,
111
+ pdfPageSize: {width, height},
112
+ centerContent: numberOfPages > 1 ? false : true
113
+ });
114
+ if (this.props.onLoadComplete) {
115
+ this.props.onLoadComplete(numberOfPages, this.props.path, {width, height});
116
+ }
117
+ }
118
+
119
+ })
120
+ .catch((error) => {
121
+ this.props.onError(error);
122
+ });
123
+
124
+ clearTimeout(this._scrollTimer);
125
+ this._scrollTimer = setTimeout(() => {
126
+ if (this._flatList) {
127
+ this._flatList.scrollToIndex({animated: false, index: this.props.page < 1 ? 0 : this.props.page - 1});
128
+ }
129
+ }, 200);
130
+ }
131
+
132
+ componentDidUpdate(prevProps) {
133
+
134
+ if (this.props.scale !== this.state.scale) {
135
+ this._onScaleChanged({
136
+ scale: this.props.scale / this.state.scale,
137
+ pageX: this.state.contentContainerSize.width / 2,
138
+ pageY: this.state.contentContainerSize.height / 2
139
+ });
140
+ }
141
+
142
+ if (this.props.horizontal !== prevProps.horizontal || this.props.page !== prevProps.page) {
143
+ let page = (this.props.page) < 1 ? 1 : this.props.page;
144
+ page = page > this.state.numberOfPages ? this.state.numberOfPages : page;
145
+
146
+ if (this._flatList) {
147
+ clearTimeout(this._scrollTimer);
148
+ this._scrollTimer = setTimeout(() => {
149
+ this._flatList.scrollToIndex({animated: false, index: page - 1});
150
+ }, 200);
151
+ }
152
+ }
153
+
154
+ }
155
+
156
+ componentWillUnmount() {
157
+ this._mounted = false;
158
+ clearTimeout(this._scaleTimer);
159
+ clearTimeout(this._scrollTimer);
160
+
161
+ }
162
+
163
+ _keyExtractor = (item, index) => "pdf-page-" + index;
164
+
165
+ _getPageWidth = () => {
166
+
167
+ let fitPolicy = this.props.fitPolicy;
168
+
169
+ // if only one page, show whole page in center
170
+ if (this.state.numberOfPages === 1 || this.props.singlePage) {
171
+ fitPolicy = 2;
172
+ }
173
+
174
+
175
+ switch (fitPolicy) {
176
+ case 0: //fit width
177
+ return this.state.contentContainerSize.width * this.state.scale;
178
+ case 1: //fit height
179
+ return this.state.contentContainerSize.height * this.state.pageAspectRate * this.state.scale;
180
+ case 2: //fit both
181
+ default: {
182
+ if (this.state.contentContainerSize.width/this.state.contentContainerSize.height<this.state.pageAspectRate) {
183
+ return this.state.contentContainerSize.width * this.state.scale;
184
+ } else {
185
+ return this.state.contentContainerSize.height * this.state.pageAspectRate * this.state.scale;
186
+ }
187
+ }
188
+ }
189
+
190
+ };
191
+
192
+ _getPageHeight = () => {
193
+
194
+ let fitPolicy = this.props.fitPolicy;
195
+
196
+ // if only one page, show whole page in center
197
+ if (this.state.numberOfPages === 1 || this.props.singlePage) {
198
+ fitPolicy = 2;
199
+ }
200
+
201
+ switch (fitPolicy) {
202
+ case 0: //fit width
203
+ return this.state.contentContainerSize.width * (1 / this.state.pageAspectRate) * this.state.scale;
204
+ case 1: //fit height
205
+ return this.state.contentContainerSize.height * this.state.scale;
206
+ case 2: //fit both
207
+ default: {
208
+ if (this.state.contentContainerSize.width/this.state.contentContainerSize.height<this.state.pageAspectRate) {
209
+ return this.state.contentContainerSize.width * (1 / this.state.pageAspectRate) * this.state.scale;
210
+ } else {
211
+ return this.state.contentContainerSize.height * this.state.scale;
212
+ }
213
+ }
214
+ }
215
+
216
+ };
217
+
218
+ _renderSeparator = () => (
219
+ <View style={this.props.horizontal ? {
220
+ width: this.props.spacing * this.state.scale,
221
+ backgroundColor: 'transparent'
222
+ } : {
223
+ height: this.props.spacing * this.state.scale,
224
+ backgroundColor: 'transparent'
225
+ }}/>
226
+ );
227
+
228
+ _onItemSingleTap = (index, x, y) => {
229
+
230
+ this.props.onPageSingleTap(index + 1, x, y);
231
+
232
+ };
233
+
234
+ _onItemDoubleTap = (index) => {
235
+
236
+ if (this.state.scale >= this.props.maxScale) {
237
+ this._onScaleChanged({
238
+ scale: 1 / this.state.scale,
239
+ pageX: this.state.contentContainerSize.width / 2,
240
+ pageY: this.state.contentContainerSize.height / 2
241
+ });
242
+ } else {
243
+ this._onScaleChanged({
244
+ scale: 1.2,
245
+ pageX: this.state.contentContainerSize.width / 2,
246
+ pageY: this.state.contentContainerSize.height / 2
247
+ });
248
+ }
249
+
250
+ };
251
+
252
+ _onScaleChanged = (pinchInfo) => {
253
+
254
+ let newScale = pinchInfo.scale * this.state.scale;
255
+ newScale = newScale > this.props.maxScale ? this.props.maxScale : newScale;
256
+ newScale = newScale < this.props.minScale ? this.props.minScale : newScale;
257
+ let newContentOffset = {
258
+ x: (this.state.contentOffset.x + pinchInfo.pageX) * (newScale / this.state.scale) - pinchInfo.pageX,
259
+ y: (this.state.contentOffset.y + pinchInfo.pageY) * (newScale / this.state.scale) - pinchInfo.pageY
260
+ }
261
+ this.setState({scale: newScale, newContentOffset: newContentOffset});
262
+ this.props.onScaleChanged(newScale);
263
+
264
+ };
265
+
266
+ _renderItem = ({item, index}) => {
267
+ const pageView = (
268
+ <PdfPageView
269
+ accessible={true}
270
+ key={item.id}
271
+ fileNo={this.state.fileNo}
272
+ page={item.key + 1}
273
+ width={this._getPageWidth()}
274
+ height={this._getPageHeight()}
275
+ />
276
+ )
277
+
278
+ if (this.props.singlePage) {
279
+ return (
280
+ <View style={{flexDirection: this.props.horizontal ? 'row' : 'column'}} >
281
+ {pageView}
282
+ </View>
283
+ )
284
+ }
285
+
286
+ return (
287
+ <DoubleTapView style={{flexDirection: this.props.horizontal ? 'row' : 'column'}}
288
+ onSingleTap={(x, y) => {
289
+ this._onItemSingleTap(index, x, y);
290
+ }}
291
+ onDoubleTap={() => {
292
+ this._onItemDoubleTap(index);
293
+ }}
294
+ >
295
+ {pageView}
296
+ {(index !== this.state.numberOfPages - 1) && this._renderSeparator()}
297
+ </DoubleTapView>
298
+ );
299
+
300
+ };
301
+
302
+ _onViewableItemsChanged = (viewableInfo) => {
303
+
304
+ for (let i = 0; i < viewableInfo.viewableItems.length; i++) {
305
+ this._onPageChanged(viewableInfo.viewableItems[i].index + 1, this.state.numberOfPages);
306
+ if (viewableInfo.viewableItems.length + viewableInfo.viewableItems[0].index < this.state.numberOfPages) break;
307
+ }
308
+
309
+ };
310
+
311
+ _onPageChanged = (page, numberOfPages) => {
312
+ if (this.props.onPageChanged && this.state.currentPage !== page) {
313
+ this.props.onPageChanged(page, numberOfPages);
314
+ this.setState({currentPage: page});
315
+ }
316
+ };
317
+
318
+
319
+ _getRef = (ref) => this._flatList = ref;
320
+
321
+ _getItemLayout = (data, index) => ({
322
+ length: this.props.horizontal ? this._getPageWidth() : this._getPageHeight(),
323
+ offset: ((this.props.horizontal ? this._getPageWidth() : this._getPageHeight()) + this.props.spacing * this.state.scale) * index,
324
+ index
325
+ });
326
+
327
+ _onScroll = (e) => {
328
+ this.setState({contentOffset: e.nativeEvent.contentOffset, newContentOffset: e.nativeEvent.contentOffset});
329
+ };
330
+
331
+ _onListContentSizeChange = (contentWidth, contentHeight) => {
332
+ if (this.state.contentOffset.x != this.state.newContentOffset.x
333
+ || this.state.contentOffset.y != this.state.newContentOffset.y) {
334
+ this._flatList.scrollToXY(this.state.newContentOffset.x, this.state.newContentOffset.y);
335
+ }
336
+ };
337
+
338
+ _renderList = () => {
339
+ let data = [];
340
+
341
+ if (this.props.singlePage) {
342
+ data[0] = {key: this.props.currentPage >= 0 ? this.props.currentPage : 0}
343
+ } else {
344
+ for (let i = 0; i < this.state.numberOfPages; i++) {
345
+ data[i] = {key: i};
346
+ }
347
+ }
348
+
349
+ return (
350
+ <PdfViewFlatList
351
+ ref={this._getRef}
352
+ style={[styles.container, this.props.style]}
353
+ pagingEnabled={this.props.enablePaging}
354
+ contentContainerStyle={[{
355
+ justifyContent: 'center',
356
+ alignItems: 'center'
357
+ }, this.props.horizontal ? {height: this.state.contentContainerSize.height * this.state.scale} : {width: this.state.contentContainerSize.width * this.state.scale}]}
358
+ horizontal={this.props.horizontal}
359
+ data={data}
360
+ renderItem={this._renderItem}
361
+ keyExtractor={this._keyExtractor}
362
+ windowSize={11}
363
+ getItemLayout={this._getItemLayout}
364
+ maxToRenderPerBatch={1}
365
+ renderScrollComponent={(props) => <ScrollView
366
+ {...props}
367
+ centerContent={this.state.centerContent}
368
+ pinchGestureEnabled={false}
369
+ />}
370
+ initialScrollIndex={this.props.page < 1 ? 0 : this.props.page - 1}
371
+ onViewableItemsChanged={this._onViewableItemsChanged}
372
+ viewabilityConfig={VIEWABILITYCONFIG}
373
+ onScroll={this._onScroll}
374
+ onContentSizeChange={this._onListContentSizeChange}
375
+ scrollEnabled={!this.props.singlePage}
376
+ />
377
+ );
378
+
379
+ };
380
+
381
+ _onLayout = (event) => {
382
+ this.setState({
383
+ contentContainerSize: {
384
+ width: event.nativeEvent.layout.width,
385
+ height: event.nativeEvent.layout.height
386
+ }
387
+ });
388
+ };
389
+
390
+
391
+ render() {
392
+ if (this.props.singlePage) {
393
+ return (
394
+ <View
395
+ style={styles.container}
396
+ onLayout={this._onLayout}
397
+ >
398
+ {this.state.pdfLoaded && this._renderList()}
399
+ </View>
400
+ )
401
+ }
402
+
403
+ return (
404
+ <PinchZoomView
405
+ style={styles.container}
406
+ onLayout={this._onLayout}
407
+ onScaleChanged={this._onScaleChanged}
408
+ >
409
+ {this.state.pdfLoaded && this._renderList()}
410
+ </PinchZoomView>
411
+ );
412
+
413
+ }
414
+
415
+ }
416
+
417
+ const styles = StyleSheet.create({
418
+ container: {
419
+ flex: 1
420
+ }
421
+ });
@@ -0,0 +1,30 @@
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 {
11
+ FlatList,
12
+ } from 'react-native';
13
+
14
+ export default class PdfViewFlatList extends FlatList {
15
+ /**
16
+ * Scrolls to a given x, y offset, either immediately or with a smooth animation.
17
+ *
18
+ * Example:
19
+ *
20
+ * `scrollTo({x: 0, y: 0, animated: true})`
21
+ *
22
+ * Note: The weird function signature is due to the fact that, for historical reasons,
23
+ * the function also accepts separate arguments as an alternative to the options object.
24
+ * This is deprecated due to ambiguity (y before x), and SHOULD NOT BE USED.
25
+ */
26
+ scrollToXY = (x, y) => {
27
+ this._listRef._scrollRef.scrollTo({x: x, y: y, animated: false});
28
+ }
29
+
30
+ }
@@ -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 PropTypes from 'prop-types';
12
+ import {
13
+ View,
14
+ StyleSheet,
15
+ PanResponder
16
+ } from 'react-native';
17
+ import {ViewPropTypes} from 'deprecated-react-native-prop-types';
18
+ export default class PinchZoomView extends Component {
19
+
20
+ static propTypes = {
21
+ ...ViewPropTypes,
22
+ scalable: PropTypes.bool,
23
+ onScaleChanged: PropTypes.func,
24
+ };
25
+
26
+ static defaultProps = {
27
+ scalable: true,
28
+ onScaleChanged: (scale) => {
29
+ },
30
+ };
31
+
32
+ constructor(props) {
33
+
34
+ super(props);
35
+ this.state = {};
36
+ this.distant = 0;
37
+ this.gestureHandlers = PanResponder.create({
38
+ onStartShouldSetPanResponder: this._handleStartShouldSetPanResponder,
39
+ onMoveShouldSetResponderCapture: (evt, gestureState) => (true),
40
+ onMoveShouldSetPanResponder: this._handleMoveShouldSetPanResponder,
41
+ onPanResponderGrant: this._handlePanResponderGrant,
42
+ onPanResponderMove: this._handlePanResponderMove,
43
+ onPanResponderRelease: this._handlePanResponderEnd,
44
+ onPanResponderTerminationRequest: evt => false,
45
+ onPanResponderTerminate: this._handlePanResponderTerminate,
46
+ onShouldBlockNativeResponder: evt => true
47
+ });
48
+
49
+ }
50
+
51
+ _handleStartShouldSetPanResponder = (e, gestureState) => {
52
+
53
+ // don't respond to single touch to avoid shielding click on child components
54
+ return false;
55
+
56
+ };
57
+
58
+ _handleMoveShouldSetPanResponder = (e, gestureState) => {
59
+
60
+ return this.props.scalable && (e.nativeEvent.changedTouches.length >= 2 || gestureState.numberActiveTouches >= 2);
61
+
62
+ };
63
+
64
+ _handlePanResponderGrant = (e, gestureState) => {
65
+
66
+ if (e.nativeEvent.changedTouches.length >= 2 || gestureState.numberActiveTouches >= 2) {
67
+ let dx = Math.abs(e.nativeEvent.touches[0].pageX - e.nativeEvent.touches[1].pageX);
68
+ let dy = Math.abs(e.nativeEvent.touches[0].pageY - e.nativeEvent.touches[1].pageY);
69
+ this.distant = Math.sqrt(dx * dx + dy * dy);
70
+ }
71
+
72
+ };
73
+
74
+ _handlePanResponderEnd = (e, gestureState) => {
75
+
76
+ this.distant = 0;
77
+
78
+ };
79
+
80
+ _handlePanResponderTerminate = (e, gestureState) => {
81
+
82
+ this.distant = 0;
83
+
84
+ };
85
+
86
+ _handlePanResponderMove = (e, gestureState) => {
87
+
88
+ if ((e.nativeEvent.changedTouches.length >= 2 || gestureState.numberActiveTouches >= 2) && this.distant > 100) {
89
+
90
+ let dx = Math.abs(e.nativeEvent.touches[0].pageX - e.nativeEvent.touches[1].pageX);
91
+ let dy = Math.abs(e.nativeEvent.touches[0].pageY - e.nativeEvent.touches[1].pageY);
92
+ let distant = Math.sqrt(dx * dx + dy * dy);
93
+ let scale = (distant / this.distant);
94
+ let pageX = (e.nativeEvent.touches[0].pageX + e.nativeEvent.touches[1].pageX) / 2;
95
+ let pageY = (e.nativeEvent.touches[0].pageY + e.nativeEvent.touches[1].pageY) / 2;
96
+ let pinchInfo = {scale: scale, pageX: pageX, pageY: pageY};
97
+
98
+ this.props.onScaleChanged(pinchInfo);
99
+ this.distant = distant;
100
+
101
+ }
102
+
103
+ };
104
+
105
+ render() {
106
+
107
+ return (
108
+ <View
109
+ {...this.props}
110
+ {...this.gestureHandlers?.panHandlers}
111
+ style={[styles.container, this.props.style]}>
112
+ {this.props.children}
113
+ </View>
114
+ );
115
+
116
+ }
117
+ }
118
+
119
+ const styles = StyleSheet.create({
120
+ container: {
121
+ flex: 1,
122
+ justifyContent: 'center',
123
+ alignItems: 'center'
124
+ }
125
+ });