facebook / react-native

A framework for building native applications using React

Home Page:https://reactnative.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

jaysoo opened this issue · comments

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

Hey jaysoo, thanks for reporting this issue!

React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.

  • If you don't know how to do something or not sure whether some behavior is expected or a bug, please ask on StackOverflow with the tag react-native or for more real time interactions, ask on Discord in the #react-native channel.
  • If this is a feature request or a bug that you would like to be fixed, please report it on Product Pains. It has a ranking feature that lets us focus on the most important issues the community is experiencing.
  • We welcome clear issues and PRs that are ready for in-depth discussion. Please provide screenshots where appropriate and always mention the version of React Native you're using. Thank you for your contributions!

Yeah, Dimensions is badly broken in android, if you rotate the screen the dimensions will still be in their old values. If you close the application and open it again but with the orientation changed, the values will be correct. The Dimension values keep their original values as opposed to change when the device orientation changes.

Also a way to assign a callback when the Dimensions change would be nice, if I could register a callback in componentDidMount and unregister it on componentWillUnmount I would be so happy.

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

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

Any update on this Issue ?

Can we get an update on this issue, I'm still experiencing this with RN 0.55.2 along with CRNA.

Closed with no explanation...? Can anyone comment on this issue please? @cpojer ?