From 497dd33a35904652eb72d16f427eb73a2f2a3d2f Mon Sep 17 00:00:00 2001 From: Developer Date: Wed, 11 Mar 2026 10:13:54 +0800 Subject: [PATCH] fix: lazy-require expo-screen-orientation for Expo Go compatibility --- components/VideoPlayer.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/components/VideoPlayer.tsx b/components/VideoPlayer.tsx index 30758c2..fb0ee9a 100644 --- a/components/VideoPlayer.tsx +++ b/components/VideoPlayer.tsx @@ -1,6 +1,8 @@ import React, { useState, useRef, useEffect } from 'react'; import { View, StyleSheet, Text, Platform, Modal, StatusBar, useWindowDimensions } from 'react-native'; -import * as ScreenOrientation from 'expo-screen-orientation'; +// expo-screen-orientation requires a dev build; gracefully degrade in Expo Go +let ScreenOrientation: typeof import('expo-screen-orientation') | null = null; +try { ScreenOrientation = require('expo-screen-orientation'); } catch {} import { NativeVideoPlayer } from './NativeVideoPlayer'; import type { PlayUrlResponse, DanmakuItem } from '../services/types'; @@ -25,19 +27,19 @@ export function VideoPlayer({ playData, qualities, currentQn, onQualityChange, o const handleEnterFullscreen = async () => { setFullscreen(true); if (Platform.OS !== 'web') - await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT); + await ScreenOrientation?.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT); }; const handleExitFullscreen = async () => { setFullscreen(false); if (Platform.OS !== 'web') - await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT_UP); + await ScreenOrientation?.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT_UP); }; useEffect(() => { return () => { if (Platform.OS !== 'web') - ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT_UP); + ScreenOrientation?.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT_UP); }; }, []);