方向未更新解锁设备后在react-native- android
问题描述:
我正在开发一个应用程序,其实我的应用程序显示横向和标签/ iPad中的肖像。但在平板电脑(iPad的工作正常),当我检查方向功能工作正常,直到解锁设备。当我锁定屏幕像特定模式(肖像/风景)之后,该设备显示方向前显示。不更新目前的方向。方向未更新解锁设备后在react-native- android
我跟着这个链接:https://github.com/yamill/react-native-orientation
这是我的代码:
componentWillMount(){
this.getOrientationtype()
}
getOrientationtype(){
//alert("Hello")
if(Platform.OS == 'ios'){ // to Identifying Android or iOS
if(aspectRatio>1.6){ // Code for Iphone
// alert("phone")
Orientation.lockToPortrait()
}
else{
Orientation.getOrientation((err, initial) => {
if(initial != 'UNKNOWN'){
this.setState({
orientation:initial
})
}
else{
this.setState({
orientation:'PORTRAIT'
})
}
});
}
}
else{
if(DeviceInfo.isTablet()){
// alert("android tab")
Orientation.getOrientation((err, initial) => {
if(initial != 'UNKNOWN'){
this.setState({
orientation:initial
})
}
else{
this.setState({
orientation:'PORTRAIT'
})
}
});
}
else{
Orientation.lockToPortrait()
}
}
}
请找出这个解决方案....我使用这个链接enter link description here
答
1.You应该使用Orientation.addOrientationListener
来收听Orientation Events。
2.As从OrientationModule.java源代码中看到,该库只需要调用unregisterReceiver
在onHostPause
,所以锁定后无法收到onConfigurationChanged
事件screen.One方法是编辑内部OrientationModule.java的onHostResume
满足你想要什么。
@Override
public void onHostResume() {
final Activity activity = getCurrentActivity();
if (activity == null) {
FLog.e(ReactConstants.TAG, "no activity to register receiver");
return;
}
activity.registerReceiver(receiver, new IntentFilter("onConfigurationChanged"));
//add below code to onHostResume function
//send broadcast onResume
final int orientationInt = getReactApplicationContext().getResources().getConfiguration().orientation;
Configuration newConfig = new Configuration();
newConfig.orientation = orientationInt;
Intent intent = new Intent("onConfigurationChanged");
intent.putExtra("newConfig", newConfig);
activity.sendBroadcast(intent);
}
整个代码可以在这里找到OrientationModule.java
呀真的非常感谢........ – Lavaraju