简体   繁体   中英

LandScape not Working in React native ? when IOS / Android Device off mode Auto Rotation

I am developing sample app based on react native orientation. Actually orientation is working. i want landscape mode when i was go to one particular page.it's ok no problem at this situation shows landscape mode, but when i am trying device turn to Portrait mode.but when i am turn Portrait or Landscape i want show only landscape not a portrait.

I am Using this module and wrote this code:

var Orientation = require('react-native-orientation');

class XOrating extends React.Component {
   constructor(props){
    super(props);
    this.state={

       HEIGHT:667,
       WIDTH:375


    }
  }

componentWillMount(){

  if(this.props.sportName == 'Pro Football'){
    Orientation.lockToLandscape();

    this.setState({
      HEIGHT:375,
      WIDTH:667


    })
  }
  else{
   Orientation.lockToPortrait();
  }

}

 _orientationDidChange(orientation) {
    if (orientation == 'LANDSCAPE') {

      Orientation.lockToLandscape();
      //do something with landscape layout
    } else if(orientation == 'PORTRAIT') {
      //do something with portrait layout   
       Orientation.lockToLandscape();
    }
  }

   componentWillUnmount() {
    Orientation.getOrientation((err,orientation)=> {
      console.log("Current Device Orientation: ", orientation);
    });
    Orientation.removeOrientationListener(this._orientationDidChange);
  }


componentDidMount(){


    Orientation.addOrientationListener(this._orientationDidChange);

 }

render(){
return(
<Image source={{uri:this.state.ImgBackground}} style={{width:this.state.WIDTH,
              height:this.state.HEIGHT, top:0, left:0}}>   
)
}

module.exports = XOrating;

Please suggest i want fit the landscape mode when hide in device in autorotation

Yes Finally I got a what i am doing my mistake.....

Just i add both two lines in AppDelegate.m file and after next clean the x code and run.

#import "../../node_modules/react-native-orientation/iOS/RCTOrientation/Orientation.h"


 - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return [Orientation getOrientation];
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM