Search code examples
reactjsreact-nativeorientationlandscape

React: Changing Screen.js to LandScape Orientation


Hello I am new to React Native and I am trying to change this screen (gameScreen.js) to have Orientation to be landscape instead of being portrait. All the other screen I want to keep Orientation as portrait. So what can I do to change the orientation to Landscape for GameScreen.js.

The Image Below is what I have tried; however, the screen is not changing to landscape but instead throws an error stating "NULL is not an object (evaluating 'Orientation.lockToLandscape)". I have tried using the library from 'react-native-orientation'; however, I have no clue on how to use them. Please HELP! Thank you.

enter image description here


Solution

  • The error is basically saying it does not recognise the react-native-orientation module. Make sure you follow the documentation to properly link the module as per https://www.npmjs.com/package/react-native-orientation.

    If you're new to React Native then Expo might be of interest as it handles a lot of the pain of linking modules etc in favour of imports. In this instance: https://docs.expo.io/versions/latest/sdk/screen-orientation/