Dimensions API does not handles orientation change #50861
Labels
API: Dimensions
Issue: Author Provided Repro
This issue can be reproduced in Snack or an attached project.
Description
Dimensions API always return portrait mode values (height > width) even if app was started in landscape mode.
Try to rotate device and check console output - height > width always.
Steps to reproduce
npx @react-native-community/cli@latest init rn791
cd rn791
yarn
cd ios && pod install
add next lines of code to App.tsx
`useEffect(() => {
const updateOrientation = () => {
const {height, width} = Dimensions.get('window');
const orientation = width > height ? 'landscape' : 'portrait';
console.log('new orientation: ', orientation);
};
updateOrientation();
const subscription = Dimensions.addEventListener(
'change',
updateOrientation,
);
return () => {
subscription?.remove();
};
}, []);`
React Native Version
0.79.1
Affected Platforms
Runtime - iOS
Output of
npx @react-native-community/cli info
Stacktrace or Logs
MANDATORY Reproducer
https://github.com/roman-zaitsev/rn791-dimensions-api-bug-reproducer
Screenshots and Videos
No response
The text was updated successfully, but these errors were encountered: