mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-01-15 15:48:05 +00:00
- Import OrientationLock and Orientation types from .tv.ts module - Add explicit type annotations to orientation event handlers - Change ScreenOrientationEnum to use Record<number, string> - Use OrientationLock enum type instead of runtime value This fixes ReactCodegen build failures caused by TypeScript errors.
69 lines
1.9 KiB
TypeScript
69 lines
1.9 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
import { Platform } from "react-native";
|
|
import * as ScreenOrientation from "@/packages/expo-screen-orientation";
|
|
import {
|
|
Orientation,
|
|
OrientationLock,
|
|
} from "../packages/expo-screen-orientation.tv";
|
|
|
|
const orientationToOrientationLock = (
|
|
orientation: Orientation,
|
|
): OrientationLock => {
|
|
switch (orientation) {
|
|
case Orientation.LANDSCAPE_LEFT:
|
|
return OrientationLock.LANDSCAPE_LEFT;
|
|
case Orientation.LANDSCAPE_RIGHT:
|
|
return OrientationLock.LANDSCAPE_RIGHT;
|
|
case Orientation.PORTRAIT_UP:
|
|
return OrientationLock.PORTRAIT_UP;
|
|
default:
|
|
return OrientationLock.PORTRAIT_UP;
|
|
}
|
|
};
|
|
|
|
export const useOrientation = () => {
|
|
const [orientation, setOrientation] = useState(
|
|
Platform.isTV
|
|
? ScreenOrientation.OrientationLock.LANDSCAPE
|
|
: ScreenOrientation.OrientationLock.UNKNOWN,
|
|
);
|
|
|
|
useEffect(() => {
|
|
if (Platform.isTV) return;
|
|
|
|
const orientationSubscription =
|
|
ScreenOrientation.addOrientationChangeListener(
|
|
(event: { orientationInfo: { orientation: Orientation } }) => {
|
|
setOrientation(
|
|
orientationToOrientationLock(event.orientationInfo.orientation),
|
|
);
|
|
},
|
|
);
|
|
|
|
ScreenOrientation.getOrientationAsync().then((orientation: Orientation) => {
|
|
setOrientation(orientationToOrientationLock(orientation));
|
|
});
|
|
|
|
return () => {
|
|
orientationSubscription.remove();
|
|
};
|
|
}, []);
|
|
|
|
const lockOrientation = async (lock: OrientationLock) => {
|
|
if (Platform.isTV) return;
|
|
|
|
if (lock === ScreenOrientation.OrientationLock.DEFAULT) {
|
|
await ScreenOrientation.unlockAsync();
|
|
} else {
|
|
await ScreenOrientation.lockAsync(lock);
|
|
}
|
|
};
|
|
|
|
const unlockOrientation = async () => {
|
|
if (Platform.isTV) return;
|
|
await ScreenOrientation.unlockAsync();
|
|
};
|
|
|
|
return { orientation, setOrientation, lockOrientation, unlockOrientation };
|
|
};
|