reactjs - React Native Dimensions iOS Change 事件不会触发
问题描述
我的 componentDidMount 中有一个非常简单的事件监听器来监听尺寸的变化,这在我的 iPhone 上的 iOS 模拟器中永远不会触发(多个模型),但它确实会在 iPad 模拟器上触发并且在 Android 中运行良好。
componentDidMount() {
Dimensions.addEventListener( 'change', () =>
{
this.getOrientation();
});
}
getOrientation = () => {
alert("Trigger Called"); // never fires in iPhone Simulator, but works on iPad Simulator and Android
if (Dimensions.get("screen").width < Dimensions.get("screen").height) {
this.setState({ screenOrientation: "portrait" });
} else {
this.setState({ screenOrientation: "landscape" });
}
};
难道我做错了什么?我也尝试过使用 EXPO Orientation,但遇到了完全相同的问题。
谢谢
解决方案
我发现了我的问题,似乎从 react-native-elements 使用 Overlay 时,它不会触发 change 事件。删除它修复它在 iPhone X(s)
推荐阅读
- amazon-web-services - 无法为 aws ubuntu 16.04 连接 ssh(端口 22)
- entity-framework - 覆盖 .NET Core 中的默认 Required ErrorMessage 属性
- javascript - 为什么我们包含将近 7 - 8 行的 Google Tag Manager 脚本?
- c# - HRESULT 异常:Application.Workbooks.Add() 时出现 0x800A03EX
- html - 如何在跨站点的 CSS 中保持样式一致?
- jenkins - 在构建期间刷新 HTML 报告视图
- r - R中的tryRetry函数?
- ruby-on-rails - Rails 使用 puma,将 localhost:3000 更改为 localhost:3000/example
- sorting - sort.Slice 没有正确排序
- react-native - React Native SVG 无处不在,有意义吗?