React Native - 方向锁定;我还能得到传感器的方向吗? [英] React Native - Orientation locked; can I still get the sensor's orientation?

查看:67
本文介绍了React Native - 方向锁定;我还能得到传感器的方向吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 React Native 应用程序,该应用程序旨在以纵向模式运行.方向通过清单锁定:

I'm working on a React Native app which is designed to run in portrait mode. The orientation is locked via the manifest:

  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:windowSoftInputMode="adjustResize"
    android:screenOrientation="portrait">

我需要添加使用 react-native-camera 完成的拍照功能.

I need to add the ability to take photos which I've done using react-native-camera.

问题是,我在拍照时无法改变方向,因为它被锁定为纵向.

The problem is, I can't get the orientation to change when taking photos since it is locked to portrait.

有没有办法允许在特定视图(即相机容器)中改变方向,以便相机可以检测到正确的方向?

Is there a way to allow orientation to change in a particular view (ie camera container) so that the camera can detect the correct orientation?

我想可能有以下几种情况:

I'm thinking maybe the following is possible:

  1. 直接从传感器请求方向
  2. 没有锁定方向的新活动

推荐答案

我遇到了同样的问题.我使用了 React-Native-Orientation :https://github.com/yamill/react-native-方向.

I had the same issue. I used React-Native-Orientation : https://github.com/yamill/react-native-orientation.

您不应该在清单中锁定方向,相反,您可以使用此库将每个屏幕锁定为纵向模式.使用 lockToPortrait()

You shouldn't lock the orientation in manifest, instead you u can lock every screen to portrait mode using this lib. Use lockToPortrait()

对于需要旋转的屏幕,只需使用 unlockAllOrientations 或 lockToLandscape()

And for the screens u need to rotate just use unlockAllOrientations or lockToLandscape()

API 很棒,但问题是你需要为每个屏幕都做这件事......如果你有很多屏幕,这似乎有点矫枉过正......但一切都很好

API is great but the problem is u need to do it for every screen .. seems kind of overkill if you have a lot of screens.. but things works great

其他提示

在每个屏幕上都这样做会很忙&很难管理.我所做的是将我的导航功能模块化为一个类.我

Doing this in every screen is going to hectic & very hard to manage. What i did was modularize my navigation functions to a single class. I

import Orientation from 'react-native-orientation';

export const navigateToMainScreen=()=>{
  determineOrientation("Main");
  this.props.navigation.navigate("Main");
}

const determineOrientation=(screenName)=>{
  // ur logic
  if(true){
      Orientation.lockToPortrait();
   }
  else{
   Orientation.lockToLandscape();
   }
}

这篇关于React Native - 方向锁定;我还能得到传感器的方向吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆