1 line
2.4 KiB
Plaintext
1 line
2.4 KiB
Plaintext
{"version":3,"sources":["useWindowDimensions.tsx"],"names":["React","Dimensions","useWindowDimensions","dimensions","setDimensions","useState","height","width","get","useEffect","onChange","window","d","addEventListener","removeEventListener"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAAqBC,UAArB,QAAuC,cAAvC,C,CAEA;AACA;;AACA,eAAe,SAASC,mBAAT,GAA+B;AAC5C,QAAM,CAACC,UAAD,EAAaC,aAAb,IAA8BJ,KAAK,CAACK,QAAN,CAAe,MAAM;AACvD;AACA,UAAM;AAAEC,MAAAA,MAAM,GAAG,CAAX;AAAcC,MAAAA,KAAK,GAAG;AAAtB,QAA4BN,UAAU,CAACO,GAAX,CAAe,QAAf,CAAlC;AAEA,WAAO;AAAEF,MAAAA,MAAF;AAAUC,MAAAA;AAAV,KAAP;AACD,GALmC,CAApC;AAOAP,EAAAA,KAAK,CAACS,SAAN,CAAgB,MAAM;AACpB,UAAMC,QAAQ,GAAG,CAAC;AAAEC,MAAAA;AAAF,KAAD,KAAwC;AACvD,YAAM;AAAEJ,QAAAA,KAAF;AAASD,QAAAA;AAAT,UAAoBK,MAA1B;AAEAP,MAAAA,aAAa,CAAEQ,CAAD,IAAO;AACnB,YAAIL,KAAK,KAAKK,CAAC,CAACL,KAAZ,IAAqBD,MAAM,KAAKM,CAAC,CAACN,MAAtC,EAA8C;AAC5C,iBAAOM,CAAP;AACD;;AAED,eAAO;AAAEL,UAAAA,KAAF;AAASD,UAAAA;AAAT,SAAP;AACD,OANY,CAAb;AAOD,KAVD,CADoB,CAapB;AACA;;;AACAI,IAAAA,QAAQ,CAAC;AAAEC,MAAAA,MAAM,EAAEV,UAAU,CAACO,GAAX,CAAe,QAAf;AAAV,KAAD,CAAR;AAEAP,IAAAA,UAAU,CAACY,gBAAX,CAA4B,QAA5B,EAAsCH,QAAtC;AAEA,WAAO,MAAMT,UAAU,CAACa,mBAAX,CAA+B,QAA/B,EAAyCJ,QAAzC,CAAb;AACD,GApBD,EAoBG,EApBH;AAsBA,SAAOP,UAAP;AACD","sourcesContent":["import * as React from 'react';\nimport { ScaledSize, Dimensions } from 'react-native';\n\n// This is similar to the new useWindowDimensions hook in react-native\n// However, we have a custom implementation to support older RN versions\nexport default function useWindowDimensions() {\n const [dimensions, setDimensions] = React.useState(() => {\n // `height` and `width` maybe undefined during SSR, so we initialize them\n const { height = 0, width = 0 } = Dimensions.get('window');\n\n return { height, width };\n });\n\n React.useEffect(() => {\n const onChange = ({ window }: { window: ScaledSize }) => {\n const { width, height } = window;\n\n setDimensions((d) => {\n if (width === d.width && height === d.height) {\n return d;\n }\n\n return { width, height };\n });\n };\n\n // We might have missed an update before the listener was added\n // So make sure to update the dimensions\n onChange({ window: Dimensions.get('window') });\n\n Dimensions.addEventListener('change', onChange);\n\n return () => Dimensions.removeEventListener('change', onChange);\n }, []);\n\n return dimensions;\n}\n"]} |