react-native-pdf 6.3.0 → 6.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -69
- package/android/.gradle/5.6.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/5.6.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/5.6.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/build.gradle +3 -3
- package/android/src/main/java/org/wonday/pdf/PdfView.java +21 -2
- package/ios/RCTPdf/PdfManager.m +11 -1
- package/ios/RCTPdf/RCTPdfView.h +2 -0
- package/ios/RCTPdf/RCTPdfView.m +21 -5
- package/ios/RCTPdf/RCTPdfViewManager.m +1 -1
- package/ios/RCTPdf.xcodeproj/xcuserdata/wonday.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/package.json +18 -6
- package/windows/RCTPdf/RCTPdfControl.xaml +0 -1
- package/windows/README.md +4 -8
- package/.babelrc +0 -3
- package/.github/workflows/windows-ci.yml +0 -39
- package/DoubleTapView.js +0 -126
- package/PdfManager.js +0 -31
- package/PdfPageView.js +0 -54
- package/PdfView.js +0 -416
- package/PdfViewFlatList.js +0 -31
- package/PinchZoomView.js +0 -126
- package/example/.eslintrc.js +0 -4
- package/example/PDFExample.js +0 -180
- package/example/__windows_tests__/TestPDF.js +0 -43
- package/example/android/app/BUCK +0 -55
- package/example/android/app/build.gradle +0 -210
- package/example/android/app/build_defs.bzl +0 -19
- package/example/android/app/proguard-rules.pro +0 -10
- package/example/android/app/src/debug/AndroidManifest.xml +0 -8
- package/example/android/app/src/main/AndroidManifest.xml +0 -26
- package/example/android/app/src/main/assets/test.pdf +0 -0
- package/example/android/app/src/main/java/com/pdfexample/MainActivity.java +0 -15
- package/example/android/app/src/main/java/com/pdfexample/MainApplication.java +0 -49
- package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/values/strings.xml +0 -3
- package/example/android/app/src/main/res/values/styles.xml +0 -9
- package/example/android/build.gradle +0 -38
- package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/example/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/example/android/gradle.properties +0 -21
- package/example/android/gradlew +0 -188
- package/example/android/gradlew.bat +0 -100
- package/example/android/settings.gradle +0 -3
- package/example/app.json +0 -4
- package/example/babel.config.js +0 -3
- package/example/index.js +0 -9
- package/example/ios/PDFExample/AppDelegate.h +0 -15
- package/example/ios/PDFExample/AppDelegate.m +0 -42
- package/example/ios/PDFExample/Base.lproj/LaunchScreen.xib +0 -42
- package/example/ios/PDFExample/Images.xcassets/AppIcon.appiconset/Contents.json +0 -38
- package/example/ios/PDFExample/Images.xcassets/Contents.json +0 -6
- package/example/ios/PDFExample/Info.plist +0 -57
- package/example/ios/PDFExample/main.m +0 -16
- package/example/ios/PDFExample-tvOS/Info.plist +0 -53
- package/example/ios/PDFExample-tvOSTests/Info.plist +0 -24
- package/example/ios/PDFExample.xcodeproj/project.pbxproj +0 -923
- package/example/ios/PDFExample.xcodeproj/xcshareddata/xcschemes/PDFExample-tvOS.xcscheme +0 -129
- package/example/ios/PDFExample.xcodeproj/xcshareddata/xcschemes/PDFExample.xcscheme +0 -129
- package/example/ios/PDFExample.xcworkspace/contents.xcworkspacedata +0 -10
- package/example/ios/PDFExampleTests/Info.plist +0 -24
- package/example/ios/PDFExampleTests/PDFExampleTests.m +0 -68
- package/example/ios/Podfile +0 -47
- package/example/ios/Podfile.lock +0 -205
- package/example/jest-windows/driver.setup.js +0 -12
- package/example/jest-windows/jest.setup.js +0 -1
- package/example/jest.windows.config.js +0 -4
- package/example/metro.config.js +0 -29
- package/example/package.json +0 -48
- package/example/test.pdf +0 -0
- package/example/windows/PDFExample/App.cpp +0 -80
- package/example/windows/PDFExample/App.h +0 -20
- package/example/windows/PDFExample/App.idl +0 -3
- package/example/windows/PDFExample/App.xaml +0 -10
- package/example/windows/PDFExample/Assets/LockScreenLogo.scale-200.png +0 -0
- package/example/windows/PDFExample/Assets/SplashScreen.scale-200.png +0 -0
- package/example/windows/PDFExample/Assets/Square150x150Logo.scale-200.png +0 -0
- package/example/windows/PDFExample/Assets/Square44x44Logo.scale-200.png +0 -0
- package/example/windows/PDFExample/Assets/Square44x44Logo.targetsize-24_altform-unplated.png +0 -0
- package/example/windows/PDFExample/Assets/StoreLogo.png +0 -0
- package/example/windows/PDFExample/Assets/Wide310x150Logo.scale-200.png +0 -0
- package/example/windows/PDFExample/AutolinkedNativeModules.g.cpp +0 -18
- package/example/windows/PDFExample/AutolinkedNativeModules.g.h +0 -10
- package/example/windows/PDFExample/AutolinkedNativeModules.g.props +0 -6
- package/example/windows/PDFExample/AutolinkedNativeModules.g.targets +0 -10
- package/example/windows/PDFExample/MainPage.cpp +0 -24
- package/example/windows/PDFExample/MainPage.h +0 -21
- package/example/windows/PDFExample/MainPage.idl +0 -8
- package/example/windows/PDFExample/MainPage.xaml +0 -16
- package/example/windows/PDFExample/PDFExample.vcxproj +0 -205
- package/example/windows/PDFExample/PDFExample.vcxproj.filters +0 -64
- package/example/windows/PDFExample/PDFExample_TemporaryKey.pfx +0 -0
- package/example/windows/PDFExample/Package.appxmanifest +0 -52
- package/example/windows/PDFExample/PropertySheet.props +0 -16
- package/example/windows/PDFExample/ReactPackageProvider.cpp +0 -18
- package/example/windows/PDFExample/ReactPackageProvider.h +0 -15
- package/example/windows/PDFExample/packages.config +0 -5
- package/example/windows/PDFExample/pch.cpp +0 -1
- package/example/windows/PDFExample/pch.h +0 -29
- package/example/windows/PDFExample.sln +0 -264
- package/index.d.ts +0 -51
- package/index.js +0 -493
- package/index.js.flow +0 -63
- package/issue_template.md +0 -13
package/DoubleTapView.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
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
|
-
ViewPropTypes,
|
|
15
|
-
} from 'react-native';
|
|
16
|
-
import PropTypes from 'prop-types';
|
|
17
|
-
|
|
18
|
-
export default class DoubleTapView extends Component {
|
|
19
|
-
|
|
20
|
-
static propTypes = {
|
|
21
|
-
...ViewPropTypes,
|
|
22
|
-
delay: PropTypes.number,
|
|
23
|
-
radius: PropTypes.number,
|
|
24
|
-
onSingleTap: PropTypes.func,
|
|
25
|
-
onDoubleTap: PropTypes.func,
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
static defaultProps = {
|
|
29
|
-
delay: 300,
|
|
30
|
-
radius: 50,
|
|
31
|
-
onSingleTap: () => {
|
|
32
|
-
},
|
|
33
|
-
onDoubleTap: () => {
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
constructor() {
|
|
38
|
-
super();
|
|
39
|
-
|
|
40
|
-
this.gestureHandlers = PanResponder.create({
|
|
41
|
-
onStartShouldSetPanResponder: (evt, gestureState) => (gestureState.numberActiveTouches === 1),
|
|
42
|
-
onStartShouldSetResponderCapture: (evt, gestureState) => (gestureState.numberActiveTouches === 1),
|
|
43
|
-
onMoveShouldSetPanResponder: (evt, gestureState) => (false),
|
|
44
|
-
onMoveShouldSetResponderCapture: (evt, gestureState) => (false),
|
|
45
|
-
onPanResponderTerminationRequest: (evt, gestureState) => false,
|
|
46
|
-
onPanResponderRelease: this.handlePanResponderRelease,
|
|
47
|
-
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
this.prevTouchInfo = {
|
|
51
|
-
prevTouchX: 0,
|
|
52
|
-
prevTouchY: 0,
|
|
53
|
-
prevTouchTimeStamp: 0,
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
this.timer = null;
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
distance = (x0, y0, x1, y1) => {
|
|
62
|
-
return Math.sqrt(Math.pow((x1 - x0), 2) + Math.pow((y1 - y0), 2)).toFixed(1);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
isDoubleTap = (currentTouchTimeStamp, {x0, y0}) => {
|
|
66
|
-
const {prevTouchX, prevTouchY, prevTouchTimeStamp} = this.prevTouchInfo;
|
|
67
|
-
const dt = currentTouchTimeStamp - prevTouchTimeStamp;
|
|
68
|
-
const {delay, radius} = this.props;
|
|
69
|
-
|
|
70
|
-
return (prevTouchTimeStamp > 0 && dt < delay && this.distance(prevTouchX, prevTouchY, x0, y0) < radius);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
handlePanResponderRelease = (evt, gestureState) => {
|
|
74
|
-
|
|
75
|
-
const currentTouchTimeStamp = Date.now();
|
|
76
|
-
const x = evt.nativeEvent.locationX;
|
|
77
|
-
const y = evt.nativeEvent.locationY;
|
|
78
|
-
|
|
79
|
-
if (this.timer) {
|
|
80
|
-
|
|
81
|
-
if (this.isDoubleTap(currentTouchTimeStamp, gestureState)) {
|
|
82
|
-
|
|
83
|
-
clearTimeout(this.timer);
|
|
84
|
-
this.timer = null;
|
|
85
|
-
this.props.onDoubleTap();
|
|
86
|
-
|
|
87
|
-
} else {
|
|
88
|
-
|
|
89
|
-
const {prevTouchX, prevTouchY, prevTouchTimeStamp} = this.prevTouchInfo;
|
|
90
|
-
const {radius} = this.props;
|
|
91
|
-
|
|
92
|
-
// if not in radius, it's a move
|
|
93
|
-
if (this.distance(prevTouchX, prevTouchY, gestureState.x0, gestureState.y0) < radius) {
|
|
94
|
-
this.timer = null;
|
|
95
|
-
this.props.onSingleTap(x, y);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
} else {
|
|
100
|
-
// do not count scroll gestures as taps
|
|
101
|
-
if (this.distance(0, gestureState.dx, 0, gestureState.dy) < 10) {
|
|
102
|
-
|
|
103
|
-
this.timer = setTimeout(() => {
|
|
104
|
-
this.props.onSingleTap(x, y);
|
|
105
|
-
this.timer = null;
|
|
106
|
-
}, this.props.delay);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
this.prevTouchInfo = {
|
|
112
|
-
prevTouchX: gestureState.x0,
|
|
113
|
-
prevTouchY: gestureState.y0,
|
|
114
|
-
prevTouchTimeStamp: currentTouchTimeStamp,
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
render() {
|
|
120
|
-
return (
|
|
121
|
-
<View {...this.props} {...this.gestureHandlers.panHandlers}>
|
|
122
|
-
{this.props.children}
|
|
123
|
-
</View>
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
}
|
package/PdfManager.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
const invariant = require('fbjs/lib/invariant');
|
|
11
|
-
const PdfManagerNative = require('react-native').NativeModules.PdfManager;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export default class PdfManager {
|
|
15
|
-
|
|
16
|
-
static loadFile(path: string,
|
|
17
|
-
password?: string,): Promise<string> {
|
|
18
|
-
|
|
19
|
-
invariant(
|
|
20
|
-
typeof path === 'string',
|
|
21
|
-
'path must be a valid string.',
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
if (password === undefined) {
|
|
25
|
-
password = "";
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return PdfManagerNative.loadFile(path, password);
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
}
|
package/PdfPageView.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
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
|
-
ViewPropTypes,
|
|
15
|
-
requireNativeComponent,
|
|
16
|
-
} from 'react-native';
|
|
17
|
-
|
|
18
|
-
export default class PdfPageView extends PureComponent {
|
|
19
|
-
_getStylePropsProps = () => {
|
|
20
|
-
const {width, height} = this.props;
|
|
21
|
-
if (width || height) {
|
|
22
|
-
return {width, height};
|
|
23
|
-
}
|
|
24
|
-
return {};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
render() {
|
|
28
|
-
const {
|
|
29
|
-
style,
|
|
30
|
-
...restProps
|
|
31
|
-
} = this.props;
|
|
32
|
-
return (
|
|
33
|
-
<PdfPageViewCustom
|
|
34
|
-
{...restProps}
|
|
35
|
-
style={[style, this._getStylePropsProps()]}
|
|
36
|
-
/>
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
PdfPageView.propTypes = {
|
|
43
|
-
...ViewPropTypes,
|
|
44
|
-
fileNo: PropTypes.number,
|
|
45
|
-
page: PropTypes.number,
|
|
46
|
-
width: PropTypes.number,
|
|
47
|
-
height: PropTypes.number
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
PdfPageView.defaultProps = {
|
|
51
|
-
style: {}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
let PdfPageViewCustom = requireNativeComponent('RCTPdfPageView', PdfPageView, {nativeOnly: {}});
|
package/PdfView.js
DELETED
|
@@ -1,416 +0,0 @@
|
|
|
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, ViewPropTypes} from 'react-native';
|
|
12
|
-
|
|
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
|
-
});
|
package/PdfViewFlatList.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
}
|