how to disable rotation in React Native?

前端 未结 11 1304
渐次进展
渐次进展 2020-12-02 07:43

I would like to support only portrait view. How can I make a React Native app not to autorotate? I tried searching documentation and Github issues, but I didn\'t find anythi

相关标签:
11条回答
  • 2020-12-02 08:31

    use this for ios ipad orientaion issue want to change in plist file https://www.reddit.com/r/reactnative/comments/7vkrfp/disabling_screen_rotate_in_react_native_both/

    IOS:

    <key>UISupportedInterfaceOrientations</key> <array> <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortraitUpsideDown</string> </array>
    
    0 讨论(0)
  • 2020-12-02 08:35

    For Android: In your manifest file put:

    xmlns:tools="http://schemas.android.com/tools"
    

    Then inside the application tag put:

    tools:ignore="LockedOrientationActivity"
    

    And then in all activity set:

    android:screenOrientation="portrait"
    
    0 讨论(0)
  • 2020-12-02 08:37

    Android :

    Go to the Androidmenifest.xml file and add one line : android:screenOrientation="portrait"

         <activity
            android:name=".MainActivity"
    
            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>
    

    IOS :

    Simple you have to uncheck rotation mode from your XCODE

    enter image description here

    ref from ANKIT-DETROJ answer.

    0 讨论(0)
  • 2020-12-02 08:38

    React Native app is pretty much just a normal iOS application, so you can do it in exactly the same way as you do for all other apps. Simply uncheck (in XCode) the "Landscape Left" and "Landscape Right" as allowed Device Orientations in the General application properties:

    0 讨论(0)
  • 2020-12-02 08:38

    For iOS, Jarek's answer is great.

    For Android, you need to edit the AndroidManifest.xml file. Add the following line to each activity that you want to lock into portrait mode:

    android:screenOrientation="portrait" 
    

    So, a full example might look like this:

          <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
            android:windowSoftInputMode="adjustResize"
            android:screenOrientation="portrait">
    
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
          </activity>
    

    See full list of available screenOrientation properties in the docs, here: https://developer.android.com/guide/topics/manifest/activity-element.html

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