From 36178c2082c60a254aa3ea6102c6242c1fe699f7 Mon Sep 17 00:00:00 2001 From: Fredrik Burmester Date: Sat, 15 Nov 2025 18:23:25 +0100 Subject: [PATCH] fix: apple tv runtime crash --- packages/expo-screen-orientation.ts | 71 ++++++++++++++++++++++++++++- react-native.config.js | 1 + 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/packages/expo-screen-orientation.ts b/packages/expo-screen-orientation.ts index 7b29bfe1..bb409b1e 100644 --- a/packages/expo-screen-orientation.ts +++ b/packages/expo-screen-orientation.ts @@ -1 +1,70 @@ -export * from "expo-screen-orientation"; +import { Platform } from "react-native"; + +// Dummy exports for TV +const DummyOrientationLock = { + DEFAULT: 0, + ALL: 1, + PORTRAIT: 2, + PORTRAIT_UP: 3, + PORTRAIT_DOWN: 4, + LANDSCAPE: 5, + LANDSCAPE_LEFT: 6, + LANDSCAPE_RIGHT: 7, +}; + +const DummyOrientation = { + UNKNOWN: 0, + PORTRAIT_UP: 1, + PORTRAIT_DOWN: 2, + LANDSCAPE_LEFT: 3, + LANDSCAPE_RIGHT: 4, +}; + +const dummyLockAsync = async () => {}; +const dummyUnlockAsync = async () => {}; +const dummyGetOrientationAsync = async () => DummyOrientation.UNKNOWN; +const dummyGetOrientationLockAsync = async () => DummyOrientationLock.DEFAULT; +const dummySupportsOrientationLockAsync = async () => false; + +// Conditionally export based on platform +let ScreenOrientation: any; +if (!Platform.isTV) { + ScreenOrientation = require("expo-screen-orientation"); +} + +export const OrientationLock = Platform.isTV + ? DummyOrientationLock + : ScreenOrientation?.OrientationLock; +export const Orientation = Platform.isTV + ? DummyOrientation + : ScreenOrientation?.Orientation; +export const lockAsync = Platform.isTV + ? dummyLockAsync + : ScreenOrientation?.lockAsync; +export const unlockAsync = Platform.isTV + ? dummyUnlockAsync + : ScreenOrientation?.unlockAsync; +export const getOrientationAsync = Platform.isTV + ? dummyGetOrientationAsync + : ScreenOrientation?.getOrientationAsync; +export const getOrientationLockAsync = Platform.isTV + ? dummyGetOrientationLockAsync + : ScreenOrientation?.getOrientationLockAsync; +export const supportsOrientationLockAsync = Platform.isTV + ? dummySupportsOrientationLockAsync + : ScreenOrientation?.supportsOrientationLockAsync; +export const lockPlatformAsync = Platform.isTV + ? dummyLockAsync + : ScreenOrientation?.lockPlatformAsync; +export const getPlatformLockAsync = Platform.isTV + ? dummyGetOrientationLockAsync + : ScreenOrientation?.getPlatformLockAsync; +export const addOrientationChangeListener = Platform.isTV + ? () => ({ remove: () => {} }) + : ScreenOrientation?.addOrientationChangeListener; +export const removeOrientationChangeListener = Platform.isTV + ? () => {} + : ScreenOrientation?.removeOrientationChangeListener; +export const removeOrientationChangeListeners = Platform.isTV + ? () => {} + : ScreenOrientation?.removeOrientationChangeListeners; diff --git a/react-native.config.js b/react-native.config.js index e18e9923..771214a6 100644 --- a/react-native.config.js +++ b/react-native.config.js @@ -32,6 +32,7 @@ module.exports = { "expo-haptics": disableForTV("expo-haptics"), "expo-brightness": disableForTV("expo-brightness"), "expo-sensors": disableForTV("expo-sensors"), + "expo-screen-orientation": disableForTV("expo-screen-orientation"), "react-native-ios-context-menu": disableForTV( "react-native-ios-context-menu", ),