Files
streamyfin/hooks/useOrientationSettings.ts
sarendsen ab33693dd9 wip
2025-01-06 13:25:49 +01:00

29 lines
781 B
TypeScript

import { useSettings } from "@/utils/atoms/settings";
import * as ScreenOrientation from "@/packages/expo-screen-orientation";
import { useEffect } from "react";
import { Platform } from "react-native";
export const useOrientationSettings = () => {
if (Platform.isTV) return;
const [settings] = useSettings();
useEffect(() => {
if (settings?.autoRotate) {
// Don't need to do anything
} else if (settings?.defaultVideoOrientation) {
ScreenOrientation.lockAsync(settings.defaultVideoOrientation);
}
return () => {
if (settings?.autoRotate) {
ScreenOrientation.unlockAsync();
} else {
ScreenOrientation.lockAsync(
ScreenOrientation.OrientationLock.PORTRAIT_UP
);
}
};
}, [settings]);
};