Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expo - Lock orientation to landscape

I'm trying to have my expo react-native app displayed in landscape

I edited app.json to have:

"orientation": "landscape",

And this in App.js

import { ScreenOrientation } from 'expo';

export default class App extends React.PureComponent {
  // ...
  componentDidMount() {
    ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE);
  }
  // ...
}

I try to run in android emulator, but it looks like the emulator is locked on portrait mode. The physical orientation of the device is landscape, The app is "streched" to fit a landscape screen, but android seems lock in portrait mode:

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

I check the device setting and "Auto-rotate" is ON.

I think I am missing something but I can't find what.

Can someone tell me what needs to be done to lock the app to landscape mode ?

Edit:

It seems to work with the Nexus 5 emulator, not on Nexus 9

like image 293
Apolo Avatar asked Jun 23 '19 15:06

Apolo


People also ask

How do I force my tablet to landscape?

When on the main screen, under the orientation section, you will see a number of options like 'Auto-rotate OFF', 'Auto-rotate ON', 'Forced Portrait' and 'Forced Landscape'. As the names suggest, you can use these buttons as one-tap shortcuts to toggle the orientation of your device.

How do I change the orientation in react native Expo?

Letting Expo Handle the Screen OrientationGo into your app. json file and delete the line titled orientation. Now if you tilt your device, your app will automatically rotate. If your app does not rotate you may have to enable auto-rotate in your device's settings.


2 Answers

for me just changing orientation in app.json is enough, the code is not needed.

like image 75
Giannhs Ker Avatar answered Sep 18 '22 18:09

Giannhs Ker


change with this.

  import * as ScreenOrientation from 'expo-screen-orientation';
ScreenOrientation.unlockAsync()
like image 31
abdullah göçer Avatar answered Sep 21 '22 18:09

abdullah göçer