描述
React Native团队,我发现一个bug,即在手机旋转锁定后,使用useWindowDimensions钩子返回的值是旧值。
重现步骤
- 创建一个支持横竖屏的默认应用。
- 将以下代码添加到应用中:
const { height, width } = useWindowDimensions();
- 在控制台打印高度和宽度的值,然后继续以下操作。
- 将手机旋转至横屏
- 锁定手机
- 将手机旋转至竖屏
- 解锁手机。
- 高度和宽度的值没有更新。
测试在iOS上进行。
React Native版本
0.74.2
受影响的平台
运行时 - iOS
npx react-native info
的输出
System:
OS: macOS 14.5
CPU: (10) arm64 Apple M1 Pro
Memory: 1.27 GB / 16.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 22.3.0
path: /opt/homebrew/bin/node
Yarn:
version: 4.2.2
path: /opt/homebrew/bin/yarn
npm:
version: 10.8.1
path: /opt/homebrew/bin/npm
Watchman:
version: 2024.06.10.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.15.2
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 23.5
- iOS 17.5
- macOS 14.5
- tvOS 17.5
- visionOS 1.2
- watchOS 10.5
Android SDK: Not Found
IDEs:
Android Studio: 2024.1 AI-241.15989.150.2411.11948838
Xcode:
version: 15.4/15F31d
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.10
path: /usr/bin/javac
Ruby:
version: 2.6.10
path: /usr/bin/ruby
npmPackages:
"@react-native-community/cli": Not Found
react: Not Found
react-native:
installed: 0.74.2
wanted: "*"
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: Not found
newArchEnabled: Not found
iOS:
hermesEnabled: true
newArchEnabled: false
堆栈跟踪或日志
Start in portrait mode:
LOG {"height": 812, "width": 375}
Rotated to landscape:
LOG {"height": 375, "width": 812}
Rotated to portrait
LOG {"height": 812, "width": 375}
Rotated to landscape
LOG {"height": 375, "width": 812}
Locked screen
Rotated to portrait
Unlocked screen
1条答案
按热度按时间pbgvytdp1#
可能重复了其中一个:
https://github.com/facebook/react-native/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+useWindowDimensions