screen orientation not locking on landscape

i’m using ScreenRotation but like i already explained in https://github.com/expo/expo/issues/902#issuecomment-467456413

ScreenOrientation.Landscape won’t lock, it shows correctly but it change to portrait automatically after a brief periode

ChartScreen.js


import React, { Component } from 'react';

import {
  View,
  StyleSheet,
  Dimensions,
  Text,
} from 'react-native';

import { ScreenOrientation } from 'expo';
export default class ChartScreen extends Component {
componentDidMount() {
    ScreenOrientation.allowAsync(ScreenOrientation.Orientation.LANDSCAPE);
    this.setState({ dataChart: this.getData() });
  }
switchToLandscape() {
    ScreenOrientation.allowAsync(ScreenOrientation.Orientation.LANDSCAPE);
  }
render() {
    this.switchToLandscape();

    return (
      <View style={styles.container}>
        <Text>test if lock on landscape is working</Text>
      </View>
    );
  }
const styles = StyleSheet.create({
  container: {
    flex: 1,

    alignItems: 'flex-end',
    backgroundColor: '#f5fcff',
  },
});

is there something wrong with my code, because i tried every thing but it does not seem to lock on landscape ?

Hey @tsouhaieb,

I’m using the code you posted, but it seems to be working as expected for me. What device are you running this on?

sorry for the inconvenience, this error happen when i’am using react-navigation to open ChartScreen, with that the landscape only mode is respected

SecondScreen.js

  handleClick = async param => {
    const { navigation } = this.props;
    const dataApi = await this.getDataWithParameter(param);
    navigation.navigate('ChartScreen', { data: dataApi, maxPoints: 200 });
  };

what i found as a temporary solution is to switch to landscape before calling ChartScreen

the code become:

  handleClick = async param => {
    const { navigation } = this.props;
    const dataApi = await this.getDataWithParameter(param);
    ScreenOrientation.allowAsync(ScreenOrientation.Orientation.LANDSCAPE);
    navigation.navigate('ChartScreen', { data: dataApi, maxPoints: 200 });
  };

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.