Skip to content

Commit 1d1323c

Browse files
authored
Merge pull request #5775 from eVoloshchak/eVoloshchak-safariZoom
Use pdf container width instead of windows width to calculate page width
2 parents 61bbde6 + b0c6b90 commit 1d1323c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/components/PDFView/index.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {PureComponent} from 'react';
22
import PropTypes from 'prop-types';
3-
import {View} from 'react-native';
3+
import {View, Dimensions} from 'react-native';
44
import {Document, Page} from 'react-pdf/dist/esm/entry.webpack';
55
import styles from '../../styles/styles';
66
import withWindowDimensions, {windowDimensionsPropTypes} from '../withWindowDimensions';
@@ -28,6 +28,7 @@ class PDFView extends PureComponent {
2828
super(props);
2929
this.state = {
3030
numPages: null,
31+
windowWidth: Dimensions.get('window').width,
3132
};
3233
this.onDocumentLoadSuccess = this.onDocumentLoadSuccess.bind(this);
3334
}
@@ -43,15 +44,16 @@ class PDFView extends PureComponent {
4344
}
4445

4546
render() {
46-
const {isSmallScreenWidth, windowWidth} = this.props;
47-
const pdfContainerWidth = windowWidth - 100;
47+
const {isSmallScreenWidth} = this.props;
48+
const pdfContainerWidth = this.state.windowWidth - 100;
4849
const pageWidthOnLargeScreen = (pdfContainerWidth <= variables.pdfPageMaxWidth)
4950
? pdfContainerWidth : variables.pdfPageMaxWidth;
50-
const pageWidth = isSmallScreenWidth ? windowWidth - 30 : pageWidthOnLargeScreen;
51+
const pageWidth = isSmallScreenWidth ? this.state.windowWidth - 30 : pageWidthOnLargeScreen;
5152

5253
return (
5354
<View
5455
style={[styles.PDFView, this.props.style]}
56+
onLayout={event => this.setState({windowWidth: event.nativeEvent.layout.width})}
5557
>
5658
<Document
5759
loading={<FullScreenLoadingIndicator />}

0 commit comments

Comments
 (0)