1 line
2.3 KiB
Plaintext
1 line
2.3 KiB
Plaintext
|
{"version":3,"sources":["useWindowDimensions.tsx"],"names":["useWindowDimensions","dimensions","setDimensions","Dimensions","get","handleChange","window","width","height","scale","fontScale","addEventListener","removeEventListener"],"mappings":";;;;;;;AAAA;;AACA;;AASA;AACA;AACe,SAASA,mBAAT,GAA+C;AAC5D,QAAM,CAACC,UAAD,EAAaC,aAAb,IAA8B,qBAAS,MAAMC,wBAAWC,GAAX,CAAe,QAAf,CAAf,CAApC;AACA,wBAAU,MAAM;AACd,aAASC,YAAT,CAAsB;AAAEC,MAAAA;AAAF,KAAtB,EAA8D;AAC5D,UACEL,UAAU,CAACM,KAAX,KAAqBD,MAAM,CAACC,KAA5B,IACAN,UAAU,CAACO,MAAX,KAAsBF,MAAM,CAACE,MAD7B,IAEAP,UAAU,CAACQ,KAAX,KAAqBH,MAAM,CAACG,KAF5B,IAGAR,UAAU,CAACS,SAAX,KAAyBJ,MAAM,CAACI,SAJlC,EAKE;AACAR,QAAAA,aAAa,CAACI,MAAD,CAAb;AACD;AACF;;AACDH,4BAAWQ,gBAAX,CAA4B,QAA5B,EAAsCN,YAAtC,EAXc,CAYd;AACA;AACA;;;AACAA,IAAAA,YAAY,CAAC;AAAEC,MAAAA,MAAM,EAAEH,wBAAWC,GAAX,CAAe,QAAf;AAAV,KAAD,CAAZ;AACA,WAAO,MAAM;AACXD,8BAAWS,mBAAX,CAA+B,QAA/B,EAAyCP,YAAzC;AACD,KAFD;AAGD,GAnBD,EAmBG,CAACJ,UAAD,CAnBH;AAoBA,SAAOA,UAAP;AACD","sourcesContent":["import { Dimensions } from 'react-native';\nimport { useEffect, useState } from 'react';\n\ntype DisplayMetrics = {\n width: number;\n height: number;\n scale: number;\n fontScale: number;\n};\n\n// Copied from https://github.com/facebook/react-native/blob/8d57691a/Libraries/Utilities/useWindowDimensions.js\n// for compatibility with React Native < 0.61.\nexport default function useWindowDimensions(): DisplayMetrics {\n const [dimensions, setDimensions] = useState(() => Dimensions.get('window'));\n useEffect(() => {\n function handleChange({ window }: { window: DisplayMetrics }) {\n if (\n dimensions.width !== window.width ||\n dimensions.height !== window.height ||\n dimensions.scale !== window.scale ||\n dimensions.fontScale !== window.fontScale\n ) {\n setDimensions(window);\n }\n }\n Dimensions.addEventListener('change', handleChange);\n // We might have missed an update between calling `get` in render and\n // `addEventListener` in this handler, so we set it here. If there was\n // no change, React will filter out this update as a no-op.\n handleChange({ window: Dimensions.get('window') });\n return () => {\n Dimensions.removeEventListener('change', handleChange);\n };\n }, [dimensions]);\n return dimensions;\n}\n"]}
|