1
1
import React , { PureComponent } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
- import { View } from 'react-native' ;
3
+ import { View , Dimensions } from 'react-native' ;
4
4
import { Document , Page } from 'react-pdf/dist/esm/entry.webpack' ;
5
5
import styles from '../../styles/styles' ;
6
6
import withWindowDimensions , { windowDimensionsPropTypes } from '../withWindowDimensions' ;
@@ -28,6 +28,7 @@ class PDFView extends PureComponent {
28
28
super ( props ) ;
29
29
this . state = {
30
30
numPages : null ,
31
+ windowWidth : Dimensions . get ( 'window' ) . width ,
31
32
} ;
32
33
this . onDocumentLoadSuccess = this . onDocumentLoadSuccess . bind ( this ) ;
33
34
}
@@ -43,15 +44,16 @@ class PDFView extends PureComponent {
43
44
}
44
45
45
46
render ( ) {
46
- const { isSmallScreenWidth, windowWidth } = this . props ;
47
- const pdfContainerWidth = windowWidth - 100 ;
47
+ const { isSmallScreenWidth} = this . props ;
48
+ const pdfContainerWidth = this . state . windowWidth - 100 ;
48
49
const pageWidthOnLargeScreen = ( pdfContainerWidth <= variables . pdfPageMaxWidth )
49
50
? pdfContainerWidth : variables . pdfPageMaxWidth ;
50
- const pageWidth = isSmallScreenWidth ? windowWidth - 30 : pageWidthOnLargeScreen ;
51
+ const pageWidth = isSmallScreenWidth ? this . state . windowWidth - 30 : pageWidthOnLargeScreen ;
51
52
52
53
return (
53
54
< View
54
55
style = { [ styles . PDFView , this . props . style ] }
56
+ onLayout = { event => this . setState ( { windowWidth : event . nativeEvent . layout . width } ) }
55
57
>
56
58
< Document
57
59
loading = { < FullScreenLoadingIndicator /> }
0 commit comments