Skip to content

Commit

Permalink
Merge pull request #5775 from eVoloshchak/eVoloshchak-safariZoom
Browse files Browse the repository at this point in the history
Use pdf container width instead of windows width to calculate page width
  • Loading branch information
AndrewGable authored Oct 18, 2021
2 parents 61bbde6 + b0c6b90 commit 1d1323c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/components/PDFView/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {View} from 'react-native';
import {View, Dimensions} from 'react-native';
import {Document, Page} from 'react-pdf/dist/esm/entry.webpack';
import styles from '../../styles/styles';
import withWindowDimensions, {windowDimensionsPropTypes} from '../withWindowDimensions';
Expand Down Expand Up @@ -28,6 +28,7 @@ class PDFView extends PureComponent {
super(props);
this.state = {
numPages: null,
windowWidth: Dimensions.get('window').width,
};
this.onDocumentLoadSuccess = this.onDocumentLoadSuccess.bind(this);
}
Expand All @@ -43,15 +44,16 @@ class PDFView extends PureComponent {
}

render() {
const {isSmallScreenWidth, windowWidth} = this.props;
const pdfContainerWidth = windowWidth - 100;
const {isSmallScreenWidth} = this.props;
const pdfContainerWidth = this.state.windowWidth - 100;
const pageWidthOnLargeScreen = (pdfContainerWidth <= variables.pdfPageMaxWidth)
? pdfContainerWidth : variables.pdfPageMaxWidth;
const pageWidth = isSmallScreenWidth ? windowWidth - 30 : pageWidthOnLargeScreen;
const pageWidth = isSmallScreenWidth ? this.state.windowWidth - 30 : pageWidthOnLargeScreen;

return (
<View
style={[styles.PDFView, this.props.style]}
onLayout={event => this.setState({windowWidth: event.nativeEvent.layout.width})}
>
<Document
loading={<FullScreenLoadingIndicator />}
Expand Down

0 comments on commit 1d1323c

Please sign in to comment.