Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jaysoo opened this issue Dec 22, 2015 · 7 comments · Fixed by LedgerHQ/ledger-live-mobile#617
Closed
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@jaysoo
Copy link
Contributor

jaysoo commented Dec 22, 2015

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

@facebook-github-bot
Copy link
Contributor

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!

@DanielHoffmann
Copy link

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.

@jaysoo
Copy link
Contributor Author

jaysoo commented 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.

@infinityl00p
Copy link

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

@shubham-2710
Copy link

Any update on this Issue ?

@metahexane
Copy link

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

@Billy-
Copy link

Billy- commented Jun 25, 2018

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

@facebook facebook locked as resolved and limited conversation to collaborators Jul 20, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants