Reputation: 2808
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
Upvotes: 0
Views: 1872
Reputation: 2808
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];
}
Upvotes: 1