Skip to content
This repository was archived by the owner on Feb 25, 2020. It is now read-only.

Commit b4f288f

Browse files
gewfysatya164
gewfy
authored andcommitted
fix: fix layout when starting in landscape (#192)
1 parent f21e8ba commit b4f288f

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/utils/withDimensions.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ export const isOrientationLandscape = ({ width, height }: DimensionsType) =>
1818
export 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

Comments
 (0)