How to disable landscape mode in React Native Android dev mode?

后端 未结 8 602
轻奢々
轻奢々 2021-01-31 13:03

I am new to android environment. I know iOS can be done in Xcode to disable device orientation. How can I disable landscape mode or any orientation mode in React Native Android?

相关标签:
8条回答
  • 2021-01-31 14:03

    As @morenoh149 stated above the property name and value to do this is android:screenOrientation="portrait". React Native generates a file called AndroidManifest.xml in your project directory under the Android folder. Within that xml file under the tag manifest/application/activity you would add the line android:screenOrientation="portrait"

    An example is shown below

    <uses-permission android:name="android.permission.INTERNET" />
    
    <application
      android:allowBackup="true"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait" 
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>
    

    0 讨论(0)
  • 2021-01-31 14:05

    The accepted answer doesn't work if you're using react-native-navigation. Use this instead:

    Navigation.setDefaultOptions({
        layout: {
            orientation: ["portrait"],
        },
    });
    

    Check the docs here.

    0 讨论(0)
提交回复
热议问题