【发布时间】:2020-11-07 03:21:58
【问题描述】:
当我尝试console.log(useDeviceOrientation()); 时,我正在使用本机反应开发应用程序。纵向和横向期间的输出 (true/false) 没有改变。有人可以帮忙吗?
使用的库是:@react-native-community/hooks
我使用的 API:useDeviceOrientation
我想做什么:
- 卸载库
- 重新安装相同的库
- 将库的依赖添加到 package.json 中
- 发生了同样的问题。改变方向时没有变化
代码:
// import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { Dimensions, StyleSheet, SafeAreaView, Alert, Button, Platform, StatusBar, View } from 'react-native';
import { useDimensions, useDeviceOrientation } from '@react-native-community/hooks'
export default function App() {
console.log(useDeviceOrientation());
const { landscape } = useDeviceOrientation();
return (
<SafeAreaView style={styles.container}>
<View style={{
backgroundColor: "dodgerblue",
width: "100%",
height: landscape ? "100%" : "30%",
}}
></View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
paddingTop: Platform.OS === "android" ? StatusBar.currentHeight : 0,
// justifyContent: "center",
// alignItems: "center",
},
});
【问题讨论】:
-
您需要提供更多详细信息。你还没有提到你正在使用的库,你已经尝试过什么......
标签: javascript react-native react-hooks device-orientation