From b30f7578ba3818f20082d052b203366556a1cc78 Mon Sep 17 00:00:00 2001 From: Lucemans Date: Thu, 2 Feb 2023 20:46:46 +0000 Subject: [PATCH] Introduce useOrientation --- src/hooks/useOrientation.ts | 11 +++++++++++ src/index.ts | 1 + test/App.tsx | 3 +++ 3 files changed, 15 insertions(+) create mode 100644 src/hooks/useOrientation.ts diff --git a/src/hooks/useOrientation.ts b/src/hooks/useOrientation.ts new file mode 100644 index 0000000..e2fce0c --- /dev/null +++ b/src/hooks/useOrientation.ts @@ -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(); +}; diff --git a/src/index.ts b/src/index.ts index 72bd78e..f648caa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; diff --git a/test/App.tsx b/test/App.tsx index 4e96eb7..7b58cfc 100644 --- a/test/App.tsx +++ b/test/App.tsx @@ -13,6 +13,7 @@ import { useIpv4Address, useIpv6Address, useMacAddress, + useOrientation, useScreenBrightness, useSerialNumber, useSerialNumberDeviceOwner, @@ -43,6 +44,7 @@ export const App: FC = () => { const { batteryLevel } = useBatteryLevel(); const { charging, chargeState } = useCharging(); const { brightness, setBrightness } = useScreenBrightness(); + const orientation = useOrientation(); return (
@@ -75,6 +77,7 @@ export const App: FC = () => {

+

Current orientation: {orientation}

); };