'can we config the screen orientation for particular screen in React Native?

I am new to react Native. am stuck in a issue, is it possible to lock a Particular screen in Landscape in react-native ? in other words can we config the screen orientation for particular screen ?

Help me to solve this?



Solution 1:[1]

You can use react-native-orientation or react-native-orientation-locker.

https://www.npmjs.com/package/react-native-orientation https://www.npmjs.com/package/react-native-orientation-locker

React native orientation provided following API which help to achieve screen orientation

Orientation.lockToPortrait()
Orientation.lockToLandscape()
Orientation.lockToLandscapeLeft()
Orientation.lockToLandscapeRight()
Orientation.unlockAllOrientations()
Orientation.getOrientation((err, orientation) => {})
Orientation.getSpecificOrientation((err, specificOrientation) => {})

Please check following code snippet

import Orientation from 'react-native-orientation'

componentDidMount() {
   Orientation.unlockAllOrientations();
}

componentWillUnmount() {
   Orientation.lockToPortrait();
}

Solution 2:[2]

I have tried both packages. https://www.npmjs.com/package/react-native-orientation https://www.npmjs.com/package/react-native-orientation-locker Both the packages work fine in android but I am getting the issue in ios devices it does not lock the orientation to landscape.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vishal Dhanotiya
Solution 2 Kaushal Lalani