美文网首页
react-native 横竖屏控制及状态变化监听

react-native 横竖屏控制及状态变化监听

作者: 日不落000 | 来源:发表于2017-10-10 16:18 被阅读1021次

安装依赖:

package.json:

  "dependencies": {
    "react-native-orientation": "git+https://github.com/yamill/react-native-orientation.git"
  },

工具类:
OrientationUtil.js

/**
 * Created by nick on 2017/7/28.
 * 封装的横竖屏工具类
 */
import React from 'react';
import Orientation from 'react-native-orientation';

export default class OrientationUtil {


    static screenLockToPortrait() {
        Orientation.lockToPortrait(); //this will lock the view to Portrait
    }

    static screenLockToLandscape() {
        Orientation.lockToLandscape(); //this will lock the view to Landscape
    }


    static screenunLockAllOrientations() {
        Orientation.unlockAllOrientations(); //this will unlock the view to all Orientations

    }

    static addOrientationListener(listener) {
        Orientation.addOrientationListener(listener);

    }

    static removeOrientationListener(listener) {
        Orientation.removeOrientationListener(listener);

    }


}

相关文章

网友评论

      本文标题:react-native 横竖屏控制及状态变化监听

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