@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.
- package/DoubleTapView.js +125 -0
- package/LICENSE +21 -0
- package/PdfManager.js +26 -0
- package/PdfPageView.js +53 -0
- package/PdfView.js +417 -0
- package/PdfViewFlatList.js +30 -0
- package/PinchZoomView.js +125 -0
- package/README.OpenSource +11 -0
- package/README.md +13 -0
- package/fabric/RNPDFPdfNativeComponent.js +48 -0
- package/fabric/RTNPdfViewNativeComponent.ts +57 -0
- package/harmony/pdfview/BuildProfile.ets +17 -0
- package/harmony/pdfview/Index.ets +7 -0
- package/harmony/pdfview/build-profile.json5 +28 -0
- package/harmony/pdfview/consumer-rules.txt +0 -0
- package/harmony/pdfview/hvigorfile.ts +6 -0
- package/harmony/pdfview/obfuscation-rules.txt +18 -0
- package/harmony/pdfview/oh-package-lock.json5 +18 -0
- package/harmony/pdfview/oh-package.json5 +11 -0
- package/harmony/pdfview/src/main/cpp/CMakeLists.txt +8 -0
- package/harmony/pdfview/src/main/cpp/ComponentDescriptors.h +36 -0
- package/harmony/pdfview/src/main/cpp/EventEmitters.cpp +39 -0
- package/harmony/pdfview/src/main/cpp/EventEmitters.h +47 -0
- package/harmony/pdfview/src/main/cpp/PdfEventEmitRequestHandler.h +50 -0
- package/harmony/pdfview/src/main/cpp/PdfViewJSIBinder.h +71 -0
- package/harmony/pdfview/src/main/cpp/PdfViewPackage.h +55 -0
- package/harmony/pdfview/src/main/cpp/Props.cpp +58 -0
- package/harmony/pdfview/src/main/cpp/Props.h +61 -0
- package/harmony/pdfview/src/main/cpp/RTNPdfViewSpecsJSI-generated.cpp +34 -0
- package/harmony/pdfview/src/main/cpp/RTNPdfViewSpecsJSI.h +36 -0
- package/harmony/pdfview/src/main/cpp/ShadowNodes.cpp +33 -0
- package/harmony/pdfview/src/main/cpp/ShadowNodes.h +47 -0
- package/harmony/pdfview/src/main/cpp/States.cpp +33 -0
- package/harmony/pdfview/src/main/cpp/States.h +52 -0
- package/harmony/pdfview/src/main/ets/Logger.ets +64 -0
- package/harmony/pdfview/src/main/ets/components/mainpage/RTNPdfView.ets +513 -0
- package/harmony/pdfview/src/main/ets/components/mainpage/types.ts +15 -0
- package/harmony/pdfview/src/main/module.json5 +11 -0
- package/harmony/pdfview/src/main/resources/base/element/string.json +8 -0
- package/harmony/pdfview/src/main/resources/en_US/element/string.json +8 -0
- package/harmony/pdfview/src/main/resources/zh_CN/element/string.json +8 -0
- package/harmony/pdfview/src/test/List.test.ets +29 -0
- package/harmony/pdfview/src/test/LocalUnit.test.ets +57 -0
- package/harmony/pdfview.har +0 -0
- package/index.d.ts +72 -0
- package/index.js +491 -0
- package/index.js.flow +67 -0
- package/package.json +61 -0
- package/windows/RCTPdf/PropertySheet.props +16 -0
- package/windows/RCTPdf/RCTPdf.def +3 -0
- package/windows/RCTPdf/RCTPdf.vcxproj +180 -0
- package/windows/RCTPdf/RCTPdf.vcxproj.filters +38 -0
- package/windows/RCTPdf/RCTPdfControl.cpp +667 -0
- package/windows/RCTPdf/RCTPdfControl.h +119 -0
- package/windows/RCTPdf/RCTPdfControl.idl +10 -0
- package/windows/RCTPdf/RCTPdfControl.xaml +33 -0
- package/windows/RCTPdf/RCTPdfViewManager.cpp +69 -0
- package/windows/RCTPdf/RCTPdfViewManager.h +51 -0
- package/windows/RCTPdf/ReactPackageProvider.cpp +15 -0
- package/windows/RCTPdf/ReactPackageProvider.h +16 -0
- package/windows/RCTPdf/ReactPackageProvider.idl +9 -0
- package/windows/RCTPdf/packages.config +4 -0
- package/windows/RCTPdf/pch.cpp +1 -0
- package/windows/RCTPdf/pch.h +31 -0
- package/windows/README.md +21 -0
package/DoubleTapView.js
ADDED
|
@@ -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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Wonday (@wonday.org)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
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,417 @@
|
|
|
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
|
+
};
|
|
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
|
+
progressContainerStyle: {},
|
|
54
|
+
fitPolicy: 2,
|
|
55
|
+
horizontal: false,
|
|
56
|
+
centerContent: false,
|
|
57
|
+
page: 1,
|
|
58
|
+
currentPage: -1,
|
|
59
|
+
enablePaging: false,
|
|
60
|
+
singlePage: false,
|
|
61
|
+
onPageSingleTap: (page, x, y) => {
|
|
62
|
+
},
|
|
63
|
+
onScaleChanged: (scale) => {
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
constructor(props) {
|
|
68
|
+
|
|
69
|
+
super(props);
|
|
70
|
+
this.state = {
|
|
71
|
+
pdfLoaded: false,
|
|
72
|
+
fileNo: -1,
|
|
73
|
+
numberOfPages: 0,
|
|
74
|
+
page: -1,
|
|
75
|
+
currentPage: -1,
|
|
76
|
+
pageAspectRate: 0.5,
|
|
77
|
+
pdfPageSize: {width: 0, height: 0},
|
|
78
|
+
contentContainerSize: {width: 0, height: 0},
|
|
79
|
+
scale: this.props.scale,
|
|
80
|
+
contentOffset: {x: 0, y: 0},
|
|
81
|
+
newContentOffset: {x: 0, y: 0},
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
this._flatList = null;
|
|
85
|
+
this._scaleTimer = null;
|
|
86
|
+
this._scrollTimer = null;
|
|
87
|
+
this._mounted = false;
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
componentDidMount() {
|
|
92
|
+
this._mounted = true;
|
|
93
|
+
PdfManager.loadFile(this.props.path, this.props.password)
|
|
94
|
+
.then((pdfInfo) => {
|
|
95
|
+
if (this._mounted) {
|
|
96
|
+
const fileNo = pdfInfo[0];
|
|
97
|
+
const numberOfPages = pdfInfo[1];
|
|
98
|
+
const width = pdfInfo[2];
|
|
99
|
+
const height = pdfInfo[3];
|
|
100
|
+
const pageAspectRatio = height === 0 ? 1 : width / height;
|
|
101
|
+
|
|
102
|
+
this.setState({
|
|
103
|
+
pdfLoaded: true,
|
|
104
|
+
fileNo,
|
|
105
|
+
numberOfPages,
|
|
106
|
+
pageAspectRate: pageAspectRatio,
|
|
107
|
+
pdfPageSize: {width, height},
|
|
108
|
+
centerContent: numberOfPages > 1 ? false : true
|
|
109
|
+
});
|
|
110
|
+
if (this.props.onLoadComplete) {
|
|
111
|
+
this.props.onLoadComplete(numberOfPages, this.props.path, {width, height});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
})
|
|
116
|
+
.catch((error) => {
|
|
117
|
+
this.props.onError(error);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
clearTimeout(this._scrollTimer);
|
|
121
|
+
this._scrollTimer = setTimeout(() => {
|
|
122
|
+
if (this._flatList) {
|
|
123
|
+
this._flatList.scrollToIndex({animated: false, index: this.props.page < 1 ? 0 : this.props.page - 1});
|
|
124
|
+
}
|
|
125
|
+
}, 200);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
componentDidUpdate(prevProps) {
|
|
129
|
+
|
|
130
|
+
if (this.props.scale !== this.state.scale) {
|
|
131
|
+
this._onScaleChanged({
|
|
132
|
+
scale: this.props.scale / this.state.scale,
|
|
133
|
+
pageX: this.state.contentContainerSize.width / 2,
|
|
134
|
+
pageY: this.state.contentContainerSize.height / 2
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (this.props.horizontal !== prevProps.horizontal || this.props.page !== prevProps.page) {
|
|
139
|
+
let page = (this.props.page) < 1 ? 1 : this.props.page;
|
|
140
|
+
page = page > this.state.numberOfPages ? this.state.numberOfPages : page;
|
|
141
|
+
|
|
142
|
+
if (this._flatList) {
|
|
143
|
+
clearTimeout(this._scrollTimer);
|
|
144
|
+
this._scrollTimer = setTimeout(() => {
|
|
145
|
+
this._flatList.scrollToIndex({animated: false, index: page - 1});
|
|
146
|
+
}, 200);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
componentWillUnmount() {
|
|
153
|
+
this._mounted = false;
|
|
154
|
+
clearTimeout(this._scaleTimer);
|
|
155
|
+
clearTimeout(this._scrollTimer);
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
_keyExtractor = (item, index) => "pdf-page-" + index;
|
|
160
|
+
|
|
161
|
+
_getPageWidth = () => {
|
|
162
|
+
|
|
163
|
+
let fitPolicy = this.props.fitPolicy;
|
|
164
|
+
|
|
165
|
+
// if only one page, show whole page in center
|
|
166
|
+
if (this.state.numberOfPages === 1 || this.props.singlePage) {
|
|
167
|
+
fitPolicy = 2;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
switch (fitPolicy) {
|
|
172
|
+
case 0: //fit width
|
|
173
|
+
return this.state.contentContainerSize.width * this.state.scale;
|
|
174
|
+
case 1: //fit height
|
|
175
|
+
return this.state.contentContainerSize.height * this.state.pageAspectRate * this.state.scale;
|
|
176
|
+
case 2: //fit both
|
|
177
|
+
default: {
|
|
178
|
+
if (this.state.contentContainerSize.width/this.state.contentContainerSize.height<this.state.pageAspectRate) {
|
|
179
|
+
return this.state.contentContainerSize.width * this.state.scale;
|
|
180
|
+
} else {
|
|
181
|
+
return this.state.contentContainerSize.height * this.state.pageAspectRate * this.state.scale;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
_getPageHeight = () => {
|
|
189
|
+
|
|
190
|
+
let fitPolicy = this.props.fitPolicy;
|
|
191
|
+
|
|
192
|
+
// if only one page, show whole page in center
|
|
193
|
+
if (this.state.numberOfPages === 1 || this.props.singlePage) {
|
|
194
|
+
fitPolicy = 2;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
switch (fitPolicy) {
|
|
198
|
+
case 0: //fit width
|
|
199
|
+
return this.state.contentContainerSize.width * (1 / this.state.pageAspectRate) * this.state.scale;
|
|
200
|
+
case 1: //fit height
|
|
201
|
+
return this.state.contentContainerSize.height * this.state.scale;
|
|
202
|
+
case 2: //fit both
|
|
203
|
+
default: {
|
|
204
|
+
if (this.state.contentContainerSize.width/this.state.contentContainerSize.height<this.state.pageAspectRate) {
|
|
205
|
+
return this.state.contentContainerSize.width * (1 / this.state.pageAspectRate) * this.state.scale;
|
|
206
|
+
} else {
|
|
207
|
+
return this.state.contentContainerSize.height * this.state.scale;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
_renderSeparator = () => (
|
|
215
|
+
<View style={this.props.horizontal ? {
|
|
216
|
+
width: this.props.spacing * this.state.scale,
|
|
217
|
+
backgroundColor: 'transparent'
|
|
218
|
+
} : {
|
|
219
|
+
height: this.props.spacing * this.state.scale,
|
|
220
|
+
backgroundColor: 'transparent'
|
|
221
|
+
}}/>
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
_onItemSingleTap = (index, x, y) => {
|
|
225
|
+
|
|
226
|
+
this.props.onPageSingleTap(index + 1, x, y);
|
|
227
|
+
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
_onItemDoubleTap = (index) => {
|
|
231
|
+
|
|
232
|
+
if (this.state.scale >= this.props.maxScale) {
|
|
233
|
+
this._onScaleChanged({
|
|
234
|
+
scale: 1 / this.state.scale,
|
|
235
|
+
pageX: this.state.contentContainerSize.width / 2,
|
|
236
|
+
pageY: this.state.contentContainerSize.height / 2
|
|
237
|
+
});
|
|
238
|
+
} else {
|
|
239
|
+
this._onScaleChanged({
|
|
240
|
+
scale: 1.2,
|
|
241
|
+
pageX: this.state.contentContainerSize.width / 2,
|
|
242
|
+
pageY: this.state.contentContainerSize.height / 2
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
_onScaleChanged = (pinchInfo) => {
|
|
249
|
+
|
|
250
|
+
let newScale = pinchInfo.scale * this.state.scale;
|
|
251
|
+
newScale = newScale > this.props.maxScale ? this.props.maxScale : newScale;
|
|
252
|
+
newScale = newScale < this.props.minScale ? this.props.minScale : newScale;
|
|
253
|
+
let newContentOffset = {
|
|
254
|
+
x: (this.state.contentOffset.x + pinchInfo.pageX) * (newScale / this.state.scale) - pinchInfo.pageX,
|
|
255
|
+
y: (this.state.contentOffset.y + pinchInfo.pageY) * (newScale / this.state.scale) - pinchInfo.pageY
|
|
256
|
+
}
|
|
257
|
+
this.setState({scale: newScale, newContentOffset: newContentOffset});
|
|
258
|
+
this.props.onScaleChanged(newScale);
|
|
259
|
+
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
_renderItem = ({item, index}) => {
|
|
263
|
+
const pageView = (
|
|
264
|
+
<PdfPageView
|
|
265
|
+
accessible={true}
|
|
266
|
+
key={item.id}
|
|
267
|
+
fileNo={this.state.fileNo}
|
|
268
|
+
page={item.key + 1}
|
|
269
|
+
width={this._getPageWidth()}
|
|
270
|
+
height={this._getPageHeight()}
|
|
271
|
+
/>
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
if (this.props.singlePage) {
|
|
275
|
+
return (
|
|
276
|
+
<View style={{flexDirection: this.props.horizontal ? 'row' : 'column'}} >
|
|
277
|
+
{pageView}
|
|
278
|
+
</View>
|
|
279
|
+
)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return (
|
|
283
|
+
<DoubleTapView style={{flexDirection: this.props.horizontal ? 'row' : 'column'}}
|
|
284
|
+
onSingleTap={(x, y) => {
|
|
285
|
+
this._onItemSingleTap(index, x, y);
|
|
286
|
+
}}
|
|
287
|
+
onDoubleTap={() => {
|
|
288
|
+
this._onItemDoubleTap(index);
|
|
289
|
+
}}
|
|
290
|
+
>
|
|
291
|
+
{pageView}
|
|
292
|
+
{(index !== this.state.numberOfPages - 1) && this._renderSeparator()}
|
|
293
|
+
</DoubleTapView>
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
_onViewableItemsChanged = (viewableInfo) => {
|
|
299
|
+
|
|
300
|
+
for (let i = 0; i < viewableInfo.viewableItems.length; i++) {
|
|
301
|
+
this._onPageChanged(viewableInfo.viewableItems[i].index + 1, this.state.numberOfPages);
|
|
302
|
+
if (viewableInfo.viewableItems.length + viewableInfo.viewableItems[0].index < this.state.numberOfPages) break;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
_onPageChanged = (page, numberOfPages) => {
|
|
308
|
+
if (this.props.onPageChanged && this.state.currentPage !== page) {
|
|
309
|
+
this.props.onPageChanged(page, numberOfPages);
|
|
310
|
+
this.setState({currentPage: page});
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
_getRef = (ref) => this._flatList = ref;
|
|
316
|
+
|
|
317
|
+
_getItemLayout = (data, index) => ({
|
|
318
|
+
length: this.props.horizontal ? this._getPageWidth() : this._getPageHeight(),
|
|
319
|
+
offset: ((this.props.horizontal ? this._getPageWidth() : this._getPageHeight()) + this.props.spacing * this.state.scale) * index,
|
|
320
|
+
index
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
_onScroll = (e) => {
|
|
324
|
+
this.setState({contentOffset: e.nativeEvent.contentOffset, newContentOffset: e.nativeEvent.contentOffset});
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
_onListContentSizeChange = (contentWidth, contentHeight) => {
|
|
328
|
+
if (this.state.contentOffset.x != this.state.newContentOffset.x
|
|
329
|
+
|| this.state.contentOffset.y != this.state.newContentOffset.y) {
|
|
330
|
+
this._flatList.scrollToXY(this.state.newContentOffset.x, this.state.newContentOffset.y);
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
_renderList = () => {
|
|
335
|
+
let data = [];
|
|
336
|
+
|
|
337
|
+
if (this.props.singlePage) {
|
|
338
|
+
data[0] = {key: this.props.currentPage >= 0 ? this.props.currentPage : 0}
|
|
339
|
+
} else {
|
|
340
|
+
for (let i = 0; i < this.state.numberOfPages; i++) {
|
|
341
|
+
data[i] = {key: i};
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
return (
|
|
346
|
+
<PdfViewFlatList
|
|
347
|
+
ref={this._getRef}
|
|
348
|
+
style={[styles.container, this.props.style]}
|
|
349
|
+
pagingEnabled={this.props.enablePaging}
|
|
350
|
+
contentContainerStyle={[{
|
|
351
|
+
justifyContent: 'center',
|
|
352
|
+
alignItems: 'center'
|
|
353
|
+
}, this.props.horizontal ? {height: this.state.contentContainerSize.height * this.state.scale} : {width: this.state.contentContainerSize.width * this.state.scale}]}
|
|
354
|
+
horizontal={this.props.horizontal}
|
|
355
|
+
data={data}
|
|
356
|
+
renderItem={this._renderItem}
|
|
357
|
+
keyExtractor={this._keyExtractor}
|
|
358
|
+
windowSize={11}
|
|
359
|
+
getItemLayout={this._getItemLayout}
|
|
360
|
+
maxToRenderPerBatch={1}
|
|
361
|
+
renderScrollComponent={(props) => <ScrollView
|
|
362
|
+
{...props}
|
|
363
|
+
centerContent={this.state.centerContent}
|
|
364
|
+
pinchGestureEnabled={false}
|
|
365
|
+
/>}
|
|
366
|
+
initialScrollIndex={this.props.page < 1 ? 0 : this.props.page - 1}
|
|
367
|
+
onViewableItemsChanged={this._onViewableItemsChanged}
|
|
368
|
+
viewabilityConfig={VIEWABILITYCONFIG}
|
|
369
|
+
onScroll={this._onScroll}
|
|
370
|
+
onContentSizeChange={this._onListContentSizeChange}
|
|
371
|
+
scrollEnabled={!this.props.singlePage}
|
|
372
|
+
/>
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
_onLayout = (event) => {
|
|
378
|
+
this.setState({
|
|
379
|
+
contentContainerSize: {
|
|
380
|
+
width: event.nativeEvent.layout.width,
|
|
381
|
+
height: event.nativeEvent.layout.height
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
render() {
|
|
388
|
+
if (this.props.singlePage) {
|
|
389
|
+
return (
|
|
390
|
+
<View
|
|
391
|
+
style={styles.container}
|
|
392
|
+
onLayout={this._onLayout}
|
|
393
|
+
>
|
|
394
|
+
{this.state.pdfLoaded && this._renderList()}
|
|
395
|
+
</View>
|
|
396
|
+
)
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return (
|
|
400
|
+
<PinchZoomView
|
|
401
|
+
style={styles.container}
|
|
402
|
+
onLayout={this._onLayout}
|
|
403
|
+
onScaleChanged={this._onScaleChanged}
|
|
404
|
+
>
|
|
405
|
+
{this.state.pdfLoaded && this._renderList()}
|
|
406
|
+
</PinchZoomView>
|
|
407
|
+
);
|
|
408
|
+
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const styles = StyleSheet.create({
|
|
414
|
+
container: {
|
|
415
|
+
flex: 1
|
|
416
|
+
}
|
|
417
|
+
});
|
|
@@ -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
|
+
}
|