Skip to content

Commit

Permalink
Introduce useDisplaySize
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Feb 2, 2023
1 parent b30f757 commit fa23533
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/hooks/useDisplaySize.ts
Original file line number Diff line number Diff line change
@@ -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(),
};
};
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
5 changes: 5 additions & 0 deletions test/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
useCurrentLocale,
useDeviceId,
useDeviceName,
useDisplaySize,
useHostname,
useHostname6,
useImei,
Expand Down Expand Up @@ -45,6 +46,7 @@ export const App: FC = () => {
const { charging, chargeState } = useCharging();
const { brightness, setBrightness } = useScreenBrightness();
const orientation = useOrientation();
const { width, height } = useDisplaySize();

return (
<div>
Expand Down Expand Up @@ -78,6 +80,9 @@ export const App: FC = () => {
<button onClick={() => setBrightness(255)}>255</button>
</p>
<p>Current orientation: {orientation}</p>
<p>
Display size: {width} x {height}
</p>
</div>
);
};

0 comments on commit fa23533

Please sign in to comment.