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
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.
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.
for me just changing orientation in app.json is enough, the code is not needed.
change with this.
import * as ScreenOrientation from 'expo-screen-orientation';
ScreenOrientation.unlockAsync()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With