react-native-orientation使用方式介绍

  1. Github地址
    react-native-orientation
  2. 执行npm命令
npm install --save react-native-orientation@git+https://github.com/yamill/react-native-orientation.git

注意: 不能使用npm install --save react-native-orientation安装稳定版npm包,有bug。

  1. 执行npm命令
react-native link react-native-orientation
  1. 配置AppDelegate.m文件
#import "Orientation.h" // <--- import
@implementation AppDelegate
  // ...
 - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return [Orientation getOrientation];
  }
@end
  1. 配置MainActivity.java文件
    import android.content.Intent; // <--- import
    import android.content.res.Configuration; // <--- import

    public class MainActivity extends ReactActivity {
      ......
      @Override
      public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        Intent intent = new Intent("onConfigurationChanged");
        intent.putExtra("newConfig", newConfig);
        this.sendBroadcast(intent);
    }
      ......
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容