Skip to content

Commit

Permalink
Introduce useOrientation
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Feb 2, 2023
1 parent 4238398 commit b30f757
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/hooks/useOrientation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { is_fully } from '../utils/is_fully';

/**
* Returns the current screen orientation.
* @returns The current screen orientation in degrees between 0 and 360.
*/
export const useOrientation = () => {
if (!is_fully()) return;

return fully.getScreenOrientation();
};
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export * from './hooks/useImei';
export * from './hooks/useIpv4Address';
export * from './hooks/useIpv6Address';
export * from './hooks/useMacAddress';
export * from './hooks/useOrientation';
export * from './hooks/useScreenBrightness';
export * from './hooks/useSerialNumber';
export * from './hooks/useSimSerialNumber';
Expand Down
3 changes: 3 additions & 0 deletions test/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
useIpv4Address,
useIpv6Address,
useMacAddress,
useOrientation,
useScreenBrightness,
useSerialNumber,
useSerialNumberDeviceOwner,
Expand Down Expand Up @@ -43,6 +44,7 @@ export const App: FC = () => {
const { batteryLevel } = useBatteryLevel();
const { charging, chargeState } = useCharging();
const { brightness, setBrightness } = useScreenBrightness();
const orientation = useOrientation();

return (
<div>
Expand Down Expand Up @@ -75,6 +77,7 @@ export const App: FC = () => {
<button onClick={() => setBrightness(100)}>100</button>
<button onClick={() => setBrightness(255)}>255</button>
</p>
<p>Current orientation: {orientation}</p>
</div>
);
};

0 comments on commit b30f757

Please sign in to comment.