美文网首页Web开发
react-native-orientation

react-native-orientation

作者: nimw | 来源:发表于2017-06-12 15:31 被阅读63次
  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);
    }
      ......
    }

相关文章

网友评论

    本文标题:react-native-orientation

    本文链接:https://www.haomeiwen.com/subject/qxmlqxtx.html