Expo - 锁定景观方向

Apo*_*olo 5 react-native expo

我正在尝试以横向显示我的 expo react-native 应用程序

我编辑 app.json 有:

"orientation": "landscape",
Run Code Online (Sandbox Code Playgroud)

这在 App.js 中

import { ScreenOrientation } from 'expo';

export default class App extends React.PureComponent {
  // ...
  componentDidMount() {
    ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE);
  }
  // ...
}
Run Code Online (Sandbox Code Playgroud)

我尝试在 android 模拟器中运行,但看起来模拟器已锁定在纵向模式。设备的物理方向是横向,应用程序被“拉伸”以适应横向屏幕,但 android 似乎锁定在纵向模式:

https://i.ibb.co/dK54ngp/Capture.png

我检查了设备设置,“自动旋转”已开启。

我想我错过了一些东西,但我找不到什么。

有人可以告诉我需要做什么才能将应用程序锁定为横向模式吗?

编辑

它似乎适用于 Nexus 5 模拟器,而不适用于 Nexus 9

小智 10

对我来说,只需更改 app.json 中的方向就足够了,不需要代码。


小智 4

以此改变。

  import * as ScreenOrientation from 'expo-screen-orientation';
ScreenOrientation.unlockAsync()
Run Code Online (Sandbox Code Playgroud)