0

I need to disable auto rotation feature in react-native application.

The application should support portrait and landscape orientation but the user should can`t rotation screen. Now I have used react-native-orientation but this module only checked orientation and change it to necessary value.

So I need rotate screen only programmatically.

RN Version: 0.33

Ray
  • 9,184
  • 3
  • 27
  • 44

1 Answers1

2

You can set your Xcode Device Orientation enter image description here

Set in your android manifest file: android:screenOrientation="portrait"

Or You can set it using Dimensions. Something like this:

Dimensions.addEventListener('change', ({ window: { width, height } }) => {
    const orientation = width > height ? 'LANDSCAPE' : 'PORTRAIT';
}

Or you can use react-native-orientation to lock the screen on portrait or landscape just as you need. I have a working example in my github: https://github.com/soutot/react-native-orientation-test

class App extends Component {
    componentDidMount() {
        Orientation.lockToLandscape();
    }

    render() {
        return(
            <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center'}}>
                <Text>This is my content</Text>
            </View>
        );
    }
}

Hope it helps

soutot
  • 3,531
  • 1
  • 18
  • 22