@@ -18,15 +18,18 @@ export const isOrientationLandscape = ({ width, height }: DimensionsType) =>
18
18
export default function withDimensions < Props extends InjectedProps > (
19
19
WrappedComponent : React . ComponentType < Props >
20
20
) : React . ComponentType < Pick < Props , Exclude < keyof Props , keyof InjectedProps > > > {
21
- const { width, height } = Dimensions . get ( 'window' ) ;
22
-
23
21
class EnhancedComponent extends React . Component {
24
22
static displayName = `withDimensions(${ WrappedComponent . displayName } )` ;
25
23
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
+ }
30
33
31
34
componentDidMount ( ) {
32
35
Dimensions . addEventListener ( 'change' , this . handleOrientationChange ) ;
@@ -37,8 +40,11 @@ export default function withDimensions<Props extends InjectedProps>(
37
40
}
38
41
39
42
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
+ } ) ;
42
48
} ;
43
49
44
50
render ( ) {
0 commit comments