@@ -18,15 +18,18 @@ export const isOrientationLandscape = ({ width, height }: DimensionsType) =>
1818export default function withDimensions < Props extends InjectedProps > (
1919 WrappedComponent : React . ComponentType < Props >
2020) : React . ComponentType < Pick < Props , Exclude < keyof Props , keyof InjectedProps > > > {
21- const { width, height } = Dimensions . get ( 'window' ) ;
22-
2321 class EnhancedComponent extends React . Component {
2422 static displayName = `withDimensions(${ WrappedComponent . displayName } )` ;
2523
26- state = {
27- dimensions : { width, height } ,
28- isLandscape : isOrientationLandscape ( { width, height } ) ,
29- } ;
24+ constructor ( props : Props ) {
25+ super ( props ) ;
26+
27+ const { width, height } = Dimensions . get ( 'window' ) ;
28+ this . state = {
29+ dimensions : { width, height } ,
30+ isLandscape : isOrientationLandscape ( { width, height } ) ,
31+ } ;
32+ }
3033
3134 componentDidMount ( ) {
3235 Dimensions . addEventListener ( 'change' , this . handleOrientationChange ) ;
@@ -37,8 +40,11 @@ export default function withDimensions<Props extends InjectedProps>(
3740 }
3841
3942 handleOrientationChange = ( { window } : { window : ScaledSize } ) => {
40- const isLandscape = isOrientationLandscape ( window ) ;
41- this . setState ( { isLandscape } ) ;
43+ const { width, height } = window ;
44+ this . setState ( {
45+ dimensions : { width, height } ,
46+ isLandscape : isOrientationLandscape ( { width, height } ) ,
47+ } ) ;
4248 } ;
4349
4450 render ( ) {
0 commit comments