diff --git a/src/hooks/useDisplaySize.ts b/src/hooks/useDisplaySize.ts new file mode 100644 index 0000000..72559ff --- /dev/null +++ b/src/hooks/useDisplaySize.ts @@ -0,0 +1,10 @@ +import { is_fully } from '../utils/is_fully'; + +export const useDisplaySize = () => { + if (!is_fully()) return { width: undefined, height: undefined }; + + return { + width: fully.getDisplayWidth(), + height: fully.getDisplayHeight(), + }; +}; diff --git a/src/index.ts b/src/index.ts index f648caa..efe9b78 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,7 @@ export * from './hooks/useCharging'; export * from './hooks/useCurrentLocale'; export * from './hooks/useDeviceId'; export * from './hooks/useDeviceName'; +export * from './hooks/useDisplaySize'; export * from './hooks/useHostname'; export * from './hooks/useImei'; export * from './hooks/useIpv4Address'; diff --git a/test/App.tsx b/test/App.tsx index 7b58cfc..926961a 100644 --- a/test/App.tsx +++ b/test/App.tsx @@ -7,6 +7,7 @@ import { useCurrentLocale, useDeviceId, useDeviceName, + useDisplaySize, useHostname, useHostname6, useImei, @@ -45,6 +46,7 @@ export const App: FC = () => { const { charging, chargeState } = useCharging(); const { brightness, setBrightness } = useScreenBrightness(); const orientation = useOrientation(); + const { width, height } = useDisplaySize(); return (
Current orientation: {orientation}
++ Display size: {width} x {height} +