app 禁止设备横屏 “react-native-orientation” 组件
安装react-native-orientation组件:
npm install -S react-native-orientation
react-native link react-native-orientation
ios 配置:
ios -> dongzhenai -> AppDelegate.m 文件,添加:
#import "Orientation.h"
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return [Orientation getOrientation];
}
android 配置:
android -> app -> dongzhenai -> MainActivity.java 文件,添加:
import android.content.Intent;
import android.content.res.Configuration;
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Intent intent = new Intent("onConfigurationChanged");
intent.putExtra("newConfig", newConfig);
this.sendBroadcast(intent);
}
用法:
导入包:
import Orientation from 'react-native-orientation';
禁止横屏方法:
componentWillMount() {
Orientation.lockToPortrait();
}
更多方法:
git地址: https://github.com/yamill/react-native-orientation#configuration
这个人暂时没有 freestyle