nativescriptnativescript-vue

How to force portrait orientation in NativeScript 8.x for iOS and Android


There are a few community plugins that made for this, but none of them support NativeScript 8.x. They utilize "tns-core-modules" rather than "@nativescript/core". I've only found one paid plugin that supports NativeScript 8.x.

Is there truly no way to force portrait orientation natively in NativeScript? If not, it seems like a major oversight for a framework dedicated to making mobile apps.


Solution

  • 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.