You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo环境下React Native安卓设备无法自动切换屏幕方向求助

Expo React Native 屏幕自动旋转问题解决方案
  • 确认app.json配置正确性
    确保app.json的expo字段下,orientation设置为"default",这是允许屏幕自动旋转的标准配置:

    {
      "expo": {
        "orientation": "default",
        // 其他项目配置...
      }
    }
    

    避免设置为"portrait"(强制竖屏)或"landscape"(强制横屏)。

  • 检查安卓设备系统自动旋转开关
    务必开启安卓设备的自动旋转功能(可通过快捷设置面板快速操作),系统层面的方向锁定会覆盖应用配置,导致无法自动旋转。

  • 用expo-screen-orientation库手动控制方向(兜底方案)
    如果上述方法无效,可通过官方库手动解锁方向:

    1. 安装依赖:
      npx expo install expo-screen-orientation
      
    2. 在根组件中添加初始化逻辑:
      import * as ScreenOrientation from 'expo-screen-orientation';
      import { useEffect } from 'react';
      
      export default function App() {
        useEffect(() => {
          const unlockOrientation = async () => {
            await ScreenOrientation.unlockAsync();
            // 也可指定支持的方向集合,比如同时支持横竖屏:
            // await ScreenOrientation.allowAsync(
            //   ScreenOrientation.Orientation.PORTRAIT_UP | 
            //   ScreenOrientation.Orientation.LANDSCAPE_LEFT | 
            //   ScreenOrientation.Orientation.LANDSCAPE_RIGHT
            // );
          };
          unlockOrientation();
        }, []);
      
        // 你的应用组件内容...
      }
      
  • 更新Expo Go到最新版本
    旧版本的Expo Go可能存在方向处理的兼容性问题,前往应用商店更新后重新测试。

内容的提问来源于stack exchange,提问作者Chew123Bacca

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 14:01:40