How to set orientation in nativescript
You will have to update your AndroidManifest.xml
& Info.plist
in your App_Resources
.
AndroidManifest.xml
Set screenOrientation to portrait on your main activity
<activity android:name="com.tns.NativeScriptActivity"
...
android:screenOrientation="portrait">
Info.plist
Keep only the portrait orientation, remove rest from UISupportedInterfaceOrientations.
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
Note: Make sure you run a clean build after these changes.
For iOS: (Without Xcode, just manipulate one file.)
- Open file
app/App_Resources/iOS/Info.plist
Comment out or delete:
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
app/App_Resources/iOS/Info.plist
...
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
(Props to @mudlabs, who already mentioned this solution in a comment.)
The top answer is correct but for some cases, adding only android:screenOrientation does not work.
I got it working by adding android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation|screenSize"
and take note the order, screenOrientation first before the configChanges.
Actually i've tested it in both android studio and the Nativescript.
In case you are using NativeScript Sidekick it is possible to set orientation for Android an iOS from project properties.