This commit is contained in:
Alex Kim
2025-12-07 02:22:09 +11:00
parent 7135be198a
commit 074222050a
5 changed files with 48 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
import type { OrientationChangeEvent } from "expo-screen-orientation";
import { useEffect, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { Platform } from "react-native";
import {
addOrientationChangeListener,
@@ -53,27 +53,28 @@ export const useOrientation = () => {
};
}, []);
const lockOrientation = async (
lock: (typeof OrientationLock)[keyof typeof OrientationLock],
) => {
if (Platform.isTV) return;
const lockOrientation = useCallback(
async (lock: (typeof OrientationLock)[keyof typeof OrientationLock]) => {
if (Platform.isTV) return;
if (lock === OrientationLock.DEFAULT) {
await unlockAsync();
} else {
await lockAsync(lock);
}
};
if (lock === OrientationLock.DEFAULT) {
await unlockAsync();
} else {
await lockAsync(lock);
}
},
[],
);
const unlockOrientationFn = async () => {
const unlockOrientation = useCallback(async () => {
if (Platform.isTV) return;
await unlockAsync();
};
}, []);
return {
orientation,
setOrientation,
lockOrientation,
unlockOrientation: unlockOrientationFn,
unlockOrientation,
};
};