如何解决在 React Native (expo) 中获取实际的设备方向锁定
如果用户的设备方向被锁定,我不想向用户显示消息,而且我无法访问此信息。
我尝试过使用 getorientationLockAsync,但这只会返回应用程序方向锁定。这是我给我们的代码
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet,Text,View } from 'react-native';
import * as Screenorientation from 'expo-screen-orientation';
export default function App() {
Screenorientation.getorientationLockAsync().then((res) => {
console.log('getorientationLockAsync',res)
})
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
<StatusBar style="auto" />
</View>
);
}
如果我将设备方向设置为纵向或横向,这总是返回app.json中设置的任何内容。
如果我的 app.json 看起来像这样:
{
"expo": {
"name": "expo-ex","slug": "expo-ex","version": "1.0.0","orientation": "default",...
}
}
getorientationLockAsync 将始终返回与“OrientationLock.DEFAULT”相关的“0”,即使我将设备方向锁定为横向。
我也尝试了 Screenorientation.getPlatformOrientationLockAsync() 功能,但这也不起作用。
我用的设备是三星s10e,expo的SDK版本是40。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。