UNPKG

3.39 kBSource Map (JSON)View Raw
1{"version":3,"sources":["withDimensions.tsx"],"names":["isOrientationLandscape","width","height","withDimensions","WrappedComponent","EnhancedComponent","React","Component","constructor","props","window","setState","dimensions","isLandscape","Dimensions","get","state","componentDidMount","addEventListener","handleOrientationChange","componentWillUnmount","removeEventListener","render","displayName"],"mappings":";;;;;;;;AAAA;;AACA;;AACA;;;;;;;;;;;;AAYO,MAAMA,sBAAsB,GAAG,CAAC;AAAEC,EAAAA,KAAF;AAASC,EAAAA;AAAT,CAAD,KACpCD,KAAK,GAAGC,MADH;;;;AAGQ,SAASC,cAAT,CACbC,gBADa,EAEgE;AAC7E,QAAMC,iBAAN,SAAgCC,KAAK,CAACC,SAAtC,CAAgD;AAG9CC,IAAAA,WAAW,CAACC,KAAD,EAAe;AACxB,YAAMA,KAAN;;AADwB,uDAkBA,CAAC;AAAEC,QAAAA;AAAF,OAAD,KAAwC;AAChE,cAAM;AAAET,UAAAA,KAAF;AAASC,UAAAA;AAAT,YAAoBQ,MAA1B;AACA,aAAKC,QAAL,CAAc;AACZC,UAAAA,UAAU,EAAE;AAAEX,YAAAA,KAAF;AAASC,YAAAA;AAAT,WADA;AAEZW,UAAAA,WAAW,EAAEb,sBAAsB,CAAC;AAAEC,YAAAA,KAAF;AAASC,YAAAA;AAAT,WAAD;AAFvB,SAAd;AAID,OAxByB;;AAGxB,YAAM;AAAED,QAAAA,KAAK,EAALA,MAAF;AAASC,QAAAA,MAAM,EAANA;AAAT,UAAoBY,wBAAWC,GAAX,CAAe,QAAf,CAA1B;;AACA,WAAKC,KAAL,GAAa;AACXJ,QAAAA,UAAU,EAAE;AAAEX,UAAAA,KAAK,EAALA,MAAF;AAASC,UAAAA,MAAM,EAANA;AAAT,SADD;AAEXW,QAAAA,WAAW,EAAEb,sBAAsB,CAAC;AAAEC,UAAAA,KAAK,EAALA,MAAF;AAASC,UAAAA,MAAM,EAANA;AAAT,SAAD;AAFxB,OAAb;AAID;;AAEDe,IAAAA,iBAAiB,GAAG;AAClBH,8BAAWI,gBAAX,CAA4B,QAA5B,EAAsC,KAAKC,uBAA3C;AACD;;AAEDC,IAAAA,oBAAoB,GAAG;AACrBN,8BAAWO,mBAAX,CAA+B,QAA/B,EAAyC,KAAKF,uBAA9C;AACD;;AAUDG,IAAAA,MAAM,GAAG;AACP;AACA,0BAAO,oBAAC,gBAAD,eAAsB,KAAKb,KAA3B,EAAsC,KAAKO,KAA3C,EAAP;AACD;;AAhC6C,GAD6B,CAoC7E;;;AApC6E,kBACvEX,iBADuE,0CAEpCD,gBAAgB,CAACmB,WAFmB;;AAqC7E,SAAO,mCAAoBlB,iBAApB,EAAuCD,gBAAvC,CAAP;AACD","sourcesContent":["import * as React from 'react';\nimport { Dimensions, ScaledSize } from 'react-native';\nimport hoistNonReactStatic from 'hoist-non-react-statics';\n\ntype DimensionsType = {\n width: number;\n height: number;\n};\n\ntype InjectedProps = {\n dimensions: DimensionsType;\n isLandscape: boolean;\n};\n\nexport const isOrientationLandscape = ({ width, height }: DimensionsType) =>\n width > height;\n\nexport default function withDimensions<Props extends InjectedProps>(\n WrappedComponent: React.ComponentType<Props>\n): React.ComponentType<Pick<Props, Exclude<keyof Props, keyof InjectedProps>>> {\n class EnhancedComponent extends React.Component {\n static displayName = `withDimensions(${WrappedComponent.displayName})`;\n\n constructor(props: Props) {\n super(props);\n\n const { width, height } = Dimensions.get('window');\n this.state = {\n dimensions: { width, height },\n isLandscape: isOrientationLandscape({ width, height }),\n };\n }\n\n componentDidMount() {\n Dimensions.addEventListener('change', this.handleOrientationChange);\n }\n\n componentWillUnmount() {\n Dimensions.removeEventListener('change', this.handleOrientationChange);\n }\n\n handleOrientationChange = ({ window }: { window: ScaledSize }) => {\n const { width, height } = window;\n this.setState({\n dimensions: { width, height },\n isLandscape: isOrientationLandscape({ width, height }),\n });\n };\n\n render() {\n // @ts-ignore\n return <WrappedComponent {...this.props} {...this.state} />;\n }\n }\n\n // @ts-ignore\n return hoistNonReactStatic(EnhancedComponent, WrappedComponent);\n}\n"]}
\No newline at end of file