Is any chance to disable screen rotation (allow only vertical)? I would like to support only portrait view. And need it to work on android and ios.
Asked
Active
Viewed 8,323 times
9
-
check this answer out for ios - http://stackoverflow.com/questions/32176548/how-to-disable-rotation-in-react-native?rq=1 – Tope Mar 19 '17 at 02:12
-
If using CRNA apps, use the `app.json` file to set `orientation` as either potrait or landscape. See here for more details: https://docs.expo.io/versions/latest/workflow/configuration#orientationlock-your-app-to-a-specific-orientation-with-portrait-or-landscape-defaults-to-no-lock-valid-values-default-portrait-landscape – Ankit Kante Apr 11 '18 at 09:36
-
Please check this article from the medium- https://medium.com/react-native-training/react-native-portrait-device-orientation-9bcdeeac0b03 – Rajan Maharjan Mar 05 '19 at 10:06
-
Does this answer your question? [how to disable rotation in React Native?](https://stackoverflow.com/questions/32176548/how-to-disable-rotation-in-react-native) – snehal agrawal Nov 20 '19 at 16:04
7 Answers
8
Add screenOrientation in your Manifest.xml class
<activity android:name=".YourActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" />

curiousMind
- 2,812
- 1
- 17
- 38
2
Put the below code in manifest file
<activity
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>

Bala Raja
- 627
- 6
- 20
2
Write the below code in manifest file
<activity
android:screenOrientation="portrait"
android:configChanges="orientation|screenSize">
</activity>

Rathod Vijay
- 417
- 2
- 7
1
In android :-
using xml :-android:screenOrientation="portrait"
using java :-
@Override
public void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

Mahesh Babariya
- 4,560
- 6
- 39
- 54
-
Please be clear with your answer, also the question is for both iOs and Android. – Rajan Maharjan Mar 05 '19 at 10:07
1
Winner: chuck this in the app code, I usually drop it right after all my imports.
Expo.ScreenOrientation.allow(Expo.ScreenOrientation.Orientation.PORTRAIT);

Bisclavret
- 1,327
- 9
- 37
- 65
0
Have a look at Android's official documentation
You just have to add this to your activity tag in your android MANIFEST
file :
<activity
android:screenOrientation=["unspecified" | "behind" |
"landscape" | "portrait" |
"reverseLandscape" | "reversePortrait" |
"sensorLandscape" | "sensorPortrait" |
"userLandscape" | "userPortrait" |
"sensor" | "fullSensor" | "nosensor" |
"user" | "fullUser" | "locked"]
using the orientation that you want.

G. Hamaide
- 7,078
- 2
- 36
- 57
-1
Try to add this in config.xml
<preference name="Orientation" value="landscape" />