From 5c18bee2cf5fcc12b09ef26e738342fffa0a1335 Mon Sep 17 00:00:00 2001 From: gewfy Date: Mon, 21 Oct 2019 15:08:29 +0200 Subject: [PATCH] fix: fix layout when starting in landscape (#192) --- packages/tabs/src/utils/withDimensions.tsx | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/tabs/src/utils/withDimensions.tsx b/packages/tabs/src/utils/withDimensions.tsx index 2e3b3336..028d6732 100644 --- a/packages/tabs/src/utils/withDimensions.tsx +++ b/packages/tabs/src/utils/withDimensions.tsx @@ -18,15 +18,18 @@ export const isOrientationLandscape = ({ width, height }: DimensionsType) => export default function withDimensions( WrappedComponent: React.ComponentType ): React.ComponentType>> { - const { width, height } = Dimensions.get('window'); - class EnhancedComponent extends React.Component { static displayName = `withDimensions(${WrappedComponent.displayName})`; - state = { - dimensions: { width, height }, - isLandscape: isOrientationLandscape({ width, height }), - }; + constructor(props: Props) { + super(props); + + const { width, height } = Dimensions.get('window'); + this.state = { + dimensions: { width, height }, + isLandscape: isOrientationLandscape({ width, height }), + }; + } componentDidMount() { Dimensions.addEventListener('change', this.handleOrientationChange); @@ -37,8 +40,11 @@ export default function withDimensions( } handleOrientationChange = ({ window }: { window: ScaledSize }) => { - const isLandscape = isOrientationLandscape(window); - this.setState({ isLandscape }); + const { width, height } = window; + this.setState({ + dimensions: { width, height }, + isLandscape: isOrientationLandscape({ width, height }), + }); }; render() {