question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dimensions.get('window').height is sometimes wrong on Android

See original GitHub issue

This only happens on a real device (I’m using OnePlus One). Could not reproduce on an emulator.

  1. Create an example app that displays the window height.
  2. Open the app for the first time.
  3. The height is reported as some value (e.g. 592 for me) – See screenshot below
  4. Press home button.
  5. Go back to the example app.
  6. 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

screenshot dec 22 2015 4-58-01 pm

Reload

screenshot dec 22 2015 4-57-28 pm

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:8
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

32reactions
infinityl00pcommented, Feb 24, 2018

bump… this is a pretty major issue, how has this not been fixed?

5reactions
jaysoocommented, Dec 29, 2015

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found