Dimensions.get('window').height is sometimes wrong on Android
See original GitHub issueThis only happens on a real device (I’m using OnePlus One). Could not reproduce on an emulator.
- Create an example app that displays the window height.
- Open the app for the first time.
- The height is reported as some value (e.g. 592 for me) – See screenshot below
- Press home button.
- Go back to the example app.
- See that the window height is now different (e.g. 640 for me) – See screenshot below
It seems that the first load, the height excludes the soft menu bar, but on subsequent reloads it includes it. (the soft menu bar for me is 48).
Here’s the code I was running in my app:
'use strict';
const React = require('react-native');
const {
AppRegistry,
Dimensions,
Text,
View
} = React;
const window = Dimensions.get('window');
const Example = React.createClass({
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text style={{ fontSize: 48}}>Height is {window.height}</Text>
</View>
);
}
});
AppRegistry.registerComponent('Example', () => Example);
First load
Reload
Issue Analytics
- State:
- Created 8 years ago
- Reactions:8
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Dimensions.get('window').height returns wrong ... - GitHub
Based on the phones I've tested, for devices giving wrong height, Dimensions.get('screen').height is not equal to Dimensions.get('window').
Read more >React-Native Android - How to use getRealDimensions ...
First the API react-native (0.54) seems to be stable for Android, the call to Dimensions.get('window') returns the same value every time (at ...
Read more >[Android] Dimensions.get('window').height doesn't subtract the ...
[Android] Dimensions. get('window'). height doesn't subtract the status bar size | Voters | React Native.
Read more >react-native-extra-dimensions-android - npm package - Snyk
There is currently a bug in React Native where Dimensions.get('window').height sometimes returns the wrong value. Also, some apps may want to set the...
Read more >Size Matters: How I used React Native to make my App look ...
In this blog post, I'll show several methods for scaling your components to different screen sizes, and which one I found to work...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
Top GitHub Comments
bump… this is a pretty major issue, how has this not been fixed?
@DanielHoffmann I created a module just so I can get going on my own project.
https://github.com/jaysoo/react-native-extra-dimensions-android
A callback would be easy to implement. Although I’d prefer it being in RN core if it makes sense.