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

后端 未结 8 764
轻奢々
轻奢々 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 13:58

    2017 Update

    In addition to the solutions posted above if you're using Expo to build your app (as is currently recommended in official guides on React Native Blog) then all you need is to set orientation in app.json to "portrait" or "landscape" and make it work on both iOS and Android at the same time with no need to edit iOS/Android-specific XML configuration files:

    "orientation": "portrait"

    Example:

    {
      "expo": {
        "name": "My app",
        "slug": "my-app",
        "sdkVersion": "21.0.0",
        "privacy": "public",
        "orientation": "portrait"
      }
    }
    

    You can also use this at runtime:

    ScreenOrientation.allow()

    Example:

    ScreenOrientation.allow(ScreenOrientation.Orientation.PORTRAIT);
    

    More details:

    For more info see: how to disable rotation in React Native?

提交回复
热议问题